From b37e57f660fda869a7c71f6e9dfe2232fea5f281 Mon Sep 17 00:00:00 2001 From: Andrei Drexler Date: Sun, 29 Oct 2023 14:54:17 +0100 Subject: [PATCH] Read add-on names from mapdb.json --- Quake/common.c | 4 +++- Quake/common.h | 3 +++ Quake/host.c | 1 - Quake/host_cmd.c | 55 +++++++++++++++++++++++++++++++++++++++++++++++- 4 files changed, 60 insertions(+), 3 deletions(-) diff --git a/Quake/common.c b/Quake/common.c index d1a9e5553..5e397c168 100644 --- a/Quake/common.c +++ b/Quake/common.c @@ -2262,7 +2262,7 @@ static void COM_AddEnginePak (void) COM_AddGameDirectory -- johnfitz -- modified based on topaz's tutorial ================= */ -static void COM_AddGameDirectory (const char *dir) +void COM_AddGameDirectory (const char *dir) { const char *base; int i, j; @@ -2883,6 +2883,8 @@ void COM_InitFilesystem (void) //johnfitz -- modified based on topaz's tutorial com_base_searchpaths = com_searchpaths; COM_ResetGameDirectories(""); + Modlist_Init (); + // add mission pack requests (only one should be specified) if (COM_CheckParm ("-rogue")) COM_AddGameDirectory ("rogue"); diff --git a/Quake/common.h b/Quake/common.h index 12ad57a39..0f26da379 100644 --- a/Quake/common.h +++ b/Quake/common.h @@ -296,6 +296,9 @@ void COM_Init (void); void COM_InitArgv (int argc, char **argv); void COM_InitFilesystem (void); +void COM_ResetGameDirectories (char *newgamedirs); +void COM_AddGameDirectory (const char *dir); + const char *COM_SkipPath (const char *pathname); void COM_StripExtension (const char *in, char *out, size_t outsize); void COM_FileBase (const char *in, char *out, size_t outsize); diff --git a/Quake/host.c b/Quake/host.c index 926c0b4d5..de0b9ed42 100644 --- a/Quake/host.c +++ b/Quake/host.c @@ -1354,7 +1354,6 @@ void Host_Init (void) BGM_Init(); Sbar_Init (); CL_Init (); - Modlist_Init (); //johnfitz ExtraMaps_Init (); //johnfitz DemoList_Init (); //ericw SaveList_Init (); diff --git a/Quake/host_cmd.c b/Quake/host_cmd.c index 5c1b400ba..0b7adcca2 100644 --- a/Quake/host_cmd.c +++ b/Quake/host_cmd.c @@ -680,7 +680,11 @@ static SDL_Thread* extramods_install_thread; const char *Modlist_GetFullName (const filelist_item_t *item) { const modinfo_t *info = (const modinfo_t *) (item + 1); - return info->full_name; + const char *full_name = info->full_name; + // 2021 rerelease episode names are localized + if (full_name && full_name[0] == '$') + full_name = LOC_GetRawString (full_name); + return full_name; } const char *Modlist_GetDescription (const filelist_item_t *item) @@ -1083,6 +1087,7 @@ static void Modlist_Add (const char *name) filelist_item_t *item; modinfo_t *info; int i; + unsigned int path_id; memset (&info, 0, sizeof (info)); item = FileList_AddWithData (name, NULL, sizeof (*info), &modlist); @@ -1120,6 +1125,50 @@ static void Modlist_Add (const char *name) } } + // look for mapdb.json file + if (!info->full_name) + { + char *mapdb = (char *) COM_LoadMallocFile ("mapdb.json", &path_id); + if (mapdb) + { + qboolean is_base_mapdb = !com_searchpaths || path_id < com_searchpaths->path_id; + json_t *json = JSON_Parse (mapdb); + free (mapdb); + if (json) + { + const jsonentry_t *episodes = JSON_Find (json->root, "episodes", JSON_ARRAY); + if (episodes) + { + const jsonentry_t *entry; + for (entry = episodes->firstchild; entry; entry = entry->next) + { + const char *mod_name = JSON_FindString (entry, "name"); + const char *mod_dir = JSON_FindString (entry, "dir"); + if (!mod_name || !mod_dir) + continue; + + // The 2021 rerelease has a single mapdb.json file in id1 with definitions + // for all the included episodes (id1, hipnotic, rogue, dopa & mg1). + // If the mapdb file comes from a base dir we only use the episode name + // if the local mod dir matches the episode dir. + // We also perform a dir check if the name of the episode is "copper" + // in order to avoid showing all Copper-based mods as "Underdark Overbright" + // if they include Copper's mapdb.json unmodified. + // In all other cases we skip the dir check so that players can rename mod dirs + // as they please without losing their descriptions in the add-on menu. + if (is_base_mapdb || q_strcasecmp (mod_dir, "copper") != 0) + if (q_strcasecmp (mod_dir, name) != 0) + continue; + + info->full_name = strdup (mod_name); + break; + } + } + JSON_Free (json); + } + } + } + // look for mod in hard-coded list if (!info->full_name) { @@ -1189,7 +1238,11 @@ static void Modlist_FindLocal (void) continue; #endif if (Modlist_Check (find->name, com_basedirs[i])) + { + COM_AddGameDirectory (find->name); Modlist_Add (find->name); + COM_ResetGameDirectories (""); + } } } }