How do I override engine (*pfn...) funcs? Created 5 months ago2023-11-26 19:16:35 UTC by nulcow nulcow

Created 5 months ago2023-11-26 19:16:35 UTC by nulcow nulcow

Posted 5 months ago2023-11-26 19:16:35 UTC Post #348097
I'm trying to modify the game_text entity to allow for custom font sizes. I implemented the custom parameter fontSize, but the next step is getting the HUD message system to display my text. I was able to find this cryptic-looking code which writes a message to be displayed on the HUD, and implemented my custom parameter:
void UTIL_HudMessage( CBaseEntity *pEntity, const hudtextparms_t &textparms, const char *pMessage )
{
    if ( !pEntity || !pEntity->IsNetClient() )
        return;

    MESSAGE_BEGIN( MSG_ONE, SVC_TEMPENTITY, NULL, pEntity->edict() );
        WRITE_BYTE( TE_TEXTMESSAGE );
        WRITE_BYTE( textparms.channel & 0xFF );

        WRITE_SHORT( FixedSigned16( textparms.x, 1<<13 ) );
        WRITE_SHORT( FixedSigned16( textparms.y, 1<<13 ) );
        WRITE_BYTE( textparms.effect );

        WRITE_BYTE( textparms.r1 );
        WRITE_BYTE( textparms.g1 );
        WRITE_BYTE( textparms.b1 );
        WRITE_BYTE( textparms.a1 );

        WRITE_BYTE( textparms.r2 );
        WRITE_BYTE( textparms.g2 );
        WRITE_BYTE( textparms.b2 );
        WRITE_BYTE( textparms.a2 );

        WRITE_SHORT( FixedUnsigned16( textparms.fadeinTime, 1<<8 ) );
        WRITE_SHORT( FixedUnsigned16( textparms.fadeoutTime, 1<<8 ) );
        WRITE_SHORT( FixedUnsigned16( textparms.holdTime, 1<<8 ) );

        WRITE_SHORT( textparms.fontSize ); // my code

        if ( textparms.effect == 2 )
            WRITE_SHORT( FixedUnsigned16( textparms.fxTime, 1<<8 ) );

        if ( strlen( pMessage ) < 512 )
        {
            WRITE_STRING( pMessage );
        }
        else
        {
            char tmp[512];
            strncpy( tmp, pMessage, 511 );
            tmp[511] = 0;
            WRITE_STRING( tmp );
        }
    MESSAGE_END();
}
I was able to trace the MESSAGE_BEGIN() macro to "enginecallback.h", where the macro is defined to call a function in "eiface.h", which is defined as this:
void (*pfnMessageBegin) (int msg_dest, int msg_type, const float *pOrigin, edict_t *ed);

No matter how hard I looked, though, I couldn't seem to find the body of void pfnMessageBegin(int, int, float, edict_t) that the pfnMessageBegin pointer in "eiface.h" was referencing. How do I change this code to use my custom data?
Posted 5 months ago2023-11-26 20:22:10 UTC Post #348098
Even if you were able to - you probably shouldn't change pfnMessageBegin, that may break a lot of stuff to do with decals, blood, effects, etc
brannanz brannanzBUGBUG
Posted 5 months ago2023-11-26 20:22:28 UTC Post #348099
I don't think you understand how this entire messaging system works. The structure in eiface.h defines the server-engine API, which is a set of functions provided by the engine to the server in a struct when the dll is loaded. This means, you can't modify these function calls, otherwise you'll break the entire API and your mod will be non-functional, possibly crash.

Also SVC_TEMPENTITY is a message that is handled inside the engine, so you cannot modify the contents of TE_TEXTMESSAGE to add your font size parameter: the engine will not understand how to process it. It'll still try to read the message contents as if that new WRITE_SHORT wasn't there.

Also I believe Half-Life's text renderer does not allow for custom font sizes. The font size used to display game texts is of fixed size, and cannot be altered. You'd need to add your own text rendering code to allow for custom font sizes, and you'll need your own client-side message function to send this info to the client.dll.
You must be logged in to post a response.