From 07173b3c7bbf1fb3583876f5bd78c0077a374de3 Mon Sep 17 00:00:00 2001 From: Marco Cawthorne Date: Sat, 18 Nov 2023 13:31:17 -0800 Subject: [PATCH] Platform: add menu debug command 'listGameLibrary' to output all the currently indexed games/mods --- src/menu-fn/entry.qc | 4 ++++ src/platform/gamelibrary.h | 4 ++++ src/platform/gamelibrary.qc | 25 +++++++++++++++++-------- src/server/mapcycle.qc | 3 +-- 4 files changed, 26 insertions(+), 10 deletions(-) diff --git a/src/menu-fn/entry.qc b/src/menu-fn/entry.qc index 27286d37..8b3325cd 100644 --- a/src/menu-fn/entry.qc +++ b/src/menu-fn/entry.qc @@ -125,6 +125,7 @@ m_init(void) registercommand("map_background"); registercommand("menu_musicstart"); registercommand("richpresence_dump"); + registercommand("listGameLibrary"); Font_Load("fonts/fontcon.font", font_console); Font_Load("fonts/menu_label.font", font_label); @@ -441,6 +442,9 @@ m_consolecommand(string cmd) localcmd(sprintf("maxplayers 2\nset coop 1\nset sv_background 1\nmap %s\n", argv(1))); break; + case "listGameLibrary": + GameLibrary_DebugList(); + break; default: return (0); } diff --git a/src/platform/gamelibrary.h b/src/platform/gamelibrary.h index 972f3f97..16847e75 100644 --- a/src/platform/gamelibrary.h +++ b/src/platform/gamelibrary.h @@ -99,6 +99,9 @@ __variant GameLibrary_GetGameInfo(int, gameInfo_t); /** Retrieves fields for the currently running game. See gameInfo_t for a list of fields you can query. */ __variant GameLibrary_GetInfo(gameInfo_t); +/** Prints debug info about the currently cached games to the console. */ +void GameLibrary_DebugList(void); + typedef enum { GAMEINFO_NONE, /**< No gameinfo available. This is probably the engine making assumptions. */ @@ -142,4 +145,5 @@ typedef struct int gameinfo_count; gameinfo_t *games; + #endif \ No newline at end of file diff --git a/src/platform/gamelibrary.qc b/src/platform/gamelibrary.qc index 59c28682..5ffe0fbc 100644 --- a/src/platform/gamelibrary.qc +++ b/src/platform/gamelibrary.qc @@ -203,6 +203,7 @@ GameLibrary_LibListParse(int id, string strKey, string strValue) case "startmap": games[id].startmap = strcat("map ", strValue, "\n"); break; + case "trainmap": case "trainingmap": games[id].trainingmap = strcat("map ", strValue, "\n"); break; @@ -404,12 +405,9 @@ GameLibrary_SetDefaults(int id, string gamedirname) games[id].readme = "readme.txt"; games[id].pkgid = -1; -#if 0 if (games[id].gamedir == "valve") { - games[id].pkgname = "valve_patch;addon_furtherdata;addon_holidaymodels"; - games[id].pkgfile = "maps/crossfire.bsp"; /* only found in patches */ + games[id].chatroom = "halflife"; } -#endif } /** Checks if a given game directory was installed manually. */ @@ -434,10 +432,12 @@ GameLibrary_InitCustom(void) int id; int foundself = 0; string gamedirname = __NULL__; - gameinfo_count = 0; + int old_count = gameinfo_count; int packageinfo_count = 0i; int c = 0i; + gameinfo_count = 0i; + /* first count let's all manually installed mods */ for (id = 0; (gamedirname = getgamedirinfo(id, 0)); id++) { gameinfo_count++; @@ -465,15 +465,14 @@ GameLibrary_InitCustom(void) } /* re-allocate the game list */ - memfree(games); - games = memalloc(sizeof(gameinfo_t) * (gameinfo_count + packageinfo_count)); + games = (gameinfo_t *)memrealloc(games, sizeof(gameinfo_t), old_count, (gameinfo_count + packageinfo_count)); /* The things we do for frequent flyer mileage. */ if (!games) error(sprintf("Attempting to allocate mod data for %i entries failed\n", gameinfo_count)); /* now loop through all the mods we found and load in the metadata */ - for (id = 0; id < gameinfo_count; id++) { + for (id = 1; id < gameinfo_count; id++) { gamedirname = getgamedirinfo(id, 0); GameLibrary_SetDefaults(id, gamedirname); @@ -829,3 +828,13 @@ GameLibrary_GetGameInfo(int gameID, gameInfo_t infoType) return __NULL__; } } + +void +GameLibrary_DebugList(void) +{ + for (int i = 0; i < gameinfo_count; i++) { + print(sprintf("%i %s (%s)\n", i, games[i].game, games[i].gamedir)); + } + + print(sprintf("\t%i game(s) loaded\n", gameinfo_count)); +} diff --git a/src/server/mapcycle.qc b/src/server/mapcycle.qc index 7b09f51b..90124b7b 100644 --- a/src/server/mapcycle.qc +++ b/src/server/mapcycle.qc @@ -15,7 +15,6 @@ */ noref var string g_mapcycle_override = __NULL__; -noref var string g_mapCycle = "mapcycle.txt"; void Mapcycle_Load(string filename) @@ -64,7 +63,7 @@ Mapcycle_Load(string filename) void Mapcycle_Init(void) { - string cycleFile = cvar_string("g_mapCycle"); + string cycleFile = autocvar(g_mapCycle, "mapcycle.txt"); /* by default, this will be multiplayer only */ if (g_grMode.IsMultiplayer() == false)