Skip to content

Commit

Permalink
Read add-on names from mapdb.json
Browse files Browse the repository at this point in the history
  • Loading branch information
andrei-drexler committed Oct 29, 2023
1 parent a11ae7a commit b37e57f
Show file tree
Hide file tree
Showing 4 changed files with 60 additions and 3 deletions.
4 changes: 3 additions & 1 deletion Quake/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
Expand Down
3 changes: 3 additions & 0 deletions Quake/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion Quake/host.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
Expand Down
55 changes: 54 additions & 1 deletion Quake/host_cmd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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)
{
Expand Down Expand Up @@ -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 ("");
}
}
}
}
Expand Down

0 comments on commit b37e57f

Please sign in to comment.