diff --git a/codemp/CMakeLists.txt b/codemp/CMakeLists.txt
index 6553df7ba7..6e41ad8117 100644
--- a/codemp/CMakeLists.txt
+++ b/codemp/CMakeLists.txt
@@ -538,7 +538,7 @@ if(BuildMPEngine)
set(MPEngineSysFiles
${MPEngineSysFiles}
"${SharedDir}/sys/sys_win32.cpp"
- "${SharedDir}/sys/con_passive.cpp"
+ "${SharedDir}/sys/con_win32.cpp"
)
else(WIN32)
set(MPEngineSysFiles
diff --git a/shared/sys/con_local.h b/shared/sys/con_local.h
index a207823b3e..4c5cc60abc 100644
--- a/shared/sys/con_local.h
+++ b/shared/sys/con_local.h
@@ -23,12 +23,15 @@ along with this program; if not, see .
#include
-/* con_passive.cpp | con_win32.cpp | con_tty.cpp */
+/* con_win32.cpp | con_tty.cpp */
void CON_Shutdown( void );
void CON_Init( void );
char *CON_Input( void );
void CON_Print( const char *msg );
+void CON_CreateConsoleWindow( void );
+void CON_DeleteConsoleWindow( void );
+
/* con_log.cpp */
void ConsoleLogAppend( const char *string );
void ConsoleLogWriteOut( FILE *fp );
diff --git a/shared/sys/con_win32.cpp b/shared/sys/con_win32.cpp
index 30261a2a81..eaee4b2426 100644
--- a/shared/sys/con_win32.cpp
+++ b/shared/sys/con_win32.cpp
@@ -50,6 +50,9 @@ static int qconsole_cursor;
static HANDLE qconsole_hout;
static HANDLE qconsole_hin;
+static FILE *stdinptr, *stdoutptr, *stderrptr;
+static qboolean never_detach;
+
/*
==================
CON_ColorCharToAttrib
@@ -190,6 +193,9 @@ static void CON_Show( void )
CHAR_INFO line[ MAX_EDIT_LINE ];
WORD attrib;
+ if( !GetConsoleWindow() )
+ return;
+
GetConsoleScreenBufferInfo( qconsole_hout, &binfo );
// if we're in the middle of printf, don't bother writing the buffer
@@ -270,6 +276,7 @@ CON_Shutdown
void CON_Shutdown( void )
{
CON_Hide( );
+ SetConsoleCtrlHandler( CON_CtrlHandler, FALSE );
SetConsoleMode( qconsole_hin, qconsole_orig_mode );
SetConsoleCursorInfo( qconsole_hout, &qconsole_orig_cursorinfo );
SetConsoleTextAttribute( qconsole_hout, qconsole_attrib );
@@ -287,6 +294,20 @@ void CON_Init( void )
CONSOLE_SCREEN_BUFFER_INFO info;
int i;
+#ifndef DEDICATED
+ if( AttachConsole( ATTACH_PARENT_PROCESS ) ) {
+ // started from console
+ stdinptr = freopen( "CONIN$", "r", stdin );
+ stdoutptr = freopen( "CONOUT$", "w", stdout );
+ stderrptr = freopen( "CONOUT$", "w", stderr );
+ never_detach = qtrue;
+ }
+#endif
+
+#ifdef _DEBUG
+ never_detach = qtrue;
+#endif
+
// handle Ctrl-C or other console termination
SetConsoleCtrlHandler( CON_CtrlHandler, TRUE );
@@ -309,7 +330,11 @@ void CON_Init( void )
qconsole_attrib = info.wAttributes;
qconsole_backgroundAttrib = qconsole_attrib & (BACKGROUND_BLUE|BACKGROUND_GREEN|BACKGROUND_RED|BACKGROUND_INTENSITY);
+#ifdef DEDICATED
SetConsoleTitle(CLIENT_WINDOW_TITLE " Dedicated Server Console");
+#else
+ SetConsoleTitle(CLIENT_WINDOW_TITLE " Console");
+#endif
// initialize history
for( i = 0; i < QCONSOLE_HISTORY; i++ )
@@ -319,6 +344,53 @@ void CON_Init( void )
SetConsoleTextAttribute( qconsole_hout, CON_ColorCharToAttrib( COLOR_WHITE ) );
}
+/*
+==================
+CON_CreateConsoleWindow
+==================
+*/
+void CON_CreateConsoleWindow(void) {
+ if (!GetConsoleWindow()) {
+ CON_Shutdown();
+
+ if (AllocConsole()) {
+ stdinptr = freopen("CONIN$", "r", stdin);
+ stdoutptr = freopen("CONOUT$", "w", stdout);
+ stderrptr = freopen("CONOUT$", "w", stderr);
+ }
+
+ CON_Init();
+ }
+}
+
+/*
+==================
+CON_DeleteConsoleWindow
+==================
+*/
+void CON_DeleteConsoleWindow(void) {
+ if (GetConsoleWindow() && !never_detach) {
+ CON_Shutdown();
+
+ if (stdinptr)
+ fclose(stdinptr);
+
+ if (stdoutptr)
+ fclose(stdoutptr);
+
+ if (stderrptr)
+ fclose(stderrptr);
+
+ if (FreeConsole()) {
+ freopen("CONIN$", "r", stdin);
+ freopen("CONOUT$", "w", stdout);
+ freopen("CONOUT$", "w", stderr);
+ }
+
+ CON_Init();
+ }
+}
+
/*
==================
CON_Input
@@ -547,6 +619,9 @@ CON_Print
*/
void CON_Print( const char *msg )
{
+ if ( !GetConsoleWindow() )
+ return;
+
CON_Hide( );
CON_WindowsColorPrint( msg );
diff --git a/shared/sys/sys_main.cpp b/shared/sys/sys_main.cpp
index 9537f8a578..cb1a607064 100644
--- a/shared/sys/sys_main.cpp
+++ b/shared/sys/sys_main.cpp
@@ -696,6 +696,9 @@ int main ( int argc, char* argv[] )
char commandLine[ MAX_STRING_CHARS ] = { 0 };
Sys_PlatformInit();
+#if defined(_DEBUG) && !defined(DEDICATED)
+ CON_CreateConsoleWindow();
+#endif
CON_Init();
// get the initial time base