From 09bcccf8bfdb83c891162c5da573cd68b556c332 Mon Sep 17 00:00:00 2001 From: Knightmare66 Date: Wed, 13 Mar 2019 19:54:41 -0400 Subject: [PATCH] Fix crash in fog code when loading save from different/incompatible game DLL. Add support for game DLLs compiled for current development version. Fixed crash in Fog_Off() when called from ShutdownGame(), typically when trying to load an incompatible savegame from a different (or different version) game DLL. Added filesytem function exports to game DLL from development branch to support game DLLs compiled for that version. --- .gitignore | 20 ++++++++++++++++++++ game/g_fog.c | 19 ++++++++++++------- game/g_func_decs.h | 4 ++-- game/g_local.h | 10 +++++----- game/g_main.c | 4 ++-- game/game.h | 13 ++++++++----- game/p_client.c | 2 +- server/sv_game.c | 9 ++++++++- 8 files changed, 58 insertions(+), 23 deletions(-) create mode 100644 .gitignore diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..95376d1 --- /dev/null +++ b/.gitignore @@ -0,0 +1,20 @@ +# ignore all make dependency files and linux object binaries +*.d +*.o +bin/ + +# ignore all the windows binaries - they shouldn't be committed! +Debug/ +Release/ +x64/ +.vs/ +*.log +*.ncb +*.opt +*.plg +*.suo +*.user +*.aps +*.clw +*.pdb +*.ilk diff --git a/game/g_fog.c b/game/g_fog.c index 2bc715f..38b1c00 100644 --- a/game/g_fog.c +++ b/game/g_fog.c @@ -41,11 +41,11 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #ifdef DISABLE_FOG -void Fog_Init() {} +void Fog_Init (void) {} void Fog (edict_t *ent) {} -void Fog_Off () {} -void Fog_ConsoleFog () {} -void GLFog () {} +void Fog_Off (qboolean gameShutdown) {} +void Fog_ConsoleFog (void) {} +void GLFog (void) {} void trig_fog_fade (edict_t *self) {} void init_trigger_fog_delay (edict_t *self) {} void fog_fade (edict_t *self) {} @@ -74,7 +74,7 @@ NEW FOG SYSTEM ================================================= */ -void Fog_Off (edict_t *player_ent) +void Client_Fog_Off (edict_t *player_ent) { if (!player_ent->client || player_ent->is_bot) return; @@ -611,7 +611,7 @@ void Fog (edict_t *ent) //vec3_t viewpoint) if (!level.active_fog) { if (level.last_active_fog) - Fog_Off(); + Fog_Off (false); level.last_active_fog = 0; return; } @@ -635,7 +635,7 @@ void Fog (edict_t *ent) //vec3_t viewpoint) level.last_active_fog = level.active_fog; } -void Fog_Off (void) +void Fog_Off (qboolean gameShutdown) { if (deathmatch->value || coop->value) return; @@ -644,6 +644,11 @@ void Fog_Off (void) { edict_t *player_ent = &g_edicts[1]; + // If game is shutting down, g_edicts will likely be invalid + // and the client will clear the fog automatically + if (gameShutdown) + return; + if (!player_ent->client || player_ent->is_bot) return; diff --git a/game/g_func_decs.h b/game/g_func_decs.h index a8937c2..e027d0a 100644 --- a/game/g_func_decs.h +++ b/game/g_func_decs.h @@ -1113,7 +1113,7 @@ extern void model_die ( edict_t * self , edict_t * inflictor , edict_t * attacke extern void model_spawn_use ( edict_t * self , edict_t * other , edict_t * activator ) ; extern void modelspawn_think ( edict_t * self ) ; extern void PrecacheDebris ( int type ) ; -extern int PatchDeadSoldier ( ) ; +extern int PatchDeadSoldier ( void ) ; extern void SP_target_fountain ( edict_t * ent ) ; extern void target_fountain_delayed_use ( edict_t * self ) ; extern void target_fountain_use ( edict_t * ent , edict_t * other , edict_t * activator ) ; @@ -1462,7 +1462,7 @@ extern void SP_target_fog ( edict_t * self ) ; extern void target_fog_use ( edict_t * self , edict_t * other , edict_t * activator ) ; extern void fog_fade ( edict_t * self ) ; extern void Fog_Init ( void ) ; -extern void Fog_Off ( void ) ; +extern void Fog_Off ( qboolean gameShutdown ) ; extern void Fog ( edict_t * ent ) ; extern void init_trigger_fog_delay ( edict_t * self ) ; extern void trig_fog_fade ( edict_t * self ) ; diff --git a/game/g_local.h b/game/g_local.h index 2589f01..e195cb6 100644 --- a/game/g_local.h +++ b/game/g_local.h @@ -959,11 +959,11 @@ void Moving_Speaker_Think(edict_t *ent); // #define MAX_FOGS 16 extern fog_t gfogs[MAX_FOGS]; -void Cmd_Fog_f(edict_t *ent); -void Fog_Init(); -void Fog(edict_t *ent); //vec3_t viewpoint); -void Fog_Off(); -void Fog_SetFogParms(); +void Cmd_Fog_f (edict_t *ent); +void Fog_Init (void); +void Fog (edict_t *ent); //vec3_t viewpoint); +void Fog_Off (qboolean gameShutdown); +void Fog_SetFogParms (void); // // g_func.c // diff --git a/game/g_main.c b/game/g_main.c index 4840939..0dd42d1 100644 --- a/game/g_main.c +++ b/game/g_main.c @@ -164,8 +164,8 @@ void ShutdownGame (void) //gi.cvar_forceset("gl_clear", va("%d", lazarus_gl_clear->value)); } // Lazarus: Turn off fog if it's on - if(!dedicated->value) - Fog_Off(); + if (!dedicated->value) + Fog_Off (true); gi.FreeTags (TAG_LEVEL); gi.FreeTags (TAG_GAME); diff --git a/game/game.h b/game/game.h index 91b7303..c51a1fc 100644 --- a/game/game.h +++ b/game/game.h @@ -198,11 +198,14 @@ typedef struct int (*LoadFile) (char *name, void **buf); void (*FreeFile) (void *buf); void (*FreeFileList) (char **list, int n); -// int (*OpenFile) (const char *name, fileHandle_t *f, fsMode_t mode); -// int (*OpenCompressedFile) (const char *zipName, const char *fileName, fileHandle_t *f, fsMode_t mode); -// void (*CloseFile) (fileHandle_t f); -// int (*FRead) (void *buffer, int size, fileHandle_t f); -// int (*FWrite) (const void *buffer, int size, fileHandle_t f); + int (*OpenFile) (const char *name, fileHandle_t *f, fsMode_t mode); + int (*OpenCompressedFile) (const char *zipName, const char *fileName, fileHandle_t *f, fsMode_t mode); + void (*CloseFile) (fileHandle_t f); + int (*FRead) (void *buffer, int size, fileHandle_t f); + int (*FWrite) (const void *buffer, int size, fileHandle_t f); + char *(*GameDir) (void); + char *(*SaveGameDir) (void); + void (*CreatePath) (char *path); #endif } game_import_t; diff --git a/game/p_client.c b/game/p_client.c index cba030d..f305493 100644 --- a/game/p_client.c +++ b/game/p_client.c @@ -2088,7 +2088,7 @@ void ClientBegin (edict_t *ent) return; } - Fog_Off(); + Fog_Off (false); stuffcmd(ent,"alias +zoomin zoomin;alias -zoomin zoominstop\n"); stuffcmd(ent,"alias +zoomout zoomout;alias -zoomout zoomoutstop\n"); diff --git a/server/sv_game.c b/server/sv_game.c index c7e1c75..4161276 100644 --- a/server/sv_game.c +++ b/server/sv_game.c @@ -405,6 +405,14 @@ void SV_InitGameProgs (void) import.LoadFile = FS_LoadFile; import.FreeFile = FS_FreeFile; import.FreeFileList = FS_FreeFileList; + import.OpenFile = FS_FOpenFile; + import.OpenCompressedFile = FS_FOpenCompressedFile; + import.CloseFile = FS_FCloseFile; + import.FRead = FS_Read; + import.FWrite = FS_Write; + import.GameDir = FS_GameDir; + import.SaveGameDir = FS_GameDir; + import.CreatePath = FS_CreatePath; import.SetAreaPortalState = CM_SetAreaPortalState; import.AreasConnected = CM_AreasConnected; @@ -419,4 +427,3 @@ void SV_InitGameProgs (void) ge->Init (); } -