From 0e70fd8ac73453acee3ce17b6e41ab8a09f59edc Mon Sep 17 00:00:00 2001 From: NepDisk Date: Sun, 9 Feb 2025 14:04:15 -0500 Subject: [PATCH] Patch alias and add listskins https://github.com/Indev450/SRB2Kart-Saturn/pull/33 --- src/command.c | 36 +++++++++++++++- src/d_netcmd.c | 115 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 150 insertions(+), 1 deletion(-) diff --git a/src/command.c b/src/command.c index 047436772..29039d574 100644 --- a/src/command.c +++ b/src/command.c @@ -714,10 +714,44 @@ static void COM_ExecuteString(char *ptext) static void COM_Alias_f(void) { cmdalias_t *a; + const char *alias_format = "\x87%-8s:\x80 %s\n"; + int argc = COM_Argc(); - if (COM_Argc() < 3) + if (argc == 2) { + const char *begin = COM_Argv(1); + size_t szBegin = strlen(begin); + + /* Display all aliases that start with `begin`. */ + CONS_Printf(M_GetText("All aliases that start with \x87'%s'\x80 are:\n"), begin); + + int count = 0; + for (cmdalias_t *head = com_alias; head->next != NULL; head = head->next) + { + if (strncmp(begin, head->name, szBegin) == 0) + { + CONS_Printf(alias_format, head->name, head->value); + count++; + } + } + + if (count == 0) + { + CONS_Printf(M_GetText("There are none.\n")); + } + + return; + } + else if (argc < 3) + { + /* Display alias subtext, show all aliases. */ CONS_Printf(M_GetText("alias : create a shortcut command that executes other command(s)\n")); + + for (cmdalias_t *head = com_alias; head->next != NULL; head = head->next) + { + CONS_Printf(alias_format, head->name, head->value); + } + return; } diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 1d8723e7a..a1b62cc56 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -217,6 +217,9 @@ static void Command_ShowTime_f(void); static void Command_Isgamemodified_f(void); static void Command_Cheats_f(void); + +static void Command_ListSkins(void); + #ifdef _DEBUG static void Command_Togglemodified_f(void); static void Command_Archivetest_f(void); @@ -1130,6 +1133,32 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_discordstreamer); CV_RegisterVar(&cv_discordasks); #endif + + COM_AddCommand("listskins", Command_ListSkins); + +} + +/** + * Searches the skins list for a skin of the "realname", if found, changes + * the CVAR value to be the "name" of the skin. + * \sa cv_skin, Skin_OnChange, Skin2_OnChange + * \author karen + */ +static void Skin_FindRealNameSkin(consvar_t *cvar) +{ + // Not the best way to implements this but it will do. + + int i; + const char *value = cvar->string; + for (i = 0; i < numskins; i++) + { + if (strncmp(value, skins[i].realname, sizeof skins[i].realname) == 0) + { + // Change the cvar to be the value of the name. + CV_StealthSet(cvar, skins[i].name); + return; + } + } } /** Checks if a name (as received from another player) is okay. @@ -6320,6 +6349,8 @@ static void Followercolor4_OnChange(void) */ static void Skin_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin[0]); + if (!Playing()) return; // do whatever you want @@ -6346,6 +6377,8 @@ static void Skin_OnChange(void) */ static void Skin2_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin[1]); + if (!Playing() || !splitscreen) return; // do whatever you want @@ -6360,6 +6393,8 @@ static void Skin2_OnChange(void) static void Skin3_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin[2]); + if (!Playing() || splitscreen < 2) return; // do whatever you want @@ -6374,6 +6409,8 @@ static void Skin3_OnChange(void) static void Skin4_OnChange(void) { + Skin_FindRealNameSkin(&cv_skin[3]); + if (!Playing() || splitscreen < 3) return; // do whatever you want @@ -6386,6 +6423,84 @@ static void Skin4_OnChange(void) } } +static void Command_ListSkins(void) +{ + int i; + int page = 0; + int numpages = numskins / 10 + (numskins % 10 ? 1 : 0); + int longest_name = 0; + + if (COM_Argc() > 1) + { + if (sscanf(COM_Argv(1), " %d", &page) == 0) + { + CONS_Printf("Expected a number.\n"); + return; + } + else if (page > numpages) + { + CONS_Printf("There are only %d pages.\n", numpages); + return; + } + else if (page < 0) + { + CONS_Printf("Page number cannot be negative.\n"); + return; + } + else if (page == 0) + { + CONS_Printf("There is no 0th page. (What are you a programmer?)\n"); + return; + } + + --page; + } + + CONS_Printf("Total %d skins. Page (%d/%d)\n", numskins, page + 1, numpages); + + // Find the longest name and realname in the skins list. (used for alignment) + for (i = page * 10; i < numskins && i < (page + 1) * 10; i++) + { + int length; + skin_t *skin = &skins[i]; + + if ((length = strlen(skin->name)) > longest_name) + longest_name = length; + } + + for (i = page * 10; i < numskins && i < (page + 1) * 10; i++) + { + skin_t *skin = &skins[i]; + UINT16 chatcolor = skincolors[skin->prefcolor].chatcolor; + char color_prefix[2]; + + if (chatcolor > V_TANMAP) + { + sprintf(color_prefix, "%c", '\x80'); + } + else + { + sprintf(color_prefix, "%c", '\x80' + (chatcolor >> V_CHARCOLORSHIFT)); + } + + CONS_Printf( + "%s[%-*s]\x80 %s\n", + color_prefix, + longest_name, + skin->name, + skin->realname); + } + + if (page + 1 != numpages) + { + CONS_Printf("Use \"listskins %d\" to see the next page.\n", page + 2); + } + else + { + CONS_Printf("There are no more pages.\n"); + } +} + /** Sends a color change for the console player, unless that player is moving. * \sa cv_playercolor, Color2_OnChange, Skin_OnChange * \author Graue