diff --git a/src/d_main.c b/src/d_main.c index 71541c2cc..49da3bb01 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -1487,6 +1487,8 @@ static void D_CheckSaturnExtraFiles(void) memcpy(inputdisplay_cons_t, inputdisplay_cons_temp, sizeof(inputdisplay_cons_t)); } +#include + // // 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(); diff --git a/src/d_netcmd.c b/src/d_netcmd.c index 3f7641af8..9b68717db 100644 --- a/src/d_netcmd.c +++ b/src/d_netcmd.c @@ -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); @@ -1093,6 +1093,8 @@ void D_RegisterClientCommands(void) CV_RegisterVar(&cv_verticallook[i]); } + CV_RegisterVar(&cv_demodateformat); + // ingame object placing COM_AddCommand("objectplace", Command_ObjectPlace_f); COM_AddCommand("writethings", Command_Writethings_f); @@ -3074,18 +3076,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 +4554,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 +4634,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 +6021,7 @@ static void Command_ListSkins(void) } static void Command_SkinSearch(void) -{ +{ size_t i; UINT16 s; UINT16 ic = 0; @@ -6022,7 +6031,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); } diff --git a/src/g_game.c b/src/g_game.c index 3cbe4bfb8..54e509be6 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -59,6 +59,10 @@ #include "discord.h" #endif +// for replay dates +#include +#include + gameaction_t gameaction; gamestate_t gamestate = GS_NULL; UINT8 ultimatemode = false; @@ -341,6 +345,9 @@ consvar_t cv_maxdemosize = {"maxdemosize", "10", CV_SAVE, maxdemosize_cons_t, NU static CV_PossibleValue_t demochangemap_cons_t[] = {{0, "Disabled"}, {1, "Diff Map"}, {2, "Always"}, {0, NULL}}; consvar_t cv_demochangemap = {"netdemo_savemapchange", "Disabled", CV_SAVE, demochangemap_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; +static CV_PossibleValue_t demodateformat_cons_t[] = {{0, "Automatic"}, {1, "EU"}, {2, "US"}, {0, NULL}}; +consvar_t cv_demodateformat = {"netdemo_dateformat", "Automatic", CV_SAVE, demodateformat_cons_t, NULL, 0, NULL, NULL, 0, 0, NULL}; + // Analog Control void SendWeaponPref(void); void SendWeaponPref2(void); @@ -6653,6 +6660,9 @@ void G_LoadDemoInfo(menudemo_t *pdemo) subversion = READUINT8(info_p); pdemoversion = READUINT16(info_p); + memset(pdemo->version, 0, sizeof(pdemo->version)); + snprintf(pdemo->version, sizeof(pdemo->version), "v%d.%d", version, subversion); + switch(pdemoversion) { case DEMOVERSION: // latest always supported @@ -6794,6 +6804,108 @@ void G_LoadDemoInfo(menudemo_t *pdemo) Z_Free(infobuffer); } +#if defined (_WIN32) +// return the file creation time +// useful for demos that were renamed +static long G_GetCreationTime(char *filepath) +{ + struct stat fileinfo; + + if (stat(filepath, &fileinfo) == 0) + return fileinfo.st_ctime; + + return 0; +} +#endif + +static char *G_GetDemoDate(menudemo_t *pdemo) +{ + char *datetime; + datetime = malloc(sizeof(pdemo->date)); // mallocma balls + + // no mallocma balls... :c + if (!datetime) + { + return NULL; + } + + time_t file_time = 0; + + // get le filepath + char *filename; + filename = strdup(pdemo->filepath); + +#if defined (_WIN32) + if (!filename) + { + // if we cant get a filename try just getting the file create time + file_time = G_GetCreationTime(pdemo->filepath); + goto skipfilenametime; + } +#else + if (!filename) + { + free(datetime); + return NULL; + } +#endif + + // get the actual filename Zzz... + nameonly(filename); + + // convert it to long Zzz.... + file_time = strtol(filename, NULL, 10); + free(filename); // dont need this anymore a + +#if defined (_WIN32) +skipfilenametime: +#endif + + // then throw it into localtime to get an actual human readable format lmao + struct tm *tm_buf = NULL; + tm_buf = localtime(&file_time); + + // cant believe we ended up in 1970 + if (tm_buf == NULL || tm_buf->tm_year <= 110) + { +#if defined (_WIN32) + // uh ohh, we got an invalid time + // try one more time getting the creation time + file_time = G_GetCreationTime(pdemo->filepath); + tm_buf = localtime(&file_time); + + if (tm_buf == NULL || tm_buf->tm_year <= 110) + { + free(datetime); + return NULL; + } + + goto gotcreationtime; +#else + free(datetime); + return NULL; +#endif + } + +#if defined (_WIN32) +gotcreationtime: +#endif + + const char *format; + + // US ppl are special (: + if (cv_demodateformat.value == 2) + format = "%m.%d.%Y"; + else if (cv_demodateformat.value == 1) + format = "%d.%m.%Y"; + else + format = strstr(setlocale(LC_TIME, NULL), "en_US") ? "%m.%d.%Y" : "%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 +6939,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: diff --git a/src/g_game.h b/src/g_game.h index 39b266b5a..e50557a9d 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -42,6 +42,7 @@ extern savebuffer_t demobuf; // demoplaying back and demo recording extern consvar_t cv_recordmultiplayerdemos, cv_netdemosyncquality, cv_maxdemosize, cv_demochangemap; +extern consvar_t cv_demodateformat; // Publicly-accessible demo vars struct demovars_s { @@ -83,6 +84,8 @@ typedef struct menudemo_s { menudemotype_e type; char title[65]; // Null-terminated for string prints + char date[11]; // date when replay was recorded + char version[12]; // combined version and subversion UINT16 map; UINT8 addonstatus; // What do we need to do addon-wise to play this demo? UINT8 gametype; diff --git a/src/m_menu.c b/src/m_menu.c index 08394c2c9..32e28c888 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -647,6 +647,7 @@ static menuitem_t MISC_ReplayOptionsMenu[] = {IT_CVAR|IT_STRING, NULL, "Sync Check Interval", &cv_netdemosyncquality, 20}, {IT_CVAR|IT_STRING, NULL, "Max demo size (MiB)", &cv_maxdemosize, 30}, {IT_CVAR|IT_STRING, NULL, "Replay Search Rate", &cv_replaysearchrate, 40}, + {IT_CVAR|IT_STRING, NULL, "Replay Date Format", &cv_demodateformat, 50}, }; static tic_t playback_last_menu_interaction_leveltime = 0; @@ -6826,7 +6827,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(); @@ -7195,7 +7204,7 @@ static void DrawReplayHutReplayInfo(void) break; // Can't think of anything to draw here right now case MD_OUTDATED: - V_DrawThinString(17, 64, V_SNAPTOTOP|V_ALLOWLOWERCASE|V_TRANSLUCENT|highlightflags, "Recorded on an outdated version."); + V_DrawThinString(17, 64, V_SNAPTOTOP|V_ALLOWLOWERCASE|V_TRANSLUCENT|highlightflags, va("Recorded on an outdated version. %s", demolist[dir_on[menudepthleft]].version)); /*fallthru*/ default: // Draw level stuff @@ -7236,8 +7245,16 @@ static void DrawReplayHutReplayInfo(void) else V_DrawString(x, y, V_SNAPTOTOP|V_ALLOWLOWERCASE|V_TRANSLUCENT, "Level is not loaded."); + INT32 datew = 0; + + if (demolist[dir_on[menudepthleft]].date[0] != '\0') + { + datew = V_StringWidth(demolist[dir_on[menudepthleft]].date, 0); + V_DrawThinString(x, y+9, V_SNAPTOTOP|V_ALLOWLOWERCASE, va("%s", demolist[dir_on[menudepthleft]].date)); + } + if (demolist[dir_on[menudepthleft]].numlaps) - V_DrawThinString(x, y+9, V_SNAPTOTOP|V_ALLOWLOWERCASE, va("(%d laps)", demolist[dir_on[menudepthleft]].numlaps)); + V_DrawThinString(x+datew, y+9, V_SNAPTOTOP|V_ALLOWLOWERCASE, va("(%d laps)", demolist[dir_on[menudepthleft]].numlaps)); 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) :