shithub: qk1

Download patch

ref: 0b9b33f9b960cd9c56b4d7d7030b8d4676610d4f
parent: 245306e314fe636490b9ad7557a5ea234b589ef2
author: Konstantinn Bonnet <qu7uux@gmail.com>
date: Tue Mar 17 20:46:03 EDT 2015

workaround for misunderstood print(2) weirdness

this "fixes" colored text being garbled in e.g. rogue and probably other mods.
I have no idea what the fuck.

--- a/console.c
+++ b/console.c
@@ -317,13 +317,23 @@
 	va_list		argptr;
 	char		msg[MAXPRINTMSG];
 	static qboolean	inupdate;
-	
-	va_start (argptr,fmt);
-	vseprint (msg,msg+sizeof(msg),fmt,argptr);
-	va_end (argptr);
-	
-// also echo to debugging console
-	Sys_Printf ("%s", msg);	// also echo to debugging console
+	char c, *p;
+
+	/* FIXME: Con_Print uses 1<<7 bit for color; this bit is used in zB rogue to print team names
+	 * in color. for some reason, if this bit is set, print(2) goes apeshit. using vseprint et al
+	 * results in a badly formed string. I've noticed some really fucked up behavior when mixing
+	 * vsnprintf with print. so, we use stdio here instead of vseprint + Sys_Printf for echoing
+	 * to 1 */
+	va_start(argptr, fmt);
+	vsnprintf(msg, sizeof(msg), fmt, argptr);
+	va_end(argptr);
+	for(p = msg; *p; p++){
+		c = *p & 0x7f;
+		if(c < 32 && c != 10 && c != 13 && c != 9)
+			printf("[%02x]", c);
+		else
+			printf("%c", c);
+	}
 
 	if (!con_initialized)
 		return;
--- a/host.c
+++ b/host.c
@@ -282,7 +282,7 @@
 	va_start (argptr,fmt);
 	vseprint (string,string+sizeof(string),fmt,argptr);
 	va_end (argptr);
-	
+
 	for (i=0 ; i<svs.maxclients ; i++)
 		if (svs.clients[i].active && svs.clients[i].spawned)
 		{
--- a/sys_9.c
+++ b/sys_9.c
@@ -57,16 +57,16 @@
 void Sys_Printf (char *fmt, ...)
 {
 	char buf[1024];
-	uchar *p;
+	char *p;
 	va_list arg;
 
 	va_start(arg, fmt);
 	vseprint(buf, buf+sizeof(buf), fmt, arg);
 	va_end(arg);
-	//write(1, buf, out-buf);
-	for(p = (uchar *)buf; *p; p++){
+
+	for(p = buf; *p; p++){
 		*p &= 0x7f;
-		if((*p > 128 || *p < 32) && *p != 10 && *p != 13 && *p != 9)
+		if(*p < 32 && *p != 10 && *p != 13 && *p != 9)
 			print("[%02x]", *p);
 		else
 			print("%c", *p);