Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "..\Interfaces.h"
- #include "..\..\NewNetvar.h"
- #include "TexGen.h"
- #include <convar.h>
- int team = 0;
- int health = 0;
- void CProceduralRegenerator::RegenerateTextureBits( ITexture *pTexture, IVTFTexture *pVTFTexture, Rect_t *pSubRect )
- {
- CPixelWriter pixelWriter;
- pixelWriter.SetPixelMemory( pVTFTexture->Format(),
- pVTFTexture->ImageData( 0, 0, 0 ), pVTFTexture->RowSizeInBytes( 0 ) );
- // Now upload the part we've been asked for
- int xmax = pSubRect->x + pSubRect->width;
- int ymax = pSubRect->y + pSubRect->height;
- int x, y;
- int tt = ConVarRef("ms_chams_color_team", false).GetInt();
- float hh = ConVarRef("ms_chams_color_health", false).GetFloat();
- for( y = pSubRect->y; y < ymax; ++y )
- {
- pixelWriter.Seek( pSubRect->x, y );
- for( x=pSubRect->x; x < xmax; ++x )
- {
- if (team == 3)//blue
- pixelWriter.WritePixel( 255-tt, hh * health, tt, 255 );
- else
- pixelWriter.WritePixel( tt, hh * health, 255-tt, 255 );
- }
- }
- }
- void CProceduralRegenerator::Release()
- {
- //delete stuff
- }
- CProceduralProxy::CProceduralProxy()
- {
- m_pTextureVar = NULL;
- m_pTexture = NULL;
- m_pTextureRegen = NULL;
- }
- CProceduralProxy::~CProceduralProxy()
- {
- if (m_pTexture != NULL)
- {
- m_pTexture->SetTextureRegenerator( NULL );
- }
- }
- IMaterial* CProceduralProxy::GetMaterial()
- {
- return m_pTextureVar->GetOwningMaterial();
- }
- bool CProceduralProxy::Init( IMaterial *pMaterial, KeyValues *pKeyValues )
- {
- bool found;
- m_pTextureVar = pMaterial->FindVar("$basetexture", &found, false); // Get a reference to our base texture variable
- if( !found )
- {
- m_pTextureVar = NULL;
- return false;
- }
- m_pTexture = m_pTextureVar->GetTextureValue(); // Now grab a ref to the actual texture
- if (m_pTexture != NULL)
- {
- m_pTextureRegen = new CProceduralRegenerator( ); // Here we create our regenerator
- m_pTexture->SetTextureRegenerator(m_pTextureRegen); // And here we attach it to the texture.
- }
- return true;
- }
- void CProceduralProxy::OnBind( void *pEntity )
- {
- if( !m_pTexture ) // Make sure we have a texture
- return;
- if(!m_pTextureVar->IsTexture() || !m_pTexture->IsProcedural()) // Make sure it is a texture
- return;
- const char* debugName = m_pTexture->GetName();
- IClientRenderable* pRender = (IClientRenderable*)pEntity;
- if (pRender && pRender->GetIClientUnknown()->GetIClientEntity())
- {
- int index = pRender->GetIClientUnknown()->GetIClientEntity()->entindex();
- if ((index < engine->GetMaxClients()) && (index > 0))
- {
- team = TF2::BasePlayer::iTeamNum(pRender->GetIClientUnknown()->GetIClientEntity());
- health = TF2::BasePlayer::iHealth(pRender->GetIClientUnknown()->GetIClientEntity());
- }
- }
- else
- {
- team = 0;
- health = 0;
- }
- //THIS PUSH IS ACTUALLY VERY IMPORTANT
- __asm push 0
- m_pTexture->Download(); // Force the regenerator to redraw
- }
Add Comment
Please, Sign In to add comment