diff --git a/src/g_game.c b/src/g_game.c index 1b18443e5..5ac23d797 100644 --- a/src/g_game.c +++ b/src/g_game.c @@ -7156,6 +7156,58 @@ void G_LoadDemoInfo(menudemo_t *pdemo) Z_Free(infobuffer); } +void G_LoadDemoTitle(menudemo_t *pdemo) +{ + UINT8 infobuffer[96], *info_p; + UINT16 pdemoversion; + size_t count; + + FILE *handle = fopen(pdemo->filepath, "rb"); + + if (!handle) + { + CONS_Alert(CONS_ERROR, M_GetText("Failed to read file '%s'.\n"), pdemo->filepath); + sprintf(pdemo->title, "INVALID REPLAY"); + return; + } + + count = fread(infobuffer, 1, 96, handle); + fclose(handle); + info_p = infobuffer; + + // First check isn't too accurate technically, but well, valid replays should be larger than that anyway + if (count < 96 || memcmp(info_p, DEMOHEADER, 12)) + { + CONS_Alert(CONS_ERROR, M_GetText("%s is not a SRB2Kart replay file.\n"), pdemo->filepath); + sprintf(pdemo->title, "INVALID REPLAY"); + Z_Free(infobuffer); + return; + } + + info_p += 12; // DEMOHEADER + + READUINT8(info_p); + READUINT8(info_p); + pdemoversion = READUINT16(info_p); + + switch(pdemoversion) + { + case DEMOVERSION: // latest always supported + // demo title + M_Memcpy(pdemo->title, info_p, 64); + break; +#ifdef DEMO_COMPAT_100 + case 0x0001: + sprintf(pdemo->title, "Legacy Replay"); + break; +#endif + // too old, cannot support. + default: + CONS_Alert(CONS_ERROR, M_GetText("%s is an incompatible replay format and cannot be played.\n"), pdemo->filepath); + sprintf(pdemo->title, "INVALID REPLAY"); + } +} + // // G_PlayDemo // diff --git a/src/g_game.h b/src/g_game.h index bfc158583..977cc4dc3 100644 --- a/src/g_game.h +++ b/src/g_game.h @@ -265,6 +265,7 @@ void G_DeferedInitNew(boolean pencoremode, const char *mapname, INT32 pickedchar void G_DoLoadLevel(boolean resetplayer); void G_LoadDemoInfo(menudemo_t *pdemo); +void G_LoadDemoTitle(menudemo_t *pdemo); // For use in replay search feature void G_DeferedPlayDemo(const char *demo); // Can be called by the startup code or M_Responder, calls P_SetupLevel. diff --git a/src/m_menu.c b/src/m_menu.c index a361a1eb5..77b5e5498 100644 --- a/src/m_menu.c +++ b/src/m_menu.c @@ -466,7 +466,7 @@ static void Dummystaff_OnChange(void); // ========================================================================== // How much replays are checked per frame when using search -consvar_t cv_replaysearchrate = {"replaysearchrate", "50", CV_SAVE, CV_Natural, NULL, 0, NULL, NULL, 0, 0, NULL }; +consvar_t cv_replaysearchrate = {"replaysearchrate", "1000", CV_SAVE, CV_Natural, NULL, 0, NULL, NULL, 0, 0, NULL }; consvar_t cv_showfocuslost = {"showfocuslost", "Yes", CV_SAVE, CV_YesNo, NULL, 0, NULL, NULL, 0, 0, NULL }; @@ -6782,10 +6782,8 @@ static void M_HutCheckReplays(size_t maxnum) break; case MD_NOTLOADED: - G_LoadDemoInfo(&demolist_all[replayquerycheck]); - ++maxnum; // Gonna check this one next iteration, don't decrease our number of tries yet - break; - + G_LoadDemoTitle(&demolist_all[replayquerycheck]); + /* FALLTHRU */ case MD_OUTDATED: case MD_LOADED: if (strcasestr(demolist_all[replayquerycheck].title, replayqueryinput) != NULL)