2018-04-13 18:23:45 +02:00
|
|
|
/*
|
|
|
|
custom.c - customization routines
|
|
|
|
Copyright (C) 2018 Uncle Mike
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "common.h"
|
|
|
|
#include "custom.h"
|
2019-02-18 19:25:26 +01:00
|
|
|
#include "ref_common.h"
|
2024-06-11 06:47:01 +02:00
|
|
|
#include "hpak.h" // be aware of HPK limits
|
2018-04-13 18:23:45 +02:00
|
|
|
|
2022-12-01 03:49:47 +01:00
|
|
|
static rgbdata_t *CustomDecal_LoadImage( const char *path, void *raw, int size )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
2022-12-01 03:49:47 +01:00
|
|
|
const char *testname;
|
|
|
|
|
|
|
|
// this way we limit file types
|
|
|
|
if( !Q_stricmp( COM_FileExtension( path ), "png" ))
|
|
|
|
testname = "#logo.png";
|
|
|
|
else testname = "#logo.bmp";
|
|
|
|
|
2022-12-05 02:56:07 +01:00
|
|
|
Image_SetForceFlags( IL_LOAD_PLAYER_DECAL );
|
|
|
|
|
2022-12-01 03:49:47 +01:00
|
|
|
return FS_LoadImage( testname, raw, size );
|
|
|
|
}
|
|
|
|
|
|
|
|
static qboolean CustomDecal_Validate( const char *path, void *raw, int nFileSize )
|
|
|
|
{
|
|
|
|
rgbdata_t *test = CustomDecal_LoadImage( path, raw, nFileSize );
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( test )
|
|
|
|
{
|
|
|
|
// all's ok, logo is valid
|
|
|
|
FS_FreeImage( test );
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
void COM_ClearCustomizationList( customization_t *pHead, qboolean bCleanDecals )
|
|
|
|
{
|
|
|
|
customization_t *pCurrent;
|
|
|
|
customization_t *pNext;
|
|
|
|
|
|
|
|
for( pCurrent = pHead->pNext; pCurrent != NULL; pCurrent = pNext )
|
|
|
|
{
|
|
|
|
pNext = pCurrent->pNext;
|
|
|
|
|
|
|
|
if( pCurrent->bInUse && pCurrent->pBuffer )
|
|
|
|
Mem_Free( pCurrent->pBuffer );
|
|
|
|
|
|
|
|
if( pCurrent->bInUse && pCurrent->pInfo )
|
|
|
|
{
|
2019-11-24 01:52:08 +01:00
|
|
|
#if !XASH_DEDICATED
|
2018-04-13 18:23:45 +02:00
|
|
|
if( pCurrent->resource.type == t_decal )
|
|
|
|
{
|
|
|
|
if( bCleanDecals && CL_Active( ))
|
2019-02-18 19:25:26 +01:00
|
|
|
ref.dllFuncs.R_DecalRemoveAll( pCurrent->nUserData1 );
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
2018-04-18 17:32:30 +02:00
|
|
|
#endif
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
FS_FreeImage( pCurrent->pInfo );
|
|
|
|
}
|
|
|
|
Mem_Free( pCurrent );
|
|
|
|
}
|
|
|
|
|
|
|
|
pHead->pNext = NULL;
|
|
|
|
}
|
|
|
|
|
|
|
|
qboolean COM_CreateCustomization( customization_t *pListHead, resource_t *pResource, int playernumber, int flags, customization_t **pOut, int *nLumps )
|
|
|
|
{
|
|
|
|
qboolean bError = false;
|
2019-05-02 18:12:23 +02:00
|
|
|
fs_offset_t checksize = 0;
|
2018-04-13 18:23:45 +02:00
|
|
|
customization_t *pCust;
|
|
|
|
|
|
|
|
if( pOut ) *pOut = NULL;
|
|
|
|
|
2018-06-09 00:28:35 +02:00
|
|
|
pCust = Z_Calloc( sizeof( customization_t ));
|
2018-04-13 18:23:45 +02:00
|
|
|
pCust->resource = *pResource;
|
|
|
|
|
|
|
|
if( pResource->nDownloadSize <= 0 )
|
|
|
|
goto CustomizationError;
|
|
|
|
|
|
|
|
pCust->bInUse = true;
|
|
|
|
|
|
|
|
if( FBitSet( flags, FCUST_FROMHPAK ))
|
|
|
|
{
|
2024-06-15 16:05:52 +02:00
|
|
|
if( !HPAK_GetDataPointer( hpk_custom_file.string, pResource, (byte **)&pCust->pBuffer, NULL ))
|
2018-04-13 18:23:45 +02:00
|
|
|
bError = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
|
|
|
|
pCust->pBuffer = FS_LoadFile( pResource->szFileName, &checksize, true );
|
2018-04-23 22:07:54 +02:00
|
|
|
if( (int)checksize != pCust->resource.nDownloadSize )
|
2018-04-13 18:23:45 +02:00
|
|
|
bError = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if( bError )
|
|
|
|
goto CustomizationError;
|
|
|
|
|
|
|
|
if( FBitSet( pCust->resource.ucFlags, RES_CUSTOM ) && pCust->resource.type == t_decal )
|
|
|
|
{
|
|
|
|
pCust->resource.playernum = playernumber;
|
|
|
|
|
2022-12-01 03:49:47 +01:00
|
|
|
if( CustomDecal_Validate( pResource->szFileName, pCust->pBuffer, pResource->nDownloadSize ))
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
if( !FBitSet( flags, FCUST_IGNOREINIT ))
|
|
|
|
{
|
2024-06-11 06:47:01 +02:00
|
|
|
if( pResource->nDownloadSize >= HPAK_ENTRY_MIN_SIZE && pResource->nDownloadSize <= HPAK_ENTRY_MAX_SIZE )
|
2018-04-13 18:23:45 +02:00
|
|
|
{
|
|
|
|
pCust->bTranslated = true;
|
|
|
|
pCust->nUserData1 = 0;
|
2024-06-11 06:47:01 +02:00
|
|
|
pCust->nUserData2 = 7;
|
2018-04-13 18:23:45 +02:00
|
|
|
|
|
|
|
if( !FBitSet( flags, FCUST_WIPEDATA ))
|
2022-12-01 03:49:47 +01:00
|
|
|
pCust->pInfo = CustomDecal_LoadImage( pResource->szFileName, pCust->pBuffer, pCust->resource.nDownloadSize );
|
2018-04-13 18:23:45 +02:00
|
|
|
else pCust->pInfo = NULL;
|
|
|
|
if( nLumps ) *nLumps = 1;
|
|
|
|
}
|
2022-11-22 15:55:44 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
Con_Printf( S_WARN "Ignoring custom decal \"%s\": wrong size (%i bytes)\n", pResource->szFileName, pResource->nDownloadSize );
|
|
|
|
}
|
2018-04-13 18:23:45 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if( pOut ) *pOut = pCust;
|
|
|
|
pCust->pNext = pListHead->pNext;
|
|
|
|
pListHead->pNext = pCust;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
CustomizationError:
|
|
|
|
if( pCust->pBuffer )
|
|
|
|
Mem_Free( pCust->pBuffer );
|
|
|
|
|
|
|
|
if( pCust->pInfo )
|
|
|
|
Mem_Free( pCust->pInfo );
|
|
|
|
Mem_Free( pCust );
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
int COM_SizeofResourceList( resource_t *pList, resourceinfo_t *ri )
|
|
|
|
{
|
|
|
|
int nSize = 0;
|
|
|
|
resource_t *p;
|
|
|
|
|
|
|
|
memset( ri, 0, sizeof( *ri ));
|
|
|
|
|
|
|
|
for( p = pList->pNext; p != pList; p = p->pNext )
|
|
|
|
{
|
|
|
|
nSize += p->nDownloadSize;
|
|
|
|
|
|
|
|
if( p->type == t_model && p->nIndex == 1 )
|
|
|
|
ri->info[t_world].size += p->nDownloadSize;
|
|
|
|
else ri->info[p->type].size += p->nDownloadSize;
|
|
|
|
}
|
|
|
|
|
|
|
|
return nSize;
|
2018-04-23 22:07:54 +02:00
|
|
|
}
|