menu: support long player skin name

This commit is contained in:
Denis Pauk 2024-06-08 23:21:00 +03:00
parent 41e9b46358
commit 8fd8c2b546

View file

@ -2468,7 +2468,7 @@ Options_MenuInit(void)
s_options_crosshair_box.generic.name = "crosshair"; s_options_crosshair_box.generic.name = "crosshair";
s_options_crosshair_box.generic.callback = CrosshairFunc; s_options_crosshair_box.generic.callback = CrosshairFunc;
s_options_crosshair_box.itemnames = crosshair_names; s_options_crosshair_box.itemnames = crosshair_names;
s_options_pauseonfocus_box.generic.type = MTYPE_SPINCONTROL; s_options_pauseonfocus_box.generic.type = MTYPE_SPINCONTROL;
s_options_pauseonfocus_box.generic.x = 0; s_options_pauseonfocus_box.generic.x = 0;
s_options_pauseonfocus_box.generic.y = (y += 10); s_options_pauseonfocus_box.generic.y = (y += 10);
@ -2988,7 +2988,7 @@ M_Credits_MenuDraw(void)
} }
} }
const char * static const char *
M_Credits_Key(int key) M_Credits_Key(int key)
{ {
key = Key_GetMenuKey(key); key = Key_GetMenuKey(key);
@ -5253,7 +5253,6 @@ static menuseparator_s s_player_hand_title;
static menuseparator_s s_player_rate_title; static menuseparator_s s_player_rate_title;
static menuaction_s s_player_download_action; static menuaction_s s_player_download_action;
#define MAX_DISPLAYNAME 16
#define MAX_PLAYERMODELS 1024 #define MAX_PLAYERMODELS 1024
typedef struct _stringlist typedef struct _stringlist
@ -5321,7 +5320,8 @@ static qboolean IconOfSkinExists(char* skin, char** pcxfiles, int npcxfiles)
} }
// strip file extension // strip file extension
void StripExtension(char* path) static void
StripExtension(char* path)
{ {
int length; int length;
@ -5370,7 +5370,8 @@ ContainsFile(char* path, char* file)
} }
// replace characters in string // replace characters in string
void ReplaceCharacters(char* s, char r, char c) static void
ReplaceCharacters(char* s, char r, char c)
{ {
char* p = s; char* p = s;
@ -5423,7 +5424,7 @@ dircmp_func(const void* _a, const void* _b)
static void static void
PlayerModelFree() PlayerModelFree()
{ {
char* s = 0; char* s = NULL;
// there should be no valid skin names if there is no valid model // there should be no valid skin names if there is no valid model
if (s_modelname.num != 0) if (s_modelname.num != 0)
@ -5505,13 +5506,14 @@ PlayerDirectoryList(void)
int num = 0; int num = 0;
// get a list of "players" subdirectories // get a list of "players" subdirectories
if ((list = FS_ListFiles2(findname, &num, 0, 0)) == 0) if ((list = FS_ListFiles2(findname, &num, 0, 0)) == NULL)
{ {
return false; return false;
} }
if (num > MAX_PLAYERMODELS) if (num > MAX_PLAYERMODELS)
{ {
Com_Printf("Too many player models (%d)!\n", num);
num = MAX_PLAYERMODELS - 1; num = MAX_PLAYERMODELS - 1;
} }
@ -5536,11 +5538,11 @@ PlayerDirectoryList(void)
char* t = list[i]; char* t = list[i];
YQ2_COM_CHECK_OOM(s, "malloc()", MAX_QPATH * sizeof(char)) YQ2_COM_CHECK_OOM(s, "malloc()", MAX_QPATH * sizeof(char))
Q_strlcpy(s, t, MAX_QPATH); Q_strlcpy(s, t, MAX_QPATH);
data[i] = s; data[i] = s;
} }
// free file list // free file list
FS_FreeList(list, num); FS_FreeList(list, num);
@ -5559,8 +5561,6 @@ PlayerModelList(void)
char findname[MAX_QPATH]; char findname[MAX_QPATH];
char** list = 0; char** list = 0;
char** data = 0; char** data = 0;
char* s = 0;
char* t = 0;
int num = 0; int num = 0;
int mdl = 0; int mdl = 0;
qboolean result = true; qboolean result = true;
@ -5575,6 +5575,10 @@ PlayerModelList(void)
// verify the existence of at least one pcx skin // verify the existence of at least one pcx skin
for (int i = 0; i < s_directory.num; ++i) for (int i = 0; i < s_directory.num; ++i)
{ {
char* s = NULL;
char* t = NULL;
int l;
if (s_directory.data[i] == 0) if (s_directory.data[i] == 0)
{ {
continue; continue;
@ -5591,7 +5595,7 @@ PlayerModelList(void)
// contains triangle .md2 model // contains triangle .md2 model
s = s_directory.data[i]; s = s_directory.data[i];
if (ContainsFile(s, "tris.md2") == false) if (ContainsFile(s, "tris.md2") == false)
{ {
continue; // invalid player model continue; // invalid player model
@ -5628,7 +5632,7 @@ PlayerModelList(void)
data = (char**)malloc((s_skinnames[mdl].num + 1) * sizeof(char*)); data = (char**)malloc((s_skinnames[mdl].num + 1) * sizeof(char*));
YQ2_COM_CHECK_OOM(data, "malloc()", (s_skinnames[mdl].num + 1) * sizeof(char*)) YQ2_COM_CHECK_OOM(data, "malloc()", (s_skinnames[mdl].num + 1) * sizeof(char*))
memset(data, 0, (s_skinnames[mdl].num + 1) * sizeof(char*)); memset(data, 0, (s_skinnames[mdl].num + 1) * sizeof(char*));
s_skinnames[mdl].data = data; s_skinnames[mdl].data = data;
s_skinnames[mdl].num = 0; s_skinnames[mdl].num = 0;
@ -5647,13 +5651,14 @@ PlayerModelList(void)
{ {
ReplaceCharacters(list[k], '\\', '/'); ReplaceCharacters(list[k], '\\', '/');
s = (char*)malloc(MAX_DISPLAYNAME);
t = strrchr(list[k], '/'); t = strrchr(list[k], '/');
YQ2_COM_CHECK_OOM(s, "malloc()", MAX_DISPLAYNAME * sizeof(char)) l = strlen(t) + 1;
s = (char*)malloc(l);
YQ2_COM_CHECK_OOM(s, "malloc()", l * sizeof(char))
StripExtension(t); StripExtension(t);
Q_strlcpy(s, t + 1, MAX_DISPLAYNAME); Q_strlcpy(s, t + 1, l);
data[s_skinnames[mdl].num++] = s; data[s_skinnames[mdl].num++] = s;
} }
@ -5664,12 +5669,13 @@ PlayerModelList(void)
qsort(s_skinnames[mdl].data, s_skinnames[mdl].num, sizeof(char**), Q_sort_stricmp); qsort(s_skinnames[mdl].data, s_skinnames[mdl].num, sizeof(char**), Q_sort_stricmp);
// at this point we have a valid player model // at this point we have a valid player model
s = (char*)malloc(MAX_DISPLAYNAME);
t = strrchr(s_directory.data[i], '/'); t = strrchr(s_directory.data[i], '/');
l = strlen(t) + 1;
s = (char*)malloc(l);
YQ2_COM_CHECK_OOM(s, "malloc()", MAX_DISPLAYNAME * sizeof(char)) YQ2_COM_CHECK_OOM(s, "malloc()", l * sizeof(char))
Q_strlcpy(s, t + 1, MAX_DISPLAYNAME); Q_strlcpy(s, t + 1, l);
s_modelname.data[s_modelname.num++] = s; s_modelname.data[s_modelname.num++] = s;
mdl = s_modelname.num; mdl = s_modelname.num;
@ -5733,8 +5739,8 @@ PlayerConfig_MenuInit(void)
extern cvar_t *skin; extern cvar_t *skin;
cvar_t *hand = Cvar_Get( "hand", "0", CVAR_USERINFO | CVAR_ARCHIVE ); cvar_t *hand = Cvar_Get( "hand", "0", CVAR_USERINFO | CVAR_ARCHIVE );
static const char *handedness[] = { "right", "left", "center", 0 }; static const char *handedness[] = { "right", "left", "center", 0 };
char mdlname[MAX_DISPLAYNAME * 2]; char mdlname[MAX_QPATH];
char imgname[MAX_DISPLAYNAME]; char imgname[MAX_QPATH];
int mdlindex = 0; int mdlindex = 0;
int imgindex = 0; int imgindex = 0;
int i = 0; int i = 0;
@ -5745,12 +5751,12 @@ PlayerConfig_MenuInit(void)
return false; return false;
} }
Q_strlcpy(mdlname, skin->string, MAX_DISPLAYNAME * 2); Q_strlcpy(mdlname, skin->string, sizeof(mdlname));
ReplaceCharacters(mdlname, '\\', '/' ); ReplaceCharacters(mdlname, '\\', '/' );
if (strchr(mdlname, '/')) if (strchr(mdlname, '/'))
{ {
Q_strlcpy(imgname, strchr(mdlname, '/') + 1, MAX_DISPLAYNAME); Q_strlcpy(imgname, strchr(mdlname, '/') + 1, sizeof(imgname));
*strchr(mdlname, '/') = 0; *strchr(mdlname, '/') = 0;
} }
else else