extract the date out of replay + display em in replay hut

this is kinda horrid, but essentially, the number at the start of replay names is actually the time when the replay was recorded, so i can extract that and convert it to a readable format
this probably can be done alot cleaner lmao
This commit is contained in:
Alug committed 2025-04-11 14:24:26 +02:00
1 parent 1ddc663e8c
commit 1ebebb5690
5 files changed
+110 -13

No files matched your search

+3
View File
@@ -1487,6 +1487,8 @@ static void D_CheckSaturnExtraFiles(void)
memcpy(inputdisplay_cons_t, inputdisplay_cons_temp, sizeof(inputdisplay_cons_t));
}
#include <locale.h>
//
// D_SRB2Main
//
@@ -1684,6 +1686,7 @@ void D_SRB2Main(void)
CONS_Printf("I_InitializeTime()...\n");
I_InitializeTime();
setlocale(LC_TIME, "");
// Make backups of some SOCcable tables.
P_BackupTables();
+18 -11
View File
@@ -954,7 +954,7 @@ void D_RegisterClientCommands(void)
COM_AddCommand("displayplayer", Command_Displayplayer_f);
CV_RegisterVar(&cv_audbuffersize);
CV_RegisterVar(&cv_audbuffersize);
// m_menu.c
CV_RegisterVar(&cv_chatheight);
@@ -965,10 +965,10 @@ void D_RegisterClientCommands(void)
CV_RegisterVar(&cv_chatnotifications);
CV_RegisterVar(&cv_chatbacktint);
CV_RegisterVar(&cv_songcredits);
CV_RegisterVar(&cv_showfreeplay);
CV_RegisterVar(&cv_showfreeplay);
CV_RegisterVar(&cv_skinselectspin);
CV_RegisterVar(&cv_showallmaps);
CV_RegisterVar(&cv_growmusic);
CV_RegisterVar(&cv_supermusic);
@@ -1054,7 +1054,7 @@ void D_RegisterClientCommands(void)
CV_RegisterVar(&cv_midimusicvolume);
#endif
CV_RegisterVar(&cv_numChannels);
#ifdef HAVE_OPENMPT
CV_RegisterVar(&cv_modfilter);
CV_RegisterVar(&cv_stereosep);
@@ -3074,18 +3074,25 @@ static void Command_ReplayMarker(void)
CONS_Printf(M_GetText("You must be in a level to use this.\n"));
return;
}
if (demo.savemode == DSM_WILLAUTOSAVE) {
if (demo.savemode == DSM_WILLAUTOSAVE)
{
demo.savemode = DSM_NOTSAVING;
CONS_Printf("Replay unmarked.\n");
} else {
int adjustedleveltime = leveltime - starttime;
}
else
{
demo.savemode = DSM_WILLAUTOSAVE;
int adjustedleveltime = leveltime - starttime;
if (adjustedleveltime < 0)
adjustedleveltime = 0;
char *title = G_BuildMapTitle(gamemap);
snprintf(demo.titlename, 64, "%s [%i:%02d/%.5s]", title, G_TicsToMinutes(adjustedleveltime, false), G_TicsToSeconds(adjustedleveltime), modeattacking ? "Record Attack" : connectedservername);
if (title)
Z_Free(title);
CONS_Printf("Replay will be saved!\n");
}
}
@@ -4545,7 +4552,7 @@ Command_Addskins (void)
/*
if (fasticmp(COM_Argv(2), "-force") || fasticmp(COM_Argv(2), "-f")) {
CONS_Alert(CONS_NOTICE, M_GetText("Adding file %s. May or may not be a skin.\n"), COM_Argv(1));
P_AddWadFile(COM_Argv(1), 0, true);
P_AddWadFile(COM_Argv(1), 0, true);
} else {
if (DumbStartsWith("KC_", COM_Argv(1))) {
P_AddWadFile(COM_Argv(1), 0, true);
@@ -4625,7 +4632,7 @@ static void Command_GLocalSkin (void)
{
int i;
for (i = 0; i < MAXPLAYERS; ++i)
for (i = 0; i < MAXPLAYERS; ++i)
{
if (!playeringame[i])
continue;
@@ -6012,7 +6019,7 @@ static void Command_ListSkins(void)
}
static void Command_SkinSearch(void)
{
{
size_t i;
UINT16 s;
UINT16 ic = 0;
@@ -6022,7 +6029,7 @@ static void Command_SkinSearch(void)
{
skin_t *skininput = &skins[s];
if (strcasestr(skininput->realname,COM_Argv(i)))
{
{
ic++;
CONS_Printf("%d. %s%s:\x80 %s\n", ic,HU_SkinColorToConsoleColor(skininput->prefcolor),skininput->realname,skininput->name);
}
+74
View File
@@ -6794,6 +6794,71 @@ void G_LoadDemoInfo(menudemo_t *pdemo)
Z_Free(infobuffer);
}
#include <time.h>
#include <locale.h>
static char *G_GetDemoDate(menudemo_t *pdemo)
{
char *datetime;
datetime = malloc(sizeof(pdemo->date)); // mallocma balls
// no mallocma balls... :c
if (!datetime)
{
free(datetime);
return NULL;
}
// get the actual filename Zzz...
const char *filename;
filename = strrchr(pdemo->filepath, '/');
if (!filename)
filename = strrchr(pdemo->filepath, '\\');
if (!filename)
{
free(datetime);
return NULL;
}
filename = filename + 1; // filename, filename, filename, filename.....
// get only the first 10 characters (time before conversion)
char timestr[10];
strncpy(timestr , filename, 10);
// convert it to long Zzz....
long longtime = 0;
longtime = strtol(timestr, NULL, 10);
// then throw it into localtime to get an actual human readable format lmao
struct tm tm_buf;
time_t demo_date = 0;
demo_date = longtime;
localtime_r(&demo_date, &tm_buf);
// cant believe we ended up in 1970
if (tm_buf.tm_year == 70)
{
free(datetime);
return NULL;
}
const char *format;
// US ppl are special (:
if (strstr(setlocale(LC_TIME, NULL), "en_US"))
format = "%m.%d.%Y";
else
format = "%d.%m.%Y";
strftime(datetime, sizeof(pdemo->date), format, &tm_buf);
return datetime;
}
void G_LoadDemoTitle(menudemo_t *pdemo)
{
UINT8 infobuffer[96], *info_p;
@@ -6827,11 +6892,20 @@ void G_LoadDemoTitle(menudemo_t *pdemo)
READUINT8(info_p);
pdemoversion = READUINT16(info_p);
memset(pdemo->date, 0, sizeof(pdemo->date));
switch(pdemoversion)
{
case DEMOVERSION: // latest always supported
// demo title
M_Memcpy(pdemo->title, info_p, 64);
// demo date
char *demodate;
demodate = G_GetDemoDate(pdemo);
if (demodate)
strncpy(pdemo->date, demodate, sizeof(pdemo->date));
free(demodate);
break;
#ifdef DEMO_COMPAT_100
case 0x0001:
+1
View File
@@ -83,6 +83,7 @@ typedef struct menudemo_s {
menudemotype_e type;
char title[65]; // Null-terminated for string prints
char date[11]; // date when replay was recorded
UINT16 map;
UINT8 addonstatus; // What do we need to do addon-wise to play this demo?
UINT8 gametype;
+14 -2
View File
@@ -6826,7 +6826,15 @@ static void ReplayNamesLoadThread(void* userdata)
for (size_t i = 0; i < demolist_all_size; ++i)
{
if (demolist_all_local[i].type != MD_SUBDIR)
{
G_LoadDemoTitle(&demolist_all_local[i]);
// this is fucking horrid, but i wanna be able to search for dates
/*if (demolist_all_local[i].date[0] != '\0')
{
snprintf(demolist_all_local[i].title, sizeof(demolist_all_local[i].title), "%s %s", demolist_all_local[i].title, demolist_all_local[i].date);
}*/
}
}
Lock_search_state();
@@ -7236,8 +7244,12 @@ static void DrawReplayHutReplayInfo(void)
else
V_DrawString(x, y, V_SNAPTOTOP|V_ALLOWLOWERCASE|V_TRANSLUCENT, "Level is not loaded.");
if (demolist[dir_on[menudepthleft]].numlaps)
V_DrawThinString(x, y+9, V_SNAPTOTOP|V_ALLOWLOWERCASE, va("(%d laps)", demolist[dir_on[menudepthleft]].numlaps));
//if (demolist[dir_on[menudepthleft]].numlaps)
//V_DrawThinString(x, y+9, V_SNAPTOTOP|V_ALLOWLOWERCASE, va("(%d laps)", demolist[dir_on[menudepthleft]].numlaps));
// not the final place for this
if (demolist[dir_on[menudepthleft]].date[0] != '\0')
V_DrawThinString(x, y+9, V_SNAPTOTOP|V_ALLOWLOWERCASE, va("%s", demolist[dir_on[menudepthleft]].date));
V_DrawString(x, y+20, V_SNAPTOTOP|V_ALLOWLOWERCASE, demolist[dir_on[menudepthleft]].gametype == GT_RACE ?
va("Race (%s speed)", kartspeed_cons_t[demolist[dir_on[menudepthleft]].kartspeed & ~DF_ENCORE].strvalue) :