Гайд Drawing images with ISurface [not actually guide] for supremacy

Banned
Пользователь
Статус
Онлайн
Регистрация
1 Окт 2016
Сообщения
143
Реакции[?]
45
Поинты[?]
2K
source:
Пожалуйста, авторизуйтесь для просмотра ссылки.


surface.h
Код:
    __forceinline bool IsTextureIdValid( int texture_id ) {
        return util::get_method< bool( __thiscall* )( decltype( this ), int ) >( this, ISTEXTUREIDVALID )( this, texture_id );
    }

.h
C++:
#include "lodepng.h"

class CTextureHolder
{
public:
    CTextureHolder( )
        : m_pSurface( g_csgo.m_surface ), m_iH( 0 ), m_iW( 0 ), m_bValid( false )
    { };

    CTextureHolder( const unsigned char* pRawRGBAData, int W, int H )
        : m_pSurface( g_csgo.m_surface ), m_iH( H ), m_iW( W ), m_bValid( false )
    {
        m_iTexture = m_pSurface->CreateNewTextureID( true );
        if ( !m_iTexture )
            return;

        m_pSurface->DrawSetTextureRGBA( m_iTexture, pRawRGBAData, W, H );
        m_bValid = true;
    };

    bool IsValid( ) const
    {
        return m_bValid;
    };

    int GetTextureId( ) const
    {
        return m_iTexture;
    };

    bool Draw( int x, int y, Color col, float scale = 1.0 )
    {
        if ( !m_pSurface->IsTextureIdValid( m_iTexture ) )
            return false;

        m_pSurface->DrawSetColor( col );
        m_pSurface->DrawSetTexture( m_iTexture );
        m_pSurface->DrawTexturedRect( x, y, x + m_iW * scale, y + m_iH * scale );
        return true;
    };

    static std::uint8_t* DecodeResourceImage( unsigned short uID, unsigned int iWidth, unsigned int iHeight );

protected:
    int m_iTexture;
    int m_iW, m_iH;
    bool m_bValid;
    ISurface* m_pSurface;
};

.cpp
C++:
std::uint8_t* CTextureHolder::DecodeResourceImage( unsigned short uID, unsigned int iWidth, unsigned int iHeight ) {
    const HRSRC pResource = FindResource( g_csgo.m_dll, MAKEINTRESOURCE( uID ), "PNG" );
    const HGLOBAL hLoadedResource = LoadResource( g_csgo.m_dll, pResource );
    const LPVOID pResourcePtr = LockResource( hLoadedResource );
    const DWORD dwResourceSize = SizeofResource( g_csgo.m_dll, pResource );

    std::vector< std::uint8_t > vecImage;

    if ( const auto error = lodepng::decode( vecImage, iWidth, iHeight, ( unsigned char* )pResourcePtr, dwResourceSize ) )
        throw std::runtime_error( "Failed to decode image!" );

    const auto pData = new std::uint8_t[ vecImage.size( ) ];

    std::copy( vecImage.begin( ), vecImage.end( ), pData );

    return pData;
}

entry.cpp
C++:
int __stdcall DllMain( HMODULE self, ulong_t reason, void *reserved ) {
    if( reason == DLL_PROCESS_ATTACH ) {

#ifndef KOLO
        HANDLE thread = CreateThread( nullptr, 0, Client::init, nullptr, 0, nullptr );
        if( !thread )
            return 0;

        g_csgo.m_dll = self;

        //CloseHandle( thread );
#else
        Client::init( nullptr );
#endif
        return 1;
    }

    return 0;
}

usage:
C++:
    .h
    bool                m_bInitialized;
    CTextureHolder      backgroundTexture;
  
    .cpp
    if ( !m_bInitialized ) {
        backgroundTexture = CTextureHolder( CTextureHolder::DecodeResourceImage( IDB_PNG1, 630, 500 ), 630, 500 );
        m_bInitialized = !m_bInitialized;
    }
  
    backgroundTexture.Draw( m_x, m_y, Color( 255, 255, 255, m_alpha ), 1 );
 
Последнее редактирование:
Сверху Снизу