Skip to content

Commit

Permalink
Replace hardcoded configstring index for CS_MV_REMAPS with a value pa…
Browse files Browse the repository at this point in the history
…rsed from the systeminfo of a server.

Clear advanced remaps before reapplying them.
  • Loading branch information
Daggolin committed May 6, 2023
1 parent 56e702c commit 4a5b4e5
Show file tree
Hide file tree
Showing 10 changed files with 48 additions and 20 deletions.
2 changes: 1 addition & 1 deletion src/client/cl_cgame.cpp
Expand Up @@ -453,7 +453,7 @@ void CL_ConfigstringModified( void ) {
}

// Shader Remaps
if ( index == CS_MV_REMAPS ) {
if ( index == cls.cs_remaps ) {
CL_ShaderStateChanged();
}
}
Expand Down
19 changes: 11 additions & 8 deletions src/client/cl_main.cpp
Expand Up @@ -4060,13 +4060,19 @@ void CL_ShaderStateChanged( void ) {
shaderRemapLightmapType_t lightmapModeValue;
shaderRemapStyleType_t styleModeValue;

const char *curPos = cl.gameState.stringData + cl.gameState.stringOffsets[ CS_MV_REMAPS ];
const char *endPos = curPos + strlen( curPos );
const char *curPos;
const char *endPos;

int length;

// Check configstring for prefix to avoid misinterpreting configstrings from mods
if ( !curPos || !*curPos || strncmp(curPos, "mvremap:", 8) ) return;
// Make sure it's a valid configstring index
if ( cls.cs_remaps < CS_SYSTEMINFO || cls.cs_remaps >= MAX_CONFIGSTRINGS ) return;

// Clear any active remaps. We are going to reapply those that should stay below when parsing the string anyway.
re.RemoveAdvancedRemaps();

curPos = cl.gameState.stringData + cl.gameState.stringOffsets[ cls.cs_remaps ];
endPos = curPos + strlen( curPos );

// Handling of these is really ugly. I originally wanted to handle them like the base game/cgame modules do, but
// those are prone to injections. Summary of delimeter issues:
Expand All @@ -4087,10 +4093,7 @@ void CL_ShaderStateChanged( void ) {
// it; this would allow for a size of up to 89, which is unlikely to be useful if MAX_QPATH ever gets increased
// -> using 47 to 127

// Skip prefix
curPos += 8;

// Example input (after skipping the "mvremap:" prefix above): "6console4clear929300;p;p;":
// Example input: "6console4clear929300;p;p;":
// - "6" -> ascii 54 -> 54 - 47 = 7 -> the next 7 characters are the source shader name
// - "console" -> source shader (7 characters)
// - "4" -> ascii 52 -> 52 - 47 = 5 -> the next 5 characters are the destination shader name
Expand Down
10 changes: 10 additions & 0 deletions src/client/cl_parse.cpp
Expand Up @@ -319,6 +319,7 @@ void CL_SystemInfoChanged( void ) {
char key[BIG_INFO_KEY];
char value[BIG_INFO_VALUE];
qboolean gameSet;
int old_cs_remaps = cls.cs_remaps;

systemInfo = cl.gameState.stringData + cl.gameState.stringOffsets[ CS_SYSTEMINFO ];
cl.serverId = atoi( Info_ValueForKey( systemInfo, "sv_serverid" ) );
Expand All @@ -327,6 +328,12 @@ void CL_SystemInfoChanged( void ) {
t = Info_ValueForKey( systemInfo, "sv_referencedPakNames" );
FS_PureServerSetReferencedPaks( s, t );

cls.cs_remaps = atoi( Info_ValueForKey(systemInfo, "mv_cs_remaps") );
if ( cls.cs_remaps != old_cs_remaps ) {
// If the configstring changed remove any active advanced remaps
re.RemoveAdvancedRemaps();
}

// don't set any other vars when playing a demo
if ( clc.demoplaying ) {
return;
Expand Down Expand Up @@ -485,6 +492,9 @@ void CL_ParseGamestate( msg_t *msg ) {
// parse serverId and other cvars
CL_SystemInfoChanged();

// Shader Remaps
CL_ShaderStateChanged();

// reinitialize the filesystem if the game directory has changed
if( FS_ConditionalRestart( clc.checksumFeed ) ) {
// don't set to true because we yet have to start downloading
Expand Down
2 changes: 2 additions & 0 deletions src/client/client.h
Expand Up @@ -352,6 +352,8 @@ typedef struct {

int fixes;
qboolean submodelBypass;

int cs_remaps;
} clientStatic_t;

#define CON_TEXTSIZE 131072 // increased in jk2mv
Expand Down
11 changes: 0 additions & 11 deletions src/game/bg_public.h
Expand Up @@ -100,17 +100,6 @@ Ghoul2 Insert End
#error overflow: (CS_MAX) > MAX_CONFIGSTRINGS
#endif


// Using highest available configstring for new mv configstring, because mods should add own configstrings between
// CS_STRING_PACKAGES and CS_MAX, making them come from the bottom.
#define CS_MV_REMAPS (MAX_CONFIGSTRINGS-1)
#define CS_MV_MIN (CS_MV_REMAPS)

// Make sure CS_MAX and CS_MV_MIN don't overlap
#if (CS_MAX) > (CS_MV_MIN)
#error overflow: (CS_MAX) > (CS_MV_MIN)
#endif

typedef enum {
G2_MODELPART_HEAD = 10,
G2_MODELPART_WAIST,
Expand Down
1 change: 1 addition & 0 deletions src/renderer/tr_init.cpp
Expand Up @@ -1523,6 +1523,7 @@ refexport_t *GetRefAPI ( int apiVersion, refimport_t *rimp ) {

re.RemapShader = R_RemapShader;
re.RemapShaderAdvanced = R_RemapShaderAdvanced;
re.RemoveAdvancedRemaps = R_RemoveAdvancedRemaps;
re.GetEntityToken = R_GetEntityToken;
re.inPVS = R_inPVS;

Expand Down
1 change: 1 addition & 0 deletions src/renderer/tr_local.h
Expand Up @@ -1463,6 +1463,7 @@ void R_InitShaders( void );
void R_ShaderList_f( void );
void R_RemapShader(const char *oldShader, const char *newShader, const char *timeOffset);
void R_RemapShaderAdvanced(const char *shaderName, const char *newShaderName, int timeOffset, shaderRemapLightmapType_t lightmapMode, shaderRemapStyleType_t styleMode);
void R_RemoveAdvancedRemaps( void );

/*
====================================================================
Expand Down
1 change: 1 addition & 0 deletions src/renderer/tr_public.h
Expand Up @@ -107,6 +107,7 @@ typedef struct {

void (*RemapShader)(const char *oldShader, const char *newShader, const char *offsetTime);
void (*RemapShaderAdvanced)(const char *oldShader, const char *newShader, int offsetTime, shaderRemapLightmapType_t lightmapMode, shaderRemapStyleType_t styleMode);
void (*RemoveAdvancedRemaps)(void);
qboolean (*GetEntityToken)( char *buffer, int size );
qboolean (*inPVS)( const vec3_t p1, const vec3_t p2 );

Expand Down
15 changes: 15 additions & 0 deletions src/renderer/tr_shader.cpp
Expand Up @@ -328,6 +328,21 @@ void R_RemapShaderAdvanced(const char *shaderName, const char *newShaderName, in
if ( failed ) ri.Printf( PRINT_WARNING, "WARNING: R_RemapShaderAdvanced: new shader %s not found (x%i)\n", newShaderName, failed );
}

void R_RemoveAdvancedRemaps( void ) {
int i;
shader_t *cur;
for ( i = 0; i < (int)ARRAY_LEN(hashTable); i++ ) {
cur = hashTable[i];
while ( cur ) {
if ( cur->advancedRemap ) {
cur->remappedShader = NULL;
cur->advancedRemap = qfalse;
}
cur = cur->next;
}
}
}

/*
===============
ParseVector
Expand Down
6 changes: 6 additions & 0 deletions src/server/sv_init.cpp
Expand Up @@ -842,6 +842,12 @@ void SV_Init (void) {
Cvar_Get ("sv_referencedPaks", "", CVAR_SYSTEMINFO | CVAR_ROM );
Cvar_Get ("sv_referencedPakNames", "", CVAR_SYSTEMINFO | CVAR_ROM );

// The mv_cs_remaps systeminfo cvar can be used by game module mods to
// announce the index of the configstring used for mvremaps. Registering the
// cvar here is not actually required. We just register it here to ensure
// the right flags are set on it.
Cvar_Get ("mv_cs_remaps", "", CVAR_SYSTEMINFO | CVAR_ROM | CVAR_INTERNAL );

// server vars
sv_rconPassword = Cvar_Get ("rconPassword", "", CVAR_TEMP );
sv_privatePassword = Cvar_Get ("sv_privatePassword", "", CVAR_TEMP );
Expand Down

0 comments on commit 4a5b4e5

Please sign in to comment.