From 1ea0796b435e07dc4bf7ffa9002dda7281a337c8 Mon Sep 17 00:00:00 2001 From: hendricks266 Date: Sun, 20 Dec 2015 05:18:59 +0000 Subject: [PATCH] Name map best time entries in the cfg by MD4 checksum instead of filename. Existing filename-demarcated personal bests are still read as a fallback if an MD4 is not found, but only MD4 entries are written. Fans of both Lunar Apocalypse and Nuclear Winter should sort out the MapTimes section of their cfg file manually. git-svn-id: https://svn.eduke32.com/eduke32@5470 1a8010ca-5511-0410-912e-c29ae57300e0 --- polymer/eduke32/source/config.c | 31 ++++++++++++++++++++++--------- polymer/eduke32/source/config.h | 4 ++-- polymer/eduke32/source/game.c | 2 +- polymer/eduke32/source/premap.c | 2 +- 4 files changed, 26 insertions(+), 13 deletions(-) diff --git a/polymer/eduke32/source/config.c b/polymer/eduke32/source/config.c index b5090e64f..78de23dbe 100644 --- a/polymer/eduke32/source/config.c +++ b/polymer/eduke32/source/config.c @@ -967,7 +967,7 @@ void CONFIG_WriteSetup(uint32_t flags) Bfflush(NULL); } -static const char *CONFIG_GetMapEntryName(char m[], const char *mapname) +static const char *CONFIG_GetMapEntryName(char m[], char const * const mapname) { strcpy(m, mapname); @@ -983,28 +983,41 @@ static const char *CONFIG_GetMapEntryName(char m[], const char *mapname) return p; } -int32_t CONFIG_GetMapBestTime(const char *mapname) +static void CONFIG_GetMD4EntryName(char m[], uint8_t const * const md4) +{ + sprintf(m, "MD4_%08x%08x%08x%08x", + B_BIG32(B_UNBUF32(&md4[0])), B_BIG32(B_UNBUF32(&md4[4])), + B_BIG32(B_UNBUF32(&md4[8])), B_BIG32(B_UNBUF32(&md4[12]))); +} + +int32_t CONFIG_GetMapBestTime(char const * const mapname, uint8_t const * const mapmd4) { if (!ud.config.setupread) return -1; if (ud.config.scripthandle < 0) return -1; - char m[BMAX_PATH]; - const char *p = CONFIG_GetMapEntryName(m, mapname); + char m[37]; + CONFIG_GetMD4EntryName(m, mapmd4); int32_t t = -1; - SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", p, &t); + if (SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", m, &t)) + { + // fall back to map filenames + char m2[BMAX_PATH]; + char const * const p = CONFIG_GetMapEntryName(m2, mapname); + SCRIPT_GetNumber(ud.config.scripthandle, "MapTimes", p, &t); + } return t; } -int32_t CONFIG_SetMapBestTime(const char *mapname, int32_t tm) +int32_t CONFIG_SetMapBestTime(uint8_t const * const mapmd4, int32_t const tm) { if (ud.config.scripthandle < 0) ud.config.scripthandle = SCRIPT_Init(setupfilename); if (ud.config.scripthandle < 0) return -1; - char m[BMAX_PATH]; - const char *p = CONFIG_GetMapEntryName(m, mapname); + char m[37]; + CONFIG_GetMD4EntryName(m, mapmd4); - SCRIPT_PutNumber(ud.config.scripthandle, "MapTimes", p, tm, FALSE, FALSE); + SCRIPT_PutNumber(ud.config.scripthandle, "MapTimes", m, tm, FALSE, FALSE); return 0; } diff --git a/polymer/eduke32/source/config.h b/polymer/eduke32/source/config.h index c7ae19173..c794d2acf 100644 --- a/polymer/eduke32/source/config.h +++ b/polymer/eduke32/source/config.h @@ -32,8 +32,8 @@ void CONFIG_SetupMouse( void ); void CONFIG_SetupJoystick( void ); void CONFIG_SetDefaultKeys(const char (*keyptr)[MAXGAMEFUNCLEN]); -int32_t CONFIG_GetMapBestTime(const char *mapname); -int32_t CONFIG_SetMapBestTime(const char *mapname, int32_t tm); +int32_t CONFIG_GetMapBestTime(char const * mapname, uint8_t const * mapmd4); +int32_t CONFIG_SetMapBestTime(uint8_t const * mapmd4, int32_t tm); void CONFIG_MapKey(int32_t which, kb_scancode key1, kb_scancode oldkey1, kb_scancode key2, kb_scancode oldkey2); diff --git a/polymer/eduke32/source/game.c b/polymer/eduke32/source/game.c index e5a2ae4c2..a282d8b68 100644 --- a/polymer/eduke32/source/game.c +++ b/polymer/eduke32/source/game.c @@ -12944,7 +12944,7 @@ void G_BonusScreen(int32_t bonusonly) totalclock = 0; if (g_player[myconnectindex].ps->player_par > 0 && (g_player[myconnectindex].ps->player_par < ud.playerbest || ud.playerbest < 0)) - CONFIG_SetMapBestTime(MapInfo[G_LastMapInfoIndex()].filename, g_player[myconnectindex].ps->player_par); + CONFIG_SetMapBestTime(g_loadedMapHack.md4, g_player[myconnectindex].ps->player_par); do { diff --git a/polymer/eduke32/source/premap.c b/polymer/eduke32/source/premap.c index 482224b51..c2f65a649 100644 --- a/polymer/eduke32/source/premap.c +++ b/polymer/eduke32/source/premap.c @@ -1929,7 +1929,7 @@ int32_t G_EnterLevel(int32_t g) G_AlignWarpElevators(); resetpspritevars(g); - ud.playerbest = CONFIG_GetMapBestTime(MapInfo[mii].filename); + ud.playerbest = CONFIG_GetMapBestTime(G_HaveUserMap() ? boardfilename : MapInfo[mii].filename, g_loadedMapHack.md4); G_FadeLoad(0,0,0, 252,0, -28, 4, -1); G_CacheMapData();