From 21195b349102b60d7ad3a19b270c29f3204131da Mon Sep 17 00:00:00 2001 From: Alibek Omarov Date: Tue, 11 Jun 2024 07:47:01 +0300 Subject: [PATCH] engine: increase logo and hpak limits, add cl_logomaxdim cvar to limit decal size (set to 96, default HL logo size is 64) --- engine/client/cl_main.c | 8 +++++--- engine/client/cl_tent.c | 22 ++++++++++++++++------ engine/client/client.h | 3 +-- engine/common/custom.c | 5 +++-- engine/common/hpak.c | 6 ++---- engine/common/hpak.h | 3 +++ engine/common/imagelib/imagelib.h | 4 ++-- 7 files changed, 32 insertions(+), 19 deletions(-) diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index eeb04990..76d36731 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -36,9 +36,10 @@ CVAR_DEFINE_AUTO( cl_resend, "6.0", 0, "time to resend connect" ); CVAR_DEFINE( cl_allow_download, "cl_allowdownload", "1", FCVAR_ARCHIVE, "allow to downloading resources from the server" ); CVAR_DEFINE_AUTO( cl_allow_upload, "1", FCVAR_ARCHIVE, "allow to uploading resources to the server" ); CVAR_DEFINE_AUTO( cl_download_ingame, "1", FCVAR_ARCHIVE, "allow to downloading resources while client is active" ); -CVAR_DEFINE_AUTO( cl_logofile, "lambda", FCVAR_ARCHIVE, "player logo name" ); -CVAR_DEFINE_AUTO( cl_logocolor, "orange", FCVAR_ARCHIVE, "player logo color" ); -CVAR_DEFINE_AUTO( cl_logoext, "bmp", FCVAR_ARCHIVE, "temporary cvar to tell engine which logo must be packed" ); +static CVAR_DEFINE_AUTO( cl_logofile, "lambda", FCVAR_ARCHIVE, "player logo name" ); +static CVAR_DEFINE_AUTO( cl_logocolor, "orange", FCVAR_ARCHIVE, "player logo color" ); +static CVAR_DEFINE_AUTO( cl_logoext, "bmp", FCVAR_ARCHIVE, "temporary cvar to tell engine which logo must be packed" ); +CVAR_DEFINE_AUTO( cl_logomaxdim, "96", FCVAR_ARCHIVE, "maximum decal dimension" ); CVAR_DEFINE_AUTO( cl_test_bandwidth, "1", FCVAR_ARCHIVE, "test network bandwith before connection" ); CVAR_DEFINE( cl_draw_particles, "r_drawparticles", "1", FCVAR_CHEAT, "render particles" ); @@ -2939,6 +2940,7 @@ static void CL_InitLocal( void ) Cvar_RegisterVariable( &cl_logofile ); Cvar_RegisterVariable( &cl_logocolor ); Cvar_RegisterVariable( &cl_logoext ); + Cvar_RegisterVariable( &cl_logomaxdim ); Cvar_RegisterVariable( &cl_test_bandwidth ); Voice_RegisterCvars(); diff --git a/engine/client/cl_tent.c b/engine/client/cl_tent.c index 86bd14cc..8c63564a 100644 --- a/engine/client/cl_tent.c +++ b/engine/client/cl_tent.c @@ -2927,16 +2927,26 @@ static void CL_PlayerDecal( int playernum, int customIndex, int entityIndex, flo { if( !pCust->nUserData1 ) { - int sprayTextureIndex; char decalname[MAX_VA_STRING]; + int width, height; Q_snprintf( decalname, sizeof( decalname ), "player%dlogo%d", playernum, customIndex ); - sprayTextureIndex = ref.dllFuncs.GL_FindTexture( decalname ); - if( sprayTextureIndex != 0 ) - { - ref.dllFuncs.GL_FreeTexture( sprayTextureIndex ); - } + textureIndex = ref.dllFuncs.GL_FindTexture( decalname ); + if( textureIndex != 0 ) + ref.dllFuncs.GL_FreeTexture( textureIndex ); + pCust->nUserData1 = GL_LoadTextureInternal( decalname, pCust->pInfo, TF_DECAL ); + + width = REF_GET_PARM( PARM_TEX_WIDTH, pCust->nUserData1 ); + height = REF_GET_PARM( PARM_TEX_HEIGHT, pCust->nUserData1 ); + + if( width > cl_logomaxdim.value || height > cl_logomaxdim.value ) + { + double scale = cl_logomaxdim.value / Q_max( width, height ); + width = round( width * scale ); + height = round( height * scale ); + ref.dllFuncs.R_OverrideTextureSourceSize( pCust->nUserData1, width, height ); // default custom decal from HL1 + } } textureIndex = pCust->nUserData1; } diff --git a/engine/client/client.h b/engine/client/client.h index 70dab480..26093d9e 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -654,8 +654,7 @@ extern gameui_static_t gameui; // cvars // extern convar_t mp_decals; -extern convar_t cl_logofile; -extern convar_t cl_logocolor; +extern convar_t cl_logomaxdim; extern convar_t cl_allow_download; extern convar_t cl_allow_upload; extern convar_t cl_download_ingame; diff --git a/engine/common/custom.c b/engine/common/custom.c index 368691f5..65997f41 100644 --- a/engine/common/custom.c +++ b/engine/common/custom.c @@ -16,6 +16,7 @@ GNU General Public License for more details. #include "common.h" #include "custom.h" #include "ref_common.h" +#include "hpak.h" // be aware of HPK limits static rgbdata_t *CustomDecal_LoadImage( const char *path, void *raw, int size ) { @@ -115,11 +116,11 @@ qboolean COM_CreateCustomization( customization_t *pListHead, resource_t *pResou { if( !FBitSet( flags, FCUST_IGNOREINIT )) { - if( pResource->nDownloadSize >= (1 * 1024) && pResource->nDownloadSize <= ( 128 * 1024 )) + if( pResource->nDownloadSize >= HPAK_ENTRY_MIN_SIZE && pResource->nDownloadSize <= HPAK_ENTRY_MAX_SIZE ) { pCust->bTranslated = true; pCust->nUserData1 = 0; - pCust->nUserData2 = 1; + pCust->nUserData2 = 7; if( !FBitSet( flags, FCUST_WIPEDATA )) pCust->pInfo = CustomDecal_LoadImage( pResource->szFileName, pCust->pBuffer, pCust->resource.nDownloadSize ); diff --git a/engine/common/hpak.c b/engine/common/hpak.c index 18f7cb2a..41cf27da 100644 --- a/engine/common/hpak.c +++ b/engine/common/hpak.c @@ -17,8 +17,6 @@ GNU General Public License for more details. #include "hpak.h" #define HPAK_MAX_ENTRIES 0x8000 -#define HPAK_ENTRY_MIN_SIZE (512) -#define HPAK_ENTRY_MAX_SIZE (128 * 1024) typedef struct hash_pack_queue_s { @@ -29,7 +27,7 @@ typedef struct hash_pack_queue_s struct hash_pack_queue_s *next; } hash_pack_queue_t; -static CVAR_DEFINE_AUTO( hpk_maxsize, "4", FCVAR_ARCHIVE, "set limit by size for all HPK-files ( 0 - unlimited )" ); +static CVAR_DEFINE_AUTO( hpk_maxsize, "8", FCVAR_ARCHIVE, "set limit by size for all HPK-files ( 0 - unlimited )" ); static hash_pack_queue_t *gp_hpak_queue = NULL; static hpak_header_t hash_pack_header; static hpak_info_t hash_pack_info; @@ -517,7 +515,7 @@ void HPAK_CheckSize( const char *filename ) Q_strncpy( pakname, filename, sizeof( pakname )); COM_ReplaceExtension( pakname, ".hpk", sizeof( pakname )); - if( FS_FileSize( pakname, false ) > ( maxsize * 1048576 )) + if( FS_FileSize( pakname, false ) > ( maxsize * 1024 * 1024 )) { Con_Printf( "Server: Size of %s > %f MB, deleting.\n", filename, hpk_maxsize.value ); Log_Printf( "Server: Size of %s > %f MB, deleting.\n", filename, hpk_maxsize.value ); diff --git a/engine/common/hpak.h b/engine/common/hpak.h index 5e71eec8..0b4add17 100644 --- a/engine/common/hpak.h +++ b/engine/common/hpak.h @@ -17,6 +17,9 @@ GNU General Public License for more details. #include "custom.h" +#define HPAK_ENTRY_MIN_SIZE (512) +#define HPAK_ENTRY_MAX_SIZE (256 * 1024) + /* ======================================================================== .HPK archive format (Hash PAK - HPK) diff --git a/engine/common/imagelib/imagelib.h b/engine/common/imagelib/imagelib.h index e4b6614c..0182719d 100644 --- a/engine/common/imagelib/imagelib.h +++ b/engine/common/imagelib/imagelib.h @@ -103,8 +103,8 @@ typedef struct imglib_s #define IMAGE_MAXHEIGHT 8192 #define LUMP_MAXWIDTH 1024 // WorldCraft limits #define LUMP_MAXHEIGHT 1024 -#define PLDECAL_MAXWIDTH 512 -#define PLDECAL_MAXHEIGHT 512 +#define PLDECAL_MAXWIDTH 768 // total of ~2mb uncompressed rgba data +#define PLDECAL_MAXHEIGHT 768 enum {