+void Sys_InitConsole (void)
+{
+#ifdef QHOST
+ int t;
+
+ // initialize the windows dedicated server console if needed
+ tevent = CreateEvent(NULL, false, false, NULL);
+
+ if (!tevent)
+ Sys_Error ("Couldn't create event");
+#endif
+
+ houtput = GetStdHandle (STD_OUTPUT_HANDLE);
+ hinput = GetStdHandle (STD_INPUT_HANDLE);
+
+ // LadyHavoc: can't check cls.state because it hasn't been initialized yet
+ // if (cls.state == ca_dedicated)
+ if (Sys_CheckParm("-dedicated"))
+ {
+ //if ((houtput == 0) || (houtput == INVALID_HANDLE_VALUE)) // LadyHavoc: on Windows XP this is never 0 or invalid, but hinput is invalid
+ {
+ if (!AllocConsole ())
+ Sys_Error ("Couldn't create dedicated server console (error code %x)", (unsigned int)GetLastError());
+ houtput = GetStdHandle (STD_OUTPUT_HANDLE);
+ hinput = GetStdHandle (STD_INPUT_HANDLE);
+ }
+ if ((houtput == 0) || (houtput == INVALID_HANDLE_VALUE))
+ Sys_Error ("Couldn't create dedicated server console");
+
+
+#ifdef QHOST
+#ifdef _WIN64
+#define atoi _atoi64
+#endif
+ // give QHOST a chance to hook into the console
+ if ((t = Sys_CheckParm ("-HFILE")) > 0)
+ {
+ if (t < sys.argc)
+ hFile = (HANDLE)atoi (sys.argv[t+1]);
+ }
+
+ if ((t = Sys_CheckParm ("-HPARENT")) > 0)
+ {
+ if (t < sys.argc)
+ heventParent = (HANDLE)atoi (sys.argv[t+1]);
+ }
+
+ if ((t = Sys_CheckParm ("-HCHILD")) > 0)
+ {
+ if (t < sys.argc)
+ heventChild = (HANDLE)atoi (sys.argv[t+1]);
+ }
+
+ InitConProc (hFile, heventParent, heventChild);
+#endif
+ }
+
+// because sound is off until we become active
+ S_BlockSound ();
+}
+