Created
October 19, 2021 15:06
-
-
Save kungfooman/0d01fa206ada1e225740fc4ceef38e00 to your computer and use it in GitHub Desktop.
Fixed con_passive allowing STDIN while playing Quake 3 (ioquake3)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// REMEMBER: Change SUBSYSTEM:WINDOWS to SUBSYSTEM:CONSOLE | |
/* | |
=========================================================================== | |
Copyright (C) 1999-2005 Id Software, Inc. | |
This file is part of Quake III Arena source code. | |
Quake III Arena source code is free software; you can redistribute it | |
and/or modify it under the terms of the GNU General Public License as | |
published by the Free Software Foundation; either version 2 of the License, | |
or (at your option) any later version. | |
Quake III Arena source code is distributed in the hope that it will be | |
useful, but WITHOUT ANY WARRANTY; without even the implied warranty of | |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
GNU General Public License for more details. | |
You should have received a copy of the GNU General Public License | |
along with Quake III Arena source code; if not, write to the Free Software | |
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
=========================================================================== | |
*/ | |
#include "../qcommon/q_shared.h" | |
#include "../qcommon/qcommon.h" | |
#include "sys_local.h" | |
#include <stdio.h> | |
#include <stdlib.h> | |
#include <windows.h> | |
HANDLE handleThread = NULL; | |
DWORD threadID = 0; | |
char *gotMsg = NULL; | |
/* | |
================== | |
CON_Shutdown | |
================== | |
*/ | |
void CON_Shutdown( void ) | |
{ | |
TerminateThread(handleThread, NULL); | |
} | |
DWORD WINAPI threadCheckInput( LPVOID lpParam ) { | |
char input[1024]; | |
while (1) { | |
prompt(input, sizeof input); | |
//printf("got line: %s", input); | |
gotMsg = input; | |
} | |
} | |
/* | |
================== | |
CON_Init | |
================== | |
*/ | |
void CON_Init( void ) | |
{ | |
handleThread = CreateThread( | |
NULL, // default security attributes | |
0, // use default stack size | |
threadCheckInput, // thread function name | |
NULL, // argument to thread function | |
0, // use default creation flags | |
&threadID // returns the thread identifier | |
); | |
printf("CON_Init> created thread: %d\n", handleThread); | |
} | |
// P3t3r from JK Discord (a bit modified by kungfooman) | |
int prompt(char *input, const int MAX_SIZE) { | |
int i = 0; | |
char ch = '\0'; | |
while (1) { | |
ch = (char)getchar(); | |
if (ch == '\n' || ch == EOF) { | |
break; | |
} else if (i < (MAX_SIZE - 1)) { | |
input[i++] = ch; | |
} | |
} | |
input[i] = '\0'; | |
return i; | |
} | |
/* | |
================== | |
CON_Input | |
================== | |
*/ | |
char *CON_Input( void ) | |
{ | |
if (gotMsg) { | |
char *tmp = gotMsg; | |
gotMsg = NULL; | |
return tmp; | |
} | |
return NULL; | |
} | |
/* | |
================== | |
CON_Print | |
================== | |
*/ | |
void CON_Print( const char *msg ) | |
{ | |
if( com_ansiColor && com_ansiColor->integer ) | |
Sys_AnsiColorPrint( msg ); | |
else | |
fputs( msg, stderr ); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment