Changed date and format.
4 // sdk_util.cpp - utility routines from HL SDK util.cpp
6 // Selected portions of dlls/util.cpp from SDK 2.1.
7 // Functions copied from there as needed...
8 // And modified to avoid buffer overflows (argh).
9 // Also modified to remove dependency on CBaseEntity class.
13 * Copyright (c) 1999, 2000 Valve LLC. All rights reserved.
15 * This product contains software technology licensed from Id
16 * Software, Inc. ("Id Technology"). Id Technology (c) 1996 Id Software, Inc.
17 * All Rights Reserved.
19 * Use, distribution, and modification of this source code and/or resulting
20 * object code is restricted to non-commercial enhancements to products from
21 * Valve LLC. All other use, distribution, or modification is prohibited
22 * without written permission from Valve LLC.
27 ===== util.cpp ========================================================
29 Utility code. Really not optional after all.
36 #include <string.h> // for strncpy(), etc
38 #include "osdep.h" // win32 vsnprintf, etc
40 char* UTIL_VarArgs( char *format, ... )
43 static char string[1024];
45 va_start (argptr, format);
46 vsnprintf (string, sizeof(string), format, argptr);
53 //=========================================================
54 // UTIL_LogPrintf - Prints a logged message to console.
55 // Preceded by LOG: ( timestamp ) < message >
56 //=========================================================
57 void UTIL_LogPrintf( char *fmt, ... )
60 static char string[1024];
62 va_start ( argptr, fmt );
63 vsnprintf ( string, sizeof(string), fmt, argptr );
66 // Print to server console
67 ALERT( at_logged, "%s", string );
71 void META_UTIL_HudMessage(edict_t *pEntity, const hudtextparms_t &textparms,
74 if ( FNullEnt(pEntity) || pEntity->free )
77 MESSAGE_BEGIN( MSG_ONE, SVC_TEMPENTITY, NULL, pEntity );
78 WRITE_BYTE( TE_TEXTMESSAGE );
79 WRITE_BYTE( textparms.channel & 0xFF );
81 WRITE_SHORT( FixedSigned16( textparms.x, 1<<13 ) );
82 WRITE_SHORT( FixedSigned16( textparms.y, 1<<13 ) );
83 WRITE_BYTE( textparms.effect );
85 WRITE_BYTE( textparms.r1 );
86 WRITE_BYTE( textparms.g1 );
87 WRITE_BYTE( textparms.b1 );
88 WRITE_BYTE( textparms.a1 );
90 WRITE_BYTE( textparms.r2 );
91 WRITE_BYTE( textparms.g2 );
92 WRITE_BYTE( textparms.b2 );
93 WRITE_BYTE( textparms.a2 );
95 WRITE_SHORT( FixedUnsigned16( textparms.fadeinTime, 1<<8 ) );
96 WRITE_SHORT( FixedUnsigned16( textparms.fadeoutTime, 1<<8 ) );
97 WRITE_SHORT( FixedUnsigned16( textparms.holdTime, 1<<8 ) );
99 if ( textparms.effect == 2 )
100 WRITE_SHORT( FixedUnsigned16( textparms.fxTime, 1<<8 ) );
102 if ( strlen( pMessage ) < 512 )
104 WRITE_STRING( pMessage );
109 strncpy( tmp, pMessage, 511 );
116 short FixedSigned16( float value, float scale )
120 output = (int) (value * scale);
122 if ( output > 32767 )
125 if ( output < -32768 )
128 return (short)output;
131 unsigned short FixedUnsigned16( float value, float scale )
135 output = (int) (value * scale);
138 if ( output > 0xFFFF )
141 return (unsigned short)output;