Skip to content

Commit

Permalink
Merged pull request "Sync with Q2PRO: Game library improvements": NVI…
Browse files Browse the repository at this point in the history
  • Loading branch information
apanteleev committed Dec 8, 2023
2 parents f496c6a + dc629e5 commit 9adb370
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 16 deletions.
2 changes: 2 additions & 0 deletions inc/shared/shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -644,11 +644,13 @@ typedef struct cvar_s {
struct cvar_s *next;

// ------ new stuff ------
#if USE_CLIENT || USE_SERVER
int integer;
char *default_string;
xchanged_t changed;
xgenerator_t generator;
struct cvar_s *hashNext;
#endif
} cvar_t;

#endif // CVAR
Expand Down
41 changes: 25 additions & 16 deletions src/server/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -686,6 +686,10 @@ static cvar_t *PF_cvar(const char *name, const char *value, int flags)

static void PF_AddCommandString(const char *string)
{
#if USE_CLIENT
if (!strcmp(string, "menu_loadgame\n"))
string = "pushmenu loadgame\n";
#endif
Cbuf_AddText(&cmd_buffer, string);
}

Expand All @@ -707,13 +711,17 @@ static qboolean PF_AreasConnected(int area1, int area2)

static void *PF_TagMalloc(unsigned size, unsigned tag)
{
Q_assert(tag <= UINT16_MAX - TAG_MAX);
if (tag > UINT16_MAX - TAG_MAX) {
Com_Error(ERR_DROP, "%s: bad tag", __func__);
}
return Z_TagMallocz(size, tag + TAG_MAX);
}

static void PF_FreeTags(unsigned tag)
{
Q_assert(tag <= UINT16_MAX - TAG_MAX);
if (tag > UINT16_MAX - TAG_MAX) {
Com_Error(ERR_DROP, "%s: bad tag", __func__);
}
Z_FreeTags(tag + TAG_MAX);
}

Expand Down Expand Up @@ -748,7 +756,7 @@ void SV_ShutdownGameProgs(void)
Z_LeakTest(TAG_FREE);
}

static void *_SV_LoadGameLibrary(const char *path)
static void *SV_LoadGameLibraryFrom(const char *path)
{
void *entry;

Expand All @@ -761,24 +769,23 @@ static void *_SV_LoadGameLibrary(const char *path)
return entry;
}

static void *SV_LoadGameLibrary(const char *game, const char *prefix)
static void *SV_LoadGameLibrary(const char *libdir, const char *gamedir)
{
char path[MAX_OSPATH];

if (Q_concat(path, sizeof(path), sys_libdir->string,
PATH_SEP_STRING, game, PATH_SEP_STRING,
prefix, "game" CPUSTRING LIBSUFFIX) >= sizeof(path)) {
if (Q_concat(path, sizeof(path), libdir,
PATH_SEP_STRING, gamedir, PATH_SEP_STRING,
"game" CPUSTRING LIBSUFFIX) >= sizeof(path)) {
Com_EPrintf("Game library path length exceeded\n");
return NULL;
}

if (os_access(path, F_OK)) {
if (!*prefix)
Com_Printf("Can't access %s: %s\n", path, strerror(errno));
if (os_access(path, X_OK)) {
Com_Printf("Can't access %s: %s\n", path, strerror(errno));
return NULL;
}

return _SV_LoadGameLibrary(path);
return SV_LoadGameLibraryFrom(path);
}

/*
Expand All @@ -798,20 +805,22 @@ void SV_InitGameProgs(void)

// for debugging or `proxy' mods
if (sys_forcegamelib->string[0])
entry = _SV_LoadGameLibrary(sys_forcegamelib->string);
entry = SV_LoadGameLibraryFrom(sys_forcegamelib->string);

// try game first
if (!entry && fs_game->string[0]) {
entry = SV_LoadGameLibrary(fs_game->string, "q2pro_");
if (sys_homedir->string[0])
entry = SV_LoadGameLibrary(sys_homedir->string, fs_game->string);
if (!entry)
entry = SV_LoadGameLibrary(fs_game->string, "");
entry = SV_LoadGameLibrary(sys_libdir->string, fs_game->string);
}

// then try baseq2
if (!entry) {
entry = SV_LoadGameLibrary(BASEGAME, "q2pro_");
if (sys_homedir->string[0])
entry = SV_LoadGameLibrary(sys_homedir->string, BASEGAME);
if (!entry)
entry = SV_LoadGameLibrary(BASEGAME, "");
entry = SV_LoadGameLibrary(sys_libdir->string, BASEGAME);
}

// all paths failed
Expand Down

0 comments on commit 9adb370

Please sign in to comment.