diff --git a/engine/client/cl_main.c b/engine/client/cl_main.c index b271d7be..a0e56d1c 100644 --- a/engine/client/cl_main.c +++ b/engine/client/cl_main.c @@ -2836,6 +2836,7 @@ void CL_Init( void ) MSG_Init( &cls.datagram, "cls.datagram", cls.datagram_buf, sizeof( cls.datagram_buf )); IN_TouchInit(); + Con_LoadHistory(); if( !CL_LoadProgs( va( "%s/%s", GI->dll_path, SI.clientlib))) Host_Error( "can't initialize %s: %s\n", SI.clientlib, COM_GetLibraryError() ); diff --git a/engine/client/client.h b/engine/client/client.h index 5b6c695c..b093b30a 100644 --- a/engine/client/client.h +++ b/engine/client/client.h @@ -1051,6 +1051,7 @@ void Con_Bottom( void ); void Con_Top( void ); void Con_PageDown( int lines ); void Con_PageUp( int lines ); +void Con_LoadHistory( void ); // // s_main.c diff --git a/engine/client/console.c b/engine/client/console.c index 13c36d8f..87268412 100644 --- a/engine/client/console.c +++ b/engine/client/console.c @@ -1068,6 +1068,61 @@ int Con_DrawString( int x, int y, const char *string, rgba_t setColor ) return Con_DrawGenericString( x, y, string, setColor, false, -1 ); } +void Con_LoadHistory( void ) +{ + const char *aFile = FS_LoadFile( "console_history.txt", NULL, true ); + const char *pLine = aFile, *pFile = aFile; + int i; + + if( !aFile ) + return; + + while( true ) + { + if( !*pFile ) + break; + if( *pFile == '\n') + { + int len = pFile - pLine + 1; + if( len > 255 ) len = 255; + Con_ClearField( &con.historyLines[con.nextHistoryLine] ); + field_t *f = &con.historyLines[con.nextHistoryLine % CON_HISTORY]; + f->widthInChars = con.linewidth; + f->cursor = len - 1; + Q_strncpy( f->buffer, pLine, len); + con.nextHistoryLine++; + pLine = pFile + 1; + } + pFile++; + } + + for( i = con.nextHistoryLine; i < CON_HISTORY; i++ ) + { + Con_ClearField( &con.historyLines[i] ); + con.historyLines[i].widthInChars = con.linewidth; + } + + con.historyLine = con.nextHistoryLine; + +} + +void Con_SaveHistory( void ) +{ + int historyStart = con.nextHistoryLine - CON_HISTORY; + int i; + file_t *f; + + if( historyStart < 0 ) + historyStart = 0; + + f = FS_Open("console_history.txt", "w", true ); + + for( i = historyStart; i < con.nextHistoryLine; i++ ) + FS_Printf( f, "%s\n", con.historyLines[i % CON_HISTORY].buffer ); + + FS_Close(f); +} + /* ================ Con_Init @@ -1104,12 +1159,6 @@ void Con_Init( void ) Con_ClearField( &con.chat ); con.chat.widthInChars = con.linewidth; - for( i = 0; i < CON_HISTORY; i++ ) - { - Con_ClearField( &con.historyLines[i] ); - con.historyLines[i].widthInChars = con.linewidth; - } - Cmd_AddCommand( "toggleconsole", Con_ToggleConsole_f, "opens or closes the console" ); Cmd_AddCommand( "con_color", Con_SetColor_f, "set a custom console color" ); Cmd_AddCommand( "clear", Con_Clear_f, "clear console history" ); @@ -1138,6 +1187,7 @@ void Con_Shutdown( void ) con.buffer = NULL; con.lines = NULL; + Con_SaveHistory(); } /*