]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - menu.c
Add .md extension to README so it actually parses the markdown
[xonotic/darkplaces.git] / menu.c
diff --git a/menu.c b/menu.c
index 9d3a4c20f6d039307dd1709e44391377d65037e0..2dc43ec921834070a93bf383c764274a09b0f2cc 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -18,9 +18,7 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 */
 #include "quakedef.h"
-#ifdef CONFIG_CD
 #include "cdaudio.h"
-#endif
 #include "image.h"
 #include "progsvm.h"
 
@@ -30,36 +28,36 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #define TYPE_GAME 2
 #define TYPE_BOTH 3
 
-static cvar_t forceqmenu = { 0, "forceqmenu", "0", "enables the quake menu instead of the quakec menu.dat (if present)" };
-static cvar_t menu_progs = { 0, "menu_progs", "menu.dat", "name of quakec menu.dat file" };
+static cvar_t forceqmenu = {CF_CLIENT, "forceqmenu", "0", "enables the quake menu instead of the quakec menu.dat (if present)"};
+static cvar_t menu_progs = {CF_CLIENT, "menu_progs", "menu.dat", "name of quakec menu.dat file"};
 
 static int NehGameType;
 
 enum m_state_e m_state;
 char m_return_reason[128];
 
-void M_Menu_Main_f (void);
-       void M_Menu_SinglePlayer_f (void);
-               void M_Menu_Transfusion_Episode_f (void);
-                       void M_Menu_Transfusion_Skill_f (void);
-               void M_Menu_Load_f (void);
-               void M_Menu_Save_f (void);
-       void M_Menu_MultiPlayer_f (void);
-               void M_Menu_Setup_f (void);
-       void M_Menu_Options_f (void);
-       void M_Menu_Options_Effects_f (void);
-       void M_Menu_Options_Graphics_f (void);
-       void M_Menu_Options_ColorControl_f (void);
-               void M_Menu_Keys_f (void);
-               void M_Menu_Reset_f (void);
-               void M_Menu_Video_f (void);
-       void M_Menu_Help_f (void);
-       void M_Menu_Credits_f (void);
-       void M_Menu_Quit_f (void);
-void M_Menu_LanConfig_f (void);
-void M_Menu_GameOptions_f (void);
-void M_Menu_ServerList_f (void);
-void M_Menu_ModList_f (void);
+void M_Menu_Main_f(cmd_state_t *cmd);
+       void M_Menu_SinglePlayer_f(cmd_state_t *cmd);
+               void M_Menu_Transfusion_Episode_f(cmd_state_t *cmd);
+                       void M_Menu_Transfusion_Skill_f(cmd_state_t *cmd);
+               void M_Menu_Load_f(cmd_state_t *cmd);
+               void M_Menu_Save_f(cmd_state_t *cmd);
+       void M_Menu_MultiPlayer_f(cmd_state_t *cmd);
+               void M_Menu_Setup_f(cmd_state_t *cmd);
+       void M_Menu_Options_f(cmd_state_t *cmd);
+       void M_Menu_Options_Effects_f(cmd_state_t *cmd);
+       void M_Menu_Options_Graphics_f(cmd_state_t *cmd);
+       void M_Menu_Options_ColorControl_f(cmd_state_t *cmd);
+               void M_Menu_Keys_f(cmd_state_t *cmd);
+               void M_Menu_Reset_f(cmd_state_t *cmd);
+               void M_Menu_Video_f(cmd_state_t *cmd);
+       void M_Menu_Help_f(cmd_state_t *cmd);
+       void M_Menu_Credits_f(cmd_state_t *cmd);
+       void M_Menu_Quit_f(cmd_state_t *cmd);
+void M_Menu_LanConfig_f(cmd_state_t *cmd);
+void M_Menu_GameOptions_f(cmd_state_t *cmd);
+void M_Menu_ServerList_f(cmd_state_t *cmd);
+void M_Menu_ModList_f(cmd_state_t *cmd);
 
 static void M_Main_Draw (void);
        static void M_SinglePlayer_Draw (void);
@@ -85,30 +83,30 @@ static void M_ServerList_Draw (void);
 static void M_ModList_Draw (void);
 
 
-static void M_Main_Key (int key, int ascii);
-       static void M_SinglePlayer_Key (int key, int ascii);
-               static void M_Transfusion_Episode_Key (int key, int ascii);
-                       static void M_Transfusion_Skill_Key (int key, int ascii);
-               static void M_Load_Key (int key, int ascii);
-               static void M_Save_Key (int key, int ascii);
-       static void M_MultiPlayer_Key (int key, int ascii);
-               static void M_Setup_Key (int key, int ascii);
-       static void M_Options_Key (int key, int ascii);
-       static void M_Options_Effects_Key (int key, int ascii);
-       static void M_Options_Graphics_Key (int key, int ascii);
-       static void M_Options_ColorControl_Key (int key, int ascii);
-               static void M_Keys_Key (int key, int ascii);
-               static void M_Reset_Key (int key, int ascii);
-               static void M_Video_Key (int key, int ascii);
-       static void M_Help_Key (int key, int ascii);
-       static void M_Credits_Key (int key, int ascii);
-       static void M_Quit_Key (int key, int ascii);
-static void M_LanConfig_Key (int key, int ascii);
-static void M_GameOptions_Key (int key, int ascii);
-static void M_ServerList_Key (int key, int ascii);
-static void M_ModList_Key (int key, int ascii);
-
-static qboolean        m_entersound;           ///< play after drawing a frame, so caching won't disrupt the sound
+static void M_Main_Key(cmd_state_t *cmd, int key, int ascii);
+       static void M_SinglePlayer_Key(cmd_state_t *cmd, int key, int ascii);
+               static void M_Transfusion_Episode_Key(cmd_state_t *cmd, int key, int ascii);
+                       static void M_Transfusion_Skill_Key(cmd_state_t *cmd, int key, int ascii);
+               static void M_Load_Key(cmd_state_t *cmd, int key, int ascii);
+               static void M_Save_Key(cmd_state_t *cmd, int key, int ascii);
+       static void M_MultiPlayer_Key(cmd_state_t *cmd, int key, int ascii);
+               static void M_Setup_Key(cmd_state_t *cmd, int key, int ascii);
+       static void M_Options_Key(cmd_state_t *cmd, int key, int ascii);
+       static void M_Options_Effects_Key(cmd_state_t *cmd, int key, int ascii);
+       static void M_Options_Graphics_Key(cmd_state_t *cmd, int key, int ascii);
+       static void M_Options_ColorControl_Key(cmd_state_t *cmd, int key, int ascii);
+               static void M_Keys_Key(cmd_state_t *cmd, int key, int ascii);
+               static void M_Reset_Key(cmd_state_t *cmd, int key, int ascii);
+               static void M_Video_Key(cmd_state_t *cmd, int key, int ascii);
+       static void M_Help_Key(cmd_state_t *cmd, int key, int ascii);
+       static void M_Credits_Key(cmd_state_t *cmd, int key, int ascii);
+       static void M_Quit_Key(cmd_state_t *cmd, int key, int ascii);
+static void M_LanConfig_Key(cmd_state_t *cmd, int key, int ascii);
+static void M_GameOptions_Key(cmd_state_t *cmd, int key, int ascii);
+static void M_ServerList_Key(cmd_state_t *cmd, int key, int ascii);
+static void M_ModList_Key(cmd_state_t *cmd, int key, int ascii);
+
+static qbool   m_entersound;           ///< play after drawing a frame, so caching won't disrupt the sound
 
 void M_Update_Return_Reason(const char *s)
 {
@@ -284,7 +282,7 @@ static void M_ToggleMenu(int mode)
        {
                if(mode == 0)
                        return; // the menu is off, and we want it off
-               M_Menu_Main_f ();
+               M_Menu_Main_f (cmd_local);
        }
        else
        {
@@ -307,11 +305,11 @@ static void M_Demo_Draw (void)
                M_Print(16, 16 + 8*i, NehahraDemos[i].desc);
 
        // line cursor
-       M_DrawCharacter (8, 16 + demo_cursor*8, 12+((int)(realtime*4)&1));
+       M_DrawCharacter (8, 16 + demo_cursor*8, 12+((int)(host.realtime*4)&1));
 }
 
 
-static void M_Menu_Demos_f (void)
+static void M_Menu_Demos_f(cmd_state_t *cmd)
 {
        key_dest = key_menu;
        m_state = m_demo;
@@ -319,20 +317,20 @@ static void M_Menu_Demos_f (void)
 }
 
 
-static void M_Demo_Key (int k, int ascii)
+static void M_Demo_Key (cmd_state_t *cmd, int k, int ascii)
 {
        char vabuf[1024];
        switch (k)
        {
        case K_ESCAPE:
-               M_Menu_Main_f ();
+               M_Menu_Main_f (cmd);
                break;
 
        case K_ENTER:
                S_LocalSound ("sound/misc/menu2.wav");
                m_state = m_none;
                key_dest = key_game;
-               Cbuf_AddText (va(vabuf, sizeof(vabuf), "playdemo %s\n", NehahraDemos[demo_cursor].name));
+               Cbuf_AddText (cmd, va(vabuf, sizeof(vabuf), "playdemo %s\n", NehahraDemos[demo_cursor].name));
                return;
 
        case K_UPARROW:
@@ -357,12 +355,12 @@ static void M_Demo_Key (int k, int ascii)
 /* MAIN MENU */
 
 static int     m_main_cursor;
-static qboolean m_missingdata = false;
+static qbool m_missingdata = false;
 
 static int MAIN_ITEMS = 4; // Nehahra: Menu Disable
 
 
-void M_Menu_Main_f (void)
+void M_Menu_Main_f(cmd_state_t *cmd)
 {
        const char *s;
        s = "gfx/mainmenu";
@@ -450,7 +448,7 @@ static void M_Main_Draw (void)
                s = "to your launch commandline";M_Print ((640-strlen(s)*8)*0.5, y, s);y+=8;
                M_Print (640/2 - 48, 480/2, "Open Console"); //The console usually better shows errors (failures)
                M_Print (640/2 - 48, 480/2 + 8, "Quit");
-               M_DrawCharacter(640/2 - 56, 480/2 + (8 * m_main_cursor), 12+((int)(realtime*4)&1));
+               M_DrawCharacter(640/2 - 56, 480/2 + (8 * m_main_cursor), 12+((int)(host.realtime*4)&1));
                return;
        }
 
@@ -493,13 +491,13 @@ static void M_Main_Draw (void)
        else
                M_DrawPic (72, 32, "gfx/mainmenu");
 
-       f = (int)(realtime * 10)%6;
+       f = (int)(host.realtime * 10)%6;
 
        M_DrawPic (54, 32 + m_main_cursor * 20, va(vabuf, sizeof(vabuf), "gfx/menudot%i", f+1));
 }
 
 
-static void M_Main_Key (int key, int ascii)
+static void M_Main_Key(cmd_state_t *cmd, int key, int ascii)
 {
        switch (key)
        {
@@ -536,10 +534,10 @@ static void M_Main_Key (int key, int ascii)
                                        m_state = m_none;
                                        key_dest = key_game;
                                }
-                               Con_ToggleConsole_f ();
+                               Con_ToggleConsole_f(cmd);
                                break;
                        case 1:
-                               M_Menu_Quit_f ();
+                               M_Menu_Quit_f(cmd);
                                break;
                        }
                }
@@ -551,30 +549,30 @@ static void M_Main_Key (int key, int ascii)
                                switch (m_main_cursor)
                                {
                                case 0:
-                                       M_Menu_SinglePlayer_f ();
+                                       M_Menu_SinglePlayer_f(cmd);
                                        break;
 
                                case 1:
-                                       M_Menu_Demos_f ();
+                                       M_Menu_Demos_f(cmd);
                                        break;
 
                                case 2:
-                                       M_Menu_MultiPlayer_f ();
+                                       M_Menu_MultiPlayer_f(cmd);
                                        break;
 
                                case 3:
-                                       M_Menu_Options_f ();
+                                       M_Menu_Options_f(cmd);
                                        break;
 
                                case 4:
                                        key_dest = key_game;
                                        if (sv.active)
-                                               Cbuf_AddText ("disconnect\n");
-                                       Cbuf_AddText ("playdemo endcred\n");
+                                               Cbuf_AddText (cmd, "disconnect\n");
+                                       Cbuf_AddText (cmd, "playdemo endcred\n");
                                        break;
 
                                case 5:
-                                       M_Menu_Quit_f ();
+                                       M_Menu_Quit_f(cmd);
                                        break;
                                }
                                break;
@@ -582,26 +580,26 @@ static void M_Main_Key (int key, int ascii)
                                switch (m_main_cursor)
                                {
                                case 0:
-                                       M_Menu_SinglePlayer_f ();
+                                       M_Menu_SinglePlayer_f(cmd);
                                        break;
 
                                case 1:
-                                       M_Menu_MultiPlayer_f ();
+                                       M_Menu_MultiPlayer_f(cmd);
                                        break;
 
                                case 2:
-                                       M_Menu_Options_f ();
+                                       M_Menu_Options_f(cmd);
                                        break;
 
                                case 3:
                                        key_dest = key_game;
                                        if (sv.active)
-                                               Cbuf_AddText ("disconnect\n");
-                                       Cbuf_AddText ("playdemo endcred\n");
+                                               Cbuf_AddText (cmd, "disconnect\n");
+                                       Cbuf_AddText (cmd, "playdemo endcred\n");
                                        break;
 
                                case 4:
-                                       M_Menu_Quit_f ();
+                                       M_Menu_Quit_f(cmd);
                                        break;
                                }
                                break;
@@ -609,22 +607,22 @@ static void M_Main_Key (int key, int ascii)
                                switch (m_main_cursor)
                                {
                                case 0:
-                                       M_Menu_Demos_f ();
+                                       M_Menu_Demos_f(cmd);
                                        break;
 
                                case 1:
                                        key_dest = key_game;
                                        if (sv.active)
-                                               Cbuf_AddText ("disconnect\n");
-                                       Cbuf_AddText ("playdemo endcred\n");
+                                               Cbuf_AddText (cmd, "disconnect\n");
+                                       Cbuf_AddText (cmd, "playdemo endcred\n");
                                        break;
 
                                case 2:
-                                       M_Menu_Options_f ();
+                                       M_Menu_Options_f(cmd);
                                        break;
 
                                case 3:
-                                       M_Menu_Quit_f ();
+                                       M_Menu_Quit_f(cmd);
                                        break;
                                }
                                break;
@@ -636,31 +634,31 @@ static void M_Main_Key (int key, int ascii)
                                switch (m_main_cursor)
                                {
                                case 0:
-                                       M_Menu_Transfusion_Episode_f ();
+                                       M_Menu_Transfusion_Episode_f(cmd);
                                        break;
 
                                case 1:
-                                       M_Menu_MultiPlayer_f ();
+                                       M_Menu_MultiPlayer_f(cmd);
                                        break;
 
                                case 2:
-                                       M_Menu_Options_f ();
+                                       M_Menu_Options_f(cmd);
                                        break;
 
                                case 3:
-                                       M_Menu_Load_f ();
+                                       M_Menu_Load_f(cmd);
                                        break;
 
                                case 4:
-                                       M_Menu_Help_f ();
+                                       M_Menu_Help_f(cmd);
                                        break;
 
                                case 5:
-                                       M_Menu_Credits_f ();
+                                       M_Menu_Credits_f(cmd);
                                        break;
 
                                case 6:
-                                       M_Menu_Quit_f ();
+                                       M_Menu_Quit_f(cmd);
                                        break;
                                }
                        }
@@ -669,35 +667,35 @@ static void M_Main_Key (int key, int ascii)
                                switch (m_main_cursor)
                                {
                                case 0:
-                                       M_Menu_Transfusion_Episode_f ();
+                                       M_Menu_Transfusion_Episode_f(cmd);
                                        break;
 
                                case 1:
-                                       M_Menu_MultiPlayer_f ();
+                                       M_Menu_MultiPlayer_f(cmd);
                                        break;
 
                                case 2:
-                                       M_Menu_Options_f ();
+                                       M_Menu_Options_f(cmd);
                                        break;
 
                                case 3:
-                                       M_Menu_Save_f ();
+                                       M_Menu_Save_f(cmd);
                                        break;
 
                                case 4:
-                                       M_Menu_Load_f ();
+                                       M_Menu_Load_f(cmd);
                                        break;
 
                                case 5:
-                                       M_Menu_Help_f ();
+                                       M_Menu_Help_f(cmd);
                                        break;
 
                                case 6:
-                                       M_Menu_Credits_f ();
+                                       M_Menu_Credits_f(cmd);
                                        break;
 
                                case 7:
-                                       M_Menu_Quit_f ();
+                                       M_Menu_Quit_f(cmd);
                                        break;
                                }
                        }
@@ -707,23 +705,23 @@ static void M_Main_Key (int key, int ascii)
                        switch (m_main_cursor)
                        {
                        case 0:
-                               M_Menu_SinglePlayer_f ();
+                               M_Menu_SinglePlayer_f(cmd);
                                break;
 
                        case 1:
-                               M_Menu_MultiPlayer_f ();
+                               M_Menu_MultiPlayer_f(cmd);
                                break;
 
                        case 2:
-                               M_Menu_Options_f ();
+                               M_Menu_Options_f(cmd);
                                break;
 
                        case 3:
-                               M_Menu_Help_f ();
+                               M_Menu_Help_f(cmd);
                                break;
 
                        case 4:
-                               M_Menu_Quit_f ();
+                               M_Menu_Quit_f(cmd);
                                break;
                        }
                }
@@ -737,7 +735,7 @@ static int  m_singleplayer_cursor;
 #define        SINGLEPLAYER_ITEMS      3
 
 
-void M_Menu_SinglePlayer_f (void)
+void M_Menu_SinglePlayer_f(cmd_state_t *cmd)
 {
        key_dest = key_menu;
        m_state = m_singleplayer;
@@ -774,14 +772,14 @@ static void M_SinglePlayer_Draw (void)
                M_DrawPic ( (320-Draw_GetPicWidth(p))/2, 4, "gfx/ttl_sgl");
                M_DrawPic (72, 32, "gfx/sp_menu");
 
-               f = (int)(realtime * 10)%6;
+               f = (int)(host.realtime * 10)%6;
 
                M_DrawPic (54, 32 + m_singleplayer_cursor * 20, va(vabuf, sizeof(vabuf), "gfx/menudot%i", f+1));
        }
 }
 
 
-static void M_SinglePlayer_Key (int key, int ascii)
+static void M_SinglePlayer_Key(cmd_state_t *cmd, int key, int ascii)
 {
        if (gamemode == GAME_GOODVSBAD2 || gamemode == GAME_BATTLEMECH)
        {
@@ -793,7 +791,7 @@ static void M_SinglePlayer_Key (int key, int ascii)
        switch (key)
        {
        case K_ESCAPE:
-               M_Menu_Main_f ();
+               M_Menu_Main_f(cmd);
                break;
 
        case K_DOWNARROW:
@@ -816,25 +814,25 @@ static void M_SinglePlayer_Key (int key, int ascii)
                case 0:
                        key_dest = key_game;
                        if (sv.active)
-                               Cbuf_AddText ("disconnect\n");
-                       Cbuf_AddText ("maxplayers 1\n");
-                       Cbuf_AddText ("deathmatch 0\n");
-                       Cbuf_AddText ("coop 0\n");
+                               Cbuf_AddText(cmd, "disconnect\n");
+                       Cbuf_AddText(cmd, "maxplayers 1\n");
+                       Cbuf_AddText(cmd, "deathmatch 0\n");
+                       Cbuf_AddText(cmd, "coop 0\n");
                        if (gamemode == GAME_TRANSFUSION)
                        {
                                key_dest = key_menu;
-                               M_Menu_Transfusion_Episode_f ();
+                               M_Menu_Transfusion_Episode_f(cmd);
                                break;
                        }
-                       Cbuf_AddText ("startmap_sp\n");
+                       Cbuf_AddText(cmd, "startmap_sp\n");
                        break;
 
                case 1:
-                       M_Menu_Load_f ();
+                       M_Menu_Load_f(cmd);
                        break;
 
                case 2:
-                       M_Menu_Save_f ();
+                       M_Menu_Save_f(cmd);
                        break;
                }
        }
@@ -887,7 +885,7 @@ static void M_ScanSaves (void)
        }
 }
 
-void M_Menu_Load_f (void)
+void M_Menu_Load_f(cmd_state_t *cmd)
 {
        m_entersound = true;
        m_state = m_load;
@@ -896,12 +894,12 @@ void M_Menu_Load_f (void)
 }
 
 
-void M_Menu_Save_f (void)
+void M_Menu_Save_f(cmd_state_t *cmd)
 {
        if (!sv.active)
                return;
 #if 1
-       // LordHavoc: allow saving multiplayer games
+       // LadyHavoc: allow saving multiplayer games
        if (cl.islocalgame && cl.intermission)
                return;
 #else
@@ -931,7 +929,7 @@ static void M_Load_Draw (void)
                M_Print(16, 32 + 8*i, m_filenames[i]);
 
 // line cursor
-       M_DrawCharacter (8, 32 + load_cursor*8, 12+((int)(realtime*4)&1));
+       M_DrawCharacter (8, 32 + load_cursor*8, 12+((int)(host.realtime*4)&1));
 }
 
 
@@ -949,20 +947,20 @@ static void M_Save_Draw (void)
                M_Print(16, 32 + 8*i, m_filenames[i]);
 
 // line cursor
-       M_DrawCharacter (8, 32 + load_cursor*8, 12+((int)(realtime*4)&1));
+       M_DrawCharacter (8, 32 + load_cursor*8, 12+((int)(host.realtime*4)&1));
 }
 
 
-static void M_Load_Key (int k, int ascii)
+static void M_Load_Key(cmd_state_t *cmd, int k, int ascii)
 {
        char vabuf[1024];
        switch (k)
        {
        case K_ESCAPE:
                if (gamemode == GAME_TRANSFUSION)
-                       M_Menu_Main_f ();
+                       M_Menu_Main_f(cmd);
                else
-                       M_Menu_SinglePlayer_f ();
+                       M_Menu_SinglePlayer_f(cmd);
                break;
 
        case K_ENTER:
@@ -973,7 +971,7 @@ static void M_Load_Key (int k, int ascii)
                key_dest = key_game;
 
                // issue the load command
-               Cbuf_AddText (va(vabuf, sizeof(vabuf), "load s%i\n", load_cursor) );
+               Cbuf_AddText (cmd, va(vabuf, sizeof(vabuf), "load s%i\n", load_cursor) );
                return;
 
        case K_UPARROW:
@@ -995,22 +993,22 @@ static void M_Load_Key (int k, int ascii)
 }
 
 
-static void M_Save_Key (int k, int ascii)
+static void M_Save_Key(cmd_state_t *cmd, int k, int ascii)
 {
        char vabuf[1024];
        switch (k)
        {
        case K_ESCAPE:
                if (gamemode == GAME_TRANSFUSION)
-                       M_Menu_Main_f ();
+                       M_Menu_Main_f(cmd);
                else
-                       M_Menu_SinglePlayer_f ();
+                       M_Menu_SinglePlayer_f(cmd);
                break;
 
        case K_ENTER:
                m_state = m_none;
                key_dest = key_game;
-               Cbuf_AddText (va(vabuf, sizeof(vabuf), "save s%i\n", load_cursor));
+               Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "save s%i\n", load_cursor));
                return;
 
        case K_UPARROW:
@@ -1037,7 +1035,7 @@ static void M_Save_Key (int k, int ascii)
 static int     m_episode_cursor;
 #define        EPISODE_ITEMS   6
 
-void M_Menu_Transfusion_Episode_f (void)
+void M_Menu_Transfusion_Episode_f(cmd_state_t *cmd)
 {
        m_entersound = true;
        m_state = m_transfusion_episode;
@@ -1060,12 +1058,12 @@ static void M_Transfusion_Episode_Draw (void)
        M_DrawPic (0, 120 + (m_episode_cursor + 1) * 40, va(vabuf, sizeof(vabuf), "gfx/menu/episode%iselected", m_episode_cursor + 1));
 }
 
-static void M_Transfusion_Episode_Key (int key, int ascii)
+static void M_Transfusion_Episode_Key(cmd_state_t *cmd, int key, int ascii)
 {
        switch (key)
        {
        case K_ESCAPE:
-               M_Menu_Main_f ();
+               M_Menu_Main_f(cmd);
                break;
 
        case K_DOWNARROW:
@@ -1083,9 +1081,9 @@ static void M_Transfusion_Episode_Key (int key, int ascii)
                break;
 
        case K_ENTER:
-               Cbuf_AddText ("deathmatch 0\n");
+               Cbuf_AddText(cmd, "deathmatch 0\n");
                m_entersound = true;
-               M_Menu_Transfusion_Skill_f ();
+               M_Menu_Transfusion_Skill_f(cmd);
        }
 }
 
@@ -1095,7 +1093,7 @@ static void M_Transfusion_Episode_Key (int key, int ascii)
 static int     m_skill_cursor = 2;
 #define        SKILL_ITEMS     5
 
-void M_Menu_Transfusion_Skill_f (void)
+void M_Menu_Transfusion_Skill_f(cmd_state_t *cmd)
 {
        m_entersound = true;
        m_state = m_transfusion_skill;
@@ -1119,12 +1117,12 @@ static void M_Transfusion_Skill_Draw (void)
        M_DrawPic (0, 140 + (m_skill_cursor + 1) *40, va(vabuf, sizeof(vabuf), "gfx/menu/difficulty%iselected", m_skill_cursor + 1));
 }
 
-static void M_Transfusion_Skill_Key (int key, int ascii)
+static void M_Transfusion_Skill_Key(cmd_state_t *cmd, int key, int ascii)
 {
        switch (key)
        {
        case K_ESCAPE:
-               M_Menu_Transfusion_Episode_f ();
+               M_Menu_Transfusion_Episode_f(cmd);
                break;
 
        case K_DOWNARROW:
@@ -1146,46 +1144,46 @@ static void M_Transfusion_Skill_Key (int key, int ascii)
                switch (m_skill_cursor)
                {
                case 0:
-                       Cbuf_AddText ("skill 1\n");
+                       Cbuf_AddText(cmd, "skill 1\n");
                        break;
                case 1:
-                       Cbuf_AddText ("skill 2\n");
+                       Cbuf_AddText(cmd, "skill 2\n");
                        break;
                case 2:
-                       Cbuf_AddText ("skill 3\n");
+                       Cbuf_AddText(cmd, "skill 3\n");
                        break;
                case 3:
-                       Cbuf_AddText ("skill 4\n");
+                       Cbuf_AddText(cmd, "skill 4\n");
                        break;
                case 4:
-                       Cbuf_AddText ("skill 5\n");
+                       Cbuf_AddText(cmd, "skill 5\n");
                        break;
                }
                key_dest = key_game;
                if (sv.active)
-                       Cbuf_AddText ("disconnect\n");
-               Cbuf_AddText ("maxplayers 1\n");
-               Cbuf_AddText ("deathmatch 0\n");
-               Cbuf_AddText ("coop 0\n");
+                       Cbuf_AddText(cmd, "disconnect\n");
+               Cbuf_AddText(cmd, "maxplayers 1\n");
+               Cbuf_AddText(cmd, "deathmatch 0\n");
+               Cbuf_AddText(cmd, "coop 0\n");
                switch (m_episode_cursor)
                {
                case 0:
-                       Cbuf_AddText ("map e1m1\n");
+                       Cbuf_AddText(cmd, "map e1m1\n");
                        break;
                case 1:
-                       Cbuf_AddText ("map e2m1\n");
+                       Cbuf_AddText(cmd, "map e2m1\n");
                        break;
                case 2:
-                       Cbuf_AddText ("map e3m1\n");
+                       Cbuf_AddText(cmd, "map e3m1\n");
                        break;
                case 3:
-                       Cbuf_AddText ("map e4m1\n");
+                       Cbuf_AddText(cmd, "map e4m1\n");
                        break;
                case 4:
-                       Cbuf_AddText ("map e6m1\n");
+                       Cbuf_AddText(cmd, "map e6m1\n");
                        break;
                case 5:
-                       Cbuf_AddText ("map cp01\n");
+                       Cbuf_AddText(cmd, "map cp01\n");
                        break;
                }
        }
@@ -1197,7 +1195,7 @@ static int        m_multiplayer_cursor;
 #define        MULTIPLAYER_ITEMS       3
 
 
-void M_Menu_MultiPlayer_f (void)
+void M_Menu_MultiPlayer_f(cmd_state_t *cmd)
 {
        key_dest = key_menu;
        m_state = m_multiplayer;
@@ -1228,18 +1226,18 @@ static void M_MultiPlayer_Draw (void)
        M_DrawPic ( (320-Draw_GetPicWidth(p))/2, 4, "gfx/p_multi");
        M_DrawPic (72, 32, "gfx/mp_menu");
 
-       f = (int)(realtime * 10)%6;
+       f = (int)(host.realtime * 10)%6;
 
        M_DrawPic (54, 32 + m_multiplayer_cursor * 20, va(vabuf, sizeof(vabuf), "gfx/menudot%i", f+1));
 }
 
 
-static void M_MultiPlayer_Key (int key, int ascii)
+static void M_MultiPlayer_Key(cmd_state_t *cmd, int key, int ascii)
 {
        switch (key)
        {
        case K_ESCAPE:
-               M_Menu_Main_f ();
+               M_Menu_Main_f(cmd);
                break;
 
        case K_DOWNARROW:
@@ -1260,11 +1258,11 @@ static void M_MultiPlayer_Key (int key, int ascii)
                {
                case 0:
                case 1:
-                       M_Menu_LanConfig_f ();
+                       M_Menu_LanConfig_f(cmd);
                        break;
 
                case 2:
-                       M_Menu_Setup_f ();
+                       M_Menu_Setup_f(cmd);
                        break;
                }
        }
@@ -1286,14 +1284,17 @@ static int              setup_oldrate;
 
 #define        NUM_SETUP_CMDS  5
 
-void M_Menu_Setup_f (void)
+extern cvar_t cl_topcolor;
+extern cvar_t cl_bottomcolor;
+
+void M_Menu_Setup_f(cmd_state_t *cmd)
 {
        key_dest = key_menu;
        m_state = m_setup;
        m_entersound = true;
        strlcpy(setup_myname, cl_name.string, sizeof(setup_myname));
-       setup_top = setup_oldtop = cl_color.integer >> 4;
-       setup_bottom = setup_oldbottom = cl_color.integer & 15;
+       setup_top = setup_oldtop = cl_topcolor.integer;
+       setup_bottom = setup_oldbottom = cl_bottomcolor.integer;
        setup_rate = cl_rate.integer;
 }
 
@@ -1362,7 +1363,7 @@ static void M_Setup_Draw (void)
        M_DrawTextBox (64, 140-8, 14, 1);
        M_Print(72, 140, "Accept Changes");
 
-       // LordHavoc: rewrote this code greatly
+       // LadyHavoc: rewrote this code greatly
        if (menuplyr_load)
        {
                unsigned char *f;
@@ -1422,13 +1423,13 @@ static void M_Setup_Draw (void)
        }
 
        if (setup_cursor == 0)
-               M_DrawCharacter (168 + 8*strlen(setup_myname), setup_cursor_table [setup_cursor], 10+((int)(realtime*4)&1));
+               M_DrawCharacter (168 + 8*strlen(setup_myname), setup_cursor_table [setup_cursor], 10+((int)(host.realtime*4)&1));
        else
-               M_DrawCharacter (56, setup_cursor_table [setup_cursor], 12+((int)(realtime*4)&1));
+               M_DrawCharacter (56, setup_cursor_table [setup_cursor], 12+((int)(host.realtime*4)&1));
 }
 
 
-static void M_Setup_Key (int k, int ascii)
+static void M_Setup_Key(cmd_state_t *cmd, int k, int ascii)
 {
        int                     l;
        char vabuf[1024];
@@ -1436,7 +1437,7 @@ static void M_Setup_Key (int k, int ascii)
        switch (k)
        {
        case K_ESCAPE:
-               M_Menu_MultiPlayer_f ();
+               M_Menu_MultiPlayer_f(cmd);
                break;
 
        case K_UPARROW:
@@ -1496,14 +1497,14 @@ forward:
 
                // setup_cursor == 4 (Accept changes)
                if (strcmp(cl_name.string, setup_myname) != 0)
-                       Cbuf_AddText(va(vabuf, sizeof(vabuf), "name \"%s\"\n", setup_myname) );
+                       Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "name \"%s\"\n", setup_myname) );
                if (setup_top != setup_oldtop || setup_bottom != setup_oldbottom)
-                       Cbuf_AddText(va(vabuf, sizeof(vabuf), "color %i %i\n", setup_top, setup_bottom) );
+                       Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "color %i %i\n", setup_top, setup_bottom) );
                if (setup_rate != setup_oldrate)
-                       Cbuf_AddText(va(vabuf, sizeof(vabuf), "rate %i\n", setup_rate));
+                       Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "rate %i\n", setup_rate));
 
                m_entersound = true;
-               M_Menu_MultiPlayer_f ();
+               M_Menu_MultiPlayer_f(cmd);
                break;
 
        case K_BACKSPACE:
@@ -1576,14 +1577,14 @@ static void M_DrawCheckbox (int x, int y, int on)
 
 static int options_cursor;
 
-void M_Menu_Options_f (void)
+void M_Menu_Options_f(cmd_state_t *cmd)
 {
        key_dest = key_menu;
        m_state = m_options;
        m_entersound = true;
 }
 
-extern cvar_t slowmo;
+extern cvar_t host_timescale;
 extern dllhandle_t jpeg_dll;
 extern cvar_t gl_texture_anisotropy;
 extern cvar_t r_textshadow;
@@ -1617,16 +1618,14 @@ static void M_Menu_Options_AdjustSliders (int dir)
                        Cvar_SetValueQuick (&cl_backspeed, 400);
                }
        }
-       else if (options_cursor == optnum++) Cvar_SetValueQuick(&showfps, !showfps.integer);
-       else if (options_cursor == optnum++) {f = !(showdate.integer && showtime.integer);Cvar_SetValueQuick(&showdate, f);Cvar_SetValueQuick(&showtime, f);}
+       else if (options_cursor == optnum++) Cvar_SetValueQuick(&cl_showfps, !cl_showfps.integer);
+       else if (options_cursor == optnum++) {f = !(cl_showdate.integer && cl_showtime.integer);Cvar_SetValueQuick(&cl_showdate, f);Cvar_SetValueQuick(&cl_showtime, f);}
        else if (options_cursor == optnum++) ;
        else if (options_cursor == optnum++) Cvar_SetValueQuick(&r_hdr_scenebrightness, bound(1, r_hdr_scenebrightness.value + dir * 0.0625, 4));
        else if (options_cursor == optnum++) Cvar_SetValueQuick(&v_contrast, bound(1, v_contrast.value + dir * 0.0625, 4));
        else if (options_cursor == optnum++) Cvar_SetValueQuick(&v_gamma, bound(0.5, v_gamma.value + dir * 0.0625, 3));
        else if (options_cursor == optnum++) Cvar_SetValueQuick(&volume, bound(0, volume.value + dir * 0.0625, 1));
-#ifdef CONFIG_CD
        else if (options_cursor == optnum++) Cvar_SetValueQuick(&bgmvolume, bound(0, bgmvolume.value + dir * 0.0625, 1));
-#endif
 }
 
 static int m_optnum;
@@ -1638,7 +1637,7 @@ static void M_Options_PrintCommand(const char *s, int enabled)
        if (m_opty >= 32)
        {
                if (m_optnum == m_optcursor)
-                       DrawQ_Fill(menu_x + 48, menu_y + m_opty, 320, 8, m_optnum == m_optcursor ? (0.5 + 0.2 * sin(realtime * M_PI)) : 0, 0, 0, 0.5, 0);
+                       DrawQ_Fill(menu_x + 48, menu_y + m_opty, 320, 8, m_optnum == m_optcursor ? (0.5 + 0.2 * sin(host.realtime * M_PI)) : 0, 0, 0, 0.5, 0);
                M_ItemPrint(0 + 48, m_opty, s, enabled);
        }
        m_opty += 8;
@@ -1650,7 +1649,7 @@ static void M_Options_PrintCheckbox(const char *s, int enabled, int yes)
        if (m_opty >= 32)
        {
                if (m_optnum == m_optcursor)
-                       DrawQ_Fill(menu_x + 48, menu_y + m_opty, 320, 8, m_optnum == m_optcursor ? (0.5 + 0.2 * sin(realtime * M_PI)) : 0, 0, 0, 0.5, 0);
+                       DrawQ_Fill(menu_x + 48, menu_y + m_opty, 320, 8, m_optnum == m_optcursor ? (0.5 + 0.2 * sin(host.realtime * M_PI)) : 0, 0, 0, 0.5, 0);
                M_ItemPrint(0 + 48, m_opty, s, enabled);
                M_DrawCheckbox(0 + 48 + (int)strlen(s) * 8 + 8, m_opty, yes);
        }
@@ -1663,7 +1662,7 @@ static void M_Options_PrintSlider(const char *s, int enabled, float value, float
        if (m_opty >= 32)
        {
                if (m_optnum == m_optcursor)
-                       DrawQ_Fill(menu_x + 48, menu_y + m_opty, 320, 8, m_optnum == m_optcursor ? (0.5 + 0.2 * sin(realtime * M_PI)) : 0, 0, 0, 0.5, 0);
+                       DrawQ_Fill(menu_x + 48, menu_y + m_opty, 320, 8, m_optnum == m_optcursor ? (0.5 + 0.2 * sin(host.realtime * M_PI)) : 0, 0, 0, 0.5, 0);
                M_ItemPrint(0 + 48, m_opty, s, enabled);
                M_DrawSlider(0 + 48 + (int)strlen(s) * 8 + 8, m_opty, value, minvalue, maxvalue);
        }
@@ -1696,16 +1695,14 @@ static void M_Options_Draw (void)
        M_Options_PrintCheckbox("          Invert Mouse", true, m_pitch.value < 0);
        M_Options_PrintSlider(  "         Field of View", true, scr_fov.integer, 1, 170);
        M_Options_PrintCheckbox("            Always Run", true, cl_forwardspeed.value > 200);
-       M_Options_PrintCheckbox("        Show Framerate", true, showfps.integer);
-       M_Options_PrintCheckbox("    Show Date and Time", true, showdate.integer && showtime.integer);
+       M_Options_PrintCheckbox("        Show Framerate", true, cl_showfps.integer);
+       M_Options_PrintCheckbox("    Show Date and Time", true, cl_showdate.integer && cl_showtime.integer);
        M_Options_PrintCommand( "     Custom Brightness", true);
        M_Options_PrintSlider(  "       Game Brightness", true, r_hdr_scenebrightness.value, 1, 4);
        M_Options_PrintSlider(  "            Brightness", true, v_contrast.value, 1, 2);
        M_Options_PrintSlider(  "                 Gamma", true, v_gamma.value, 0.5, 3);
        M_Options_PrintSlider(  "          Sound Volume", snd_initialized.integer, volume.value, 0, 1);
-#ifdef CONFIG_CD
        M_Options_PrintSlider(  "          Music Volume", cdaudioinitialized.integer, bgmvolume.value, 0, 1);
-#endif
        M_Options_PrintCommand( "     Customize Effects", true);
        M_Options_PrintCommand( "       Effects:  Quake", true);
        M_Options_PrintCommand( "       Effects: Normal", true);
@@ -1719,12 +1716,12 @@ static void M_Options_Draw (void)
 }
 
 
-static void M_Options_Key (int k, int ascii)
+static void M_Options_Key(cmd_state_t *cmd, int k, int ascii)
 {
        switch (k)
        {
        case K_ESCAPE:
-               M_Menu_Main_f ();
+               M_Menu_Main_f(cmd);
                break;
 
        case K_ENTER:
@@ -1732,51 +1729,51 @@ static void M_Options_Key (int k, int ascii)
                switch (options_cursor)
                {
                case 0:
-                       M_Menu_Keys_f ();
+                       M_Menu_Keys_f(cmd);
                        break;
                case 1:
                        m_state = m_none;
                        key_dest = key_game;
-                       Con_ToggleConsole_f ();
+                       Con_ToggleConsole_f(cmd);
                        break;
                case 2:
-                       M_Menu_Reset_f ();
+                       M_Menu_Reset_f(cmd);
                        break;
                case 3:
-                       M_Menu_Video_f ();
+                       M_Menu_Video_f(cmd);
                        break;
                case 11:
-                       M_Menu_Options_ColorControl_f ();
+                       M_Menu_Options_ColorControl_f(cmd);
                        break;
                case 17: // Customize Effects
-                       M_Menu_Options_Effects_f ();
+                       M_Menu_Options_Effects_f(cmd);
                        break;
                case 18: // Effects: Quake
-                       Cbuf_AddText("cl_particles 1;cl_particles_quake 1;cl_particles_quality 1;cl_particles_explosions_shell 0;r_explosionclip 1;cl_stainmaps 0;cl_stainmaps_clearonload 1;cl_decals 0;cl_particles_bulletimpacts 1;cl_particles_smoke 1;cl_particles_sparks 1;cl_particles_bubbles 1;cl_particles_blood 1;cl_particles_blood_alpha 1;cl_particles_blood_bloodhack 0;cl_beams_polygons 0;cl_beams_instantaimhack 0;cl_beams_quakepositionhack 1;cl_beams_lightatend 0;r_lerpmodels 1;r_lerpsprites 1;r_lerplightstyles 0;gl_polyblend 1;r_skyscroll1 1;r_skyscroll2 2;r_waterwarp 1;r_wateralpha 1;r_waterscroll 1\n");
+                       Cbuf_AddText(cmd, "cl_particles 1;cl_particles_quake 1;cl_particles_quality 1;cl_particles_explosions_shell 0;r_explosionclip 1;cl_stainmaps 0;cl_stainmaps_clearonload 1;cl_decals 0;cl_particles_bulletimpacts 1;cl_particles_smoke 1;cl_particles_sparks 1;cl_particles_bubbles 1;cl_particles_blood 1;cl_particles_blood_alpha 1;cl_particles_blood_bloodhack 0;cl_beams_polygons 0;cl_beams_instantaimhack 0;cl_beams_quakepositionhack 1;cl_beams_lightatend 0;r_lerpmodels 1;r_lerpsprites 1;r_lerplightstyles 0;gl_polyblend 1;r_skyscroll1 1;r_skyscroll2 2;r_waterwarp 1;r_wateralpha 1;r_waterscroll 1\n");
                        break;
                case 19: // Effects: Normal
-                       Cbuf_AddText("cl_particles 1;cl_particles_quake 0;cl_particles_quality 1;cl_particles_explosions_shell 0;r_explosionclip 1;cl_stainmaps 0;cl_stainmaps_clearonload 1;cl_decals 1;cl_particles_bulletimpacts 1;cl_particles_smoke 1;cl_particles_sparks 1;cl_particles_bubbles 1;cl_particles_blood 1;cl_particles_blood_alpha 1;cl_particles_blood_bloodhack 1;cl_beams_polygons 1;cl_beams_instantaimhack 0;cl_beams_quakepositionhack 1;cl_beams_lightatend 0;r_lerpmodels 1;r_lerpsprites 1;r_lerplightstyles 0;gl_polyblend 1;r_skyscroll1 1;r_skyscroll2 2;r_waterwarp 1;r_wateralpha 1;r_waterscroll 1\n");
+                       Cbuf_AddText(cmd, "cl_particles 1;cl_particles_quake 0;cl_particles_quality 1;cl_particles_explosions_shell 0;r_explosionclip 1;cl_stainmaps 0;cl_stainmaps_clearonload 1;cl_decals 1;cl_particles_bulletimpacts 1;cl_particles_smoke 1;cl_particles_sparks 1;cl_particles_bubbles 1;cl_particles_blood 1;cl_particles_blood_alpha 1;cl_particles_blood_bloodhack 1;cl_beams_polygons 1;cl_beams_instantaimhack 0;cl_beams_quakepositionhack 1;cl_beams_lightatend 0;r_lerpmodels 1;r_lerpsprites 1;r_lerplightstyles 0;gl_polyblend 1;r_skyscroll1 1;r_skyscroll2 2;r_waterwarp 1;r_wateralpha 1;r_waterscroll 1\n");
                        break;
                case 20: // Effects: High
-                       Cbuf_AddText("cl_particles 1;cl_particles_quake 0;cl_particles_quality 2;cl_particles_explosions_shell 0;r_explosionclip 1;cl_stainmaps 1;cl_stainmaps_clearonload 1;cl_decals 1;cl_particles_bulletimpacts 1;cl_particles_smoke 1;cl_particles_sparks 1;cl_particles_bubbles 1;cl_particles_blood 1;cl_particles_blood_alpha 1;cl_particles_blood_bloodhack 1;cl_beams_polygons 1;cl_beams_instantaimhack 0;cl_beams_quakepositionhack 1;cl_beams_lightatend 0;r_lerpmodels 1;r_lerpsprites 1;r_lerplightstyles 0;gl_polyblend 1;r_skyscroll1 1;r_skyscroll2 2;r_waterwarp 1;r_wateralpha 1;r_waterscroll 1\n");
+                       Cbuf_AddText(cmd, "cl_particles 1;cl_particles_quake 0;cl_particles_quality 2;cl_particles_explosions_shell 0;r_explosionclip 1;cl_stainmaps 1;cl_stainmaps_clearonload 1;cl_decals 1;cl_particles_bulletimpacts 1;cl_particles_smoke 1;cl_particles_sparks 1;cl_particles_bubbles 1;cl_particles_blood 1;cl_particles_blood_alpha 1;cl_particles_blood_bloodhack 1;cl_beams_polygons 1;cl_beams_instantaimhack 0;cl_beams_quakepositionhack 1;cl_beams_lightatend 0;r_lerpmodels 1;r_lerpsprites 1;r_lerplightstyles 0;gl_polyblend 1;r_skyscroll1 1;r_skyscroll2 2;r_waterwarp 1;r_wateralpha 1;r_waterscroll 1\n");
                        break;
                case 21:
-                       M_Menu_Options_Graphics_f ();
+                       M_Menu_Options_Graphics_f(cmd);
                        break;
                case 22: // Lighting: Flares
-                       Cbuf_AddText("r_coronas 1;gl_flashblend 1;r_shadow_gloss 0;r_shadow_realtime_dlight 0;r_shadow_realtime_dlight_shadows 0;r_shadow_realtime_world 0;r_shadow_realtime_world_lightmaps 0;r_shadow_realtime_world_shadows 1;r_bloom 0");
+                       Cbuf_AddText(cmd, "r_coronas 1;gl_flashblend 1;r_shadow_gloss 0;r_shadow_realtime_dlight 0;r_shadow_realtime_dlight_shadows 0;r_shadow_realtime_world 0;r_shadow_realtime_world_lightmaps 0;r_shadow_realtime_world_shadows 1;r_bloom 0");
                        break;
                case 23: // Lighting: Normal
-                       Cbuf_AddText("r_coronas 1;gl_flashblend 0;r_shadow_gloss 1;r_shadow_realtime_dlight 1;r_shadow_realtime_dlight_shadows 0;r_shadow_realtime_world 0;r_shadow_realtime_world_lightmaps 0;r_shadow_realtime_world_shadows 1;r_bloom 0");
+                       Cbuf_AddText(cmd, "r_coronas 1;gl_flashblend 0;r_shadow_gloss 1;r_shadow_realtime_dlight 1;r_shadow_realtime_dlight_shadows 0;r_shadow_realtime_world 0;r_shadow_realtime_world_lightmaps 0;r_shadow_realtime_world_shadows 1;r_bloom 0");
                        break;
                case 24: // Lighting: High
-                       Cbuf_AddText("r_coronas 1;gl_flashblend 0;r_shadow_gloss 1;r_shadow_realtime_dlight 1;r_shadow_realtime_dlight_shadows 1;r_shadow_realtime_world 0;r_shadow_realtime_world_lightmaps 0;r_shadow_realtime_world_shadows 1;r_bloom 1");
+                       Cbuf_AddText(cmd, "r_coronas 1;gl_flashblend 0;r_shadow_gloss 1;r_shadow_realtime_dlight 1;r_shadow_realtime_dlight_shadows 1;r_shadow_realtime_world 0;r_shadow_realtime_world_lightmaps 0;r_shadow_realtime_world_shadows 1;r_bloom 1");
                        break;
                case 25: // Lighting: Full
-                       Cbuf_AddText("r_coronas 1;gl_flashblend 0;r_shadow_gloss 1;r_shadow_realtime_dlight 1;r_shadow_realtime_dlight_shadows 1;r_shadow_realtime_world 1;r_shadow_realtime_world_lightmaps 0;r_shadow_realtime_world_shadows 1;r_bloom 1");
+                       Cbuf_AddText(cmd, "r_coronas 1;gl_flashblend 0;r_shadow_gloss 1;r_shadow_realtime_dlight 1;r_shadow_realtime_dlight_shadows 1;r_shadow_realtime_world 1;r_shadow_realtime_world_lightmaps 0;r_shadow_realtime_world_shadows 1;r_bloom 1");
                        break;
                case 26:
-                       M_Menu_ModList_f ();
+                       M_Menu_ModList_f(cmd);
                        break;
                default:
                        M_Menu_Options_AdjustSliders (1);
@@ -1812,7 +1809,7 @@ static void M_Options_Key (int k, int ascii)
 
 static int options_effects_cursor;
 
-void M_Menu_Options_Effects_f (void)
+void M_Menu_Options_Effects_f(cmd_state_t *cmd)
 {
        key_dest = key_menu;
        m_state = m_options_effects;
@@ -1934,12 +1931,12 @@ static void M_Options_Effects_Draw (void)
 }
 
 
-static void M_Options_Effects_Key (int k, int ascii)
+static void M_Options_Effects_Key(cmd_state_t *cmd, int k, int ascii)
 {
        switch (k)
        {
        case K_ESCAPE:
-               M_Menu_Options_f ();
+               M_Menu_Options_f(cmd);
                break;
 
        case K_ENTER:
@@ -1975,7 +1972,7 @@ static void M_Options_Effects_Key (int k, int ascii)
 
 static int options_graphics_cursor;
 
-void M_Menu_Options_Graphics_f (void)
+void M_Menu_Options_Graphics_f(cmd_state_t *cmd)
 {
        key_dest = key_menu;
        m_state = m_options_graphics;
@@ -1999,7 +1996,7 @@ extern cvar_t r_hdr_scenebrightness;
 extern cvar_t r_hdr_glowintensity;
 extern cvar_t gl_picmip;
 
-static void M_Menu_Options_Graphics_AdjustSliders (int dir)
+static void M_Menu_Options_Graphics_AdjustSliders (cmd_state_t *cmd, int dir)
 {
        int optnum;
        S_LocalSound ("sound/misc/menu3.wav");
@@ -2023,7 +2020,7 @@ static void M_Menu_Options_Graphics_AdjustSliders (int dir)
        else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_bloom_brighten,                        bound(1, r_bloom_brighten.value + dir * 0.0625, 4));
        else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_bloom_blur,                            bound(1, r_bloom_blur.value + dir * 1, 16));
        else if (options_graphics_cursor == optnum++) Cvar_SetValueQuick (&r_bloom_resolution,                      bound(64, r_bloom_resolution.value + dir * 64, 2048));
-       else if (options_graphics_cursor == optnum++) Cbuf_AddText ("r_restart\n");
+       else if (options_graphics_cursor == optnum++) Cbuf_AddText(cmd, "r_restart\n");
 }
 
 
@@ -2064,16 +2061,16 @@ static void M_Options_Graphics_Draw (void)
 }
 
 
-static void M_Options_Graphics_Key (int k, int ascii)
+static void M_Options_Graphics_Key (cmd_state_t *cmd, int k, int ascii)
 {
        switch (k)
        {
        case K_ESCAPE:
-               M_Menu_Options_f ();
+               M_Menu_Options_f(cmd);
                break;
 
        case K_ENTER:
-               M_Menu_Options_Graphics_AdjustSliders (1);
+               M_Menu_Options_Graphics_AdjustSliders (cmd, 1);
                break;
 
        case K_UPARROW:
@@ -2091,11 +2088,11 @@ static void M_Options_Graphics_Key (int k, int ascii)
                break;
 
        case K_LEFTARROW:
-               M_Menu_Options_Graphics_AdjustSliders (-1);
+               M_Menu_Options_Graphics_AdjustSliders(cmd, -1);
                break;
 
        case K_RIGHTARROW:
-               M_Menu_Options_Graphics_AdjustSliders (1);
+               M_Menu_Options_Graphics_AdjustSliders(cmd, 1);
                break;
        }
 }
@@ -2106,9 +2103,9 @@ static void M_Options_Graphics_Key (int k, int ascii)
 static int             options_colorcontrol_cursor;
 
 // intensity value to match up to 50% dither to 'correct' quake
-static cvar_t menu_options_colorcontrol_correctionvalue = {0, "menu_options_colorcontrol_correctionvalue", "0.5", "intensity value that matches up to white/black dither pattern, should be 0.5 for linear color"};
+static cvar_t menu_options_colorcontrol_correctionvalue = {CF_CLIENT, "menu_options_colorcontrol_correctionvalue", "0.5", "intensity value that matches up to white/black dither pattern, should be 0.5 for linear color"};
 
-void M_Menu_Options_ColorControl_f (void)
+void M_Menu_Options_ColorControl_f(cmd_state_t *cmd)
 {
        key_dest = key_menu;
        m_state = m_options_colorcontrol;
@@ -2292,12 +2289,12 @@ static void M_Options_ColorControl_Draw (void)
 }
 
 
-static void M_Options_ColorControl_Key (int k, int ascii)
+static void M_Options_ColorControl_Key(cmd_state_t *cmd, int k, int ascii)
 {
        switch (k)
        {
        case K_ESCAPE:
-               M_Menu_Options_f ();
+               M_Menu_Options_f(cmd);
                break;
 
        case K_ENTER:
@@ -2554,7 +2551,7 @@ static void M_DefaultBinds (void)
 static int             keys_cursor;
 static int             bind_grab;
 
-void M_Menu_Keys_f (void)
+void M_Menu_Keys_f(cmd_state_t *cmd)
 {
        key_dest = key_menu_grabbed;
        m_state = m_keys;
@@ -2641,7 +2638,7 @@ static void M_Keys_Draw (void)
 
                Key_FindKeysForCommand (bindnames[i][0], keys, NUMKEYS, 0);
 
-               // LordHavoc: redesigned to print more than 2 keys, inspired by Tomaz's MiniRacer
+               // LadyHavoc: redesigned to print more than 2 keys, inspired by Tomaz's MiniRacer
                if (keys[0] == -1)
                        strlcpy(keystring, "???", sizeof(keystring));
                else
@@ -2664,13 +2661,13 @@ static void M_Keys_Draw (void)
        if (bind_grab)
                M_DrawCharacter (140, 48 + keys_cursor*8, '=');
        else
-               M_DrawCharacter (140, 48 + keys_cursor*8, 12+((int)(realtime*4)&1));
+               M_DrawCharacter (140, 48 + keys_cursor*8, 12+((int)(host.realtime*4)&1));
 }
 
 
-static void M_Keys_Key (int k, int ascii)
+static void M_Keys_Key(cmd_state_t *cmd, int k, int ascii)
 {
-       char    cmd[80];
+       char    line[80];
        int             keys[NUMKEYS];
        char    tinystr[2];
 
@@ -2683,8 +2680,8 @@ static void M_Keys_Key (int k, int ascii)
                }
                else //if (k != '`')
                {
-                       dpsnprintf (cmd, sizeof(cmd), "bind \"%s\" \"%s\"\n", Key_KeynumToString (k, tinystr, sizeof(tinystr)), bindnames[keys_cursor][0]);
-                       Cbuf_InsertText (cmd);
+                       dpsnprintf(line, sizeof(line), "bind \"%s\" \"%s\"\n", Key_KeynumToString(k, tinystr, sizeof(tinystr)), bindnames[keys_cursor][0]);
+                       Cbuf_InsertText (cmd, line);
                }
 
                bind_grab = false;
@@ -2694,7 +2691,7 @@ static void M_Keys_Key (int k, int ascii)
        switch (k)
        {
        case K_ESCAPE:
-               M_Menu_Options_f ();
+               M_Menu_Options_f(cmd);
                break;
 
        case K_LEFTARROW:
@@ -2737,7 +2734,7 @@ static void M_Keys_Key (int k, int ascii)
        }
 }
 
-void M_Menu_Reset_f (void)
+void M_Menu_Reset_f(cmd_state_t *cmd)
 {
        key_dest = key_menu;
        m_state = m_reset;
@@ -2745,13 +2742,13 @@ void M_Menu_Reset_f (void)
 }
 
 
-static void M_Reset_Key (int key, int ascii)
+static void M_Reset_Key(cmd_state_t *cmd, int key, int ascii)
 {
        switch (key)
        {
        case 'Y':
        case 'y':
-               Cbuf_AddText ("cvar_resettodefaults_all;exec default.cfg\n");
+               Cbuf_AddText(cmd, "cvar_resettodefaults_all;exec default.cfg\n");
                // no break here since we also exit the menu
 
        case K_ESCAPE:
@@ -2841,9 +2838,9 @@ video_resolution_t video_resolutions_hardcoded[] =
 // this is the number of the default mode (640x480) in the list above
 int video_resolutions_hardcoded_count = sizeof(video_resolutions_hardcoded) / sizeof(*video_resolutions_hardcoded) - 1;
 
-#define VIDEO_ITEMS 11
+#define VIDEO_ITEMS 10
 static int video_cursor = 0;
-static int video_cursor_table[VIDEO_ITEMS] = {68, 88, 96, 104, 112, 120, 128, 136, 144, 152, 168};
+static int video_cursor_table[VIDEO_ITEMS] = {68, 88, 96, 104, 112, 120, 128, 136, 144, 152};
 static int menu_video_resolution;
 
 video_resolution_t *video_resolutions;
@@ -2851,7 +2848,7 @@ int video_resolutions_count;
 
 static video_resolution_t *menu_video_resolutions;
 static int menu_video_resolutions_count;
-static qboolean menu_video_resolutions_forfullscreen;
+static qbool menu_video_resolutions_forfullscreen;
 
 static void M_Menu_Video_FindResolution(int w, int h, float a)
 {
@@ -2901,7 +2898,7 @@ static void M_Menu_Video_FindResolution(int w, int h, float a)
        }
 }
 
-void M_Menu_Video_f (void)
+void M_Menu_Video_f(cmd_state_t *cmd)
 {
        key_dest = key_menu;
        m_state = m_video;
@@ -2943,12 +2940,7 @@ static void M_Video_Draw (void)
        M_Print(96, video_cursor_table[t] + 8, va(vabuf, sizeof(vabuf), "Type: %s", menu_video_resolutions[menu_video_resolution].type));
        t++;
 
-       // Bits per pixel
-       M_Print(16, video_cursor_table[t], "        Bits per pixel");
-       M_Print(220, video_cursor_table[t], (vid_bitsperpixel.integer == 32) ? "32" : "16");
-       t++;
-
-       // Bits per pixel
+       // Antialiasing
        M_Print(16, video_cursor_table[t], "          Antialiasing");
        M_DrawSlider(220, video_cursor_table[t], vid_samples.value, 1, 32);
        t++;
@@ -2981,7 +2973,7 @@ static void M_Video_Draw (void)
        M_DrawSlider(220, video_cursor_table[t], gl_picmip.value, 3, 0);
        t++;
 
-       M_ItemPrint(16, video_cursor_table[t], "   Texture Compression", vid.support.arb_texture_compression);
+       M_ItemPrint(16, video_cursor_table[t], "   Texture Compression", true);
        M_DrawCheckbox(220, video_cursor_table[t], gl_texturecompression.integer);
        t++;
 
@@ -2990,7 +2982,7 @@ static void M_Video_Draw (void)
        t++;
 
        // Cursor
-       M_DrawCharacter(200, video_cursor_table[video_cursor], 12+((int)(realtime*4)&1));
+       M_DrawCharacter(200, video_cursor_table[video_cursor], 12+((int)(host.realtime*4)&1));
 }
 
 
@@ -3016,8 +3008,6 @@ static void M_Menu_Video_AdjustSliders (int dir)
                                break;
                }
        }
-       else if (video_cursor == t++)
-               Cvar_SetValueQuick (&vid_bitsperpixel, (vid_bitsperpixel.integer == 32) ? 16 : 32);
        else if (video_cursor == t++)
                Cvar_SetValueQuick (&vid_samples, bound(1, vid_samples.value * (dir > 0 ? 2 : 0.5), 32));
        else if (video_cursor == t++)
@@ -3037,7 +3027,7 @@ static void M_Menu_Video_AdjustSliders (int dir)
 }
 
 
-static void M_Video_Key (int key, int ascii)
+static void M_Video_Key(cmd_state_t *cmd, int key, int ascii)
 {
        switch (key)
        {
@@ -3051,7 +3041,7 @@ static void M_Video_Key (int key, int ascii)
                        Cvar_SetValueQuick(&vid_userefreshrate, vid.userefreshrate);
 
                        S_LocalSound ("sound/misc/menu1.wav");
-                       M_Menu_Options_f ();
+                       M_Menu_Options_f(cmd);
                        break;
 
                case K_ENTER:
@@ -3064,8 +3054,8 @@ static void M_Video_Key (int key, int ascii)
                                        Cvar_SetValueQuick (&vid_conwidth, menu_video_resolutions[menu_video_resolution].conwidth);
                                        Cvar_SetValueQuick (&vid_conheight, menu_video_resolutions[menu_video_resolution].conheight);
                                        Cvar_SetValueQuick (&vid_pixelheight, menu_video_resolutions[menu_video_resolution].pixelheight);
-                                       Cbuf_AddText ("vid_restart\n");
-                                       M_Menu_Options_f ();
+                                       Cbuf_AddText(cmd, "vid_restart\n");
+                                       M_Menu_Options_f(cmd);
                                        break;
                                default:
                                        M_Menu_Video_AdjustSliders (1);
@@ -3103,7 +3093,7 @@ static int                help_page;
 #define        NUM_HELP_PAGES  6
 
 
-void M_Menu_Help_f (void)
+void M_Menu_Help_f(cmd_state_t *cmd)
 {
        key_dest = key_menu;
        m_state = m_help;
@@ -3121,12 +3111,12 @@ static void M_Help_Draw (void)
 }
 
 
-static void M_Help_Key (int key, int ascii)
+static void M_Help_Key(cmd_state_t *cmd, int key, int ascii)
 {
        switch (key)
        {
        case K_ESCAPE:
-               M_Menu_Main_f ();
+               M_Menu_Main_f(cmd);
                break;
 
        case K_UPARROW:
@@ -3149,7 +3139,7 @@ static void M_Help_Key (int key, int ascii)
 //=============================================================================
 /* CEDITS MENU */
 
-void M_Menu_Credits_f (void)
+void M_Menu_Credits_f(cmd_state_t *cmd)
 {
        key_dest = key_menu;
        m_state = m_credits;
@@ -3168,9 +3158,9 @@ static void M_Credits_Draw (void)
 }
 
 
-static void M_Credits_Key (int key, int ascii)
+static void M_Credits_Key(cmd_state_t *cmd, int key, int ascii)
 {
-               M_Menu_Main_f ();
+               M_Menu_Main_f(cmd);
 }
 
 //=============================================================================
@@ -3178,7 +3168,7 @@ static void M_Credits_Key (int key, int ascii)
 
 static const char *m_quit_message[9];
 static int             m_quit_prevstate;
-static qboolean        wasInMenus;
+static qbool   wasInMenus;
 
 
 static int M_QuitMessage(const char *line1, const char *line2, const char *line3, const char *line4, const char *line5, const char *line6, const char *line7, const char *line8)
@@ -3259,7 +3249,7 @@ static int M_ChooseQuitMessage(int request)
        return 0;
 }
 
-void M_Menu_Quit_f (void)
+void M_Menu_Quit_f(cmd_state_t *cmd)
 {
        int n;
        if (m_state == m_quit)
@@ -3276,7 +3266,7 @@ void M_Menu_Quit_f (void)
 }
 
 
-static void M_Quit_Key (int key, int ascii)
+static void M_Quit_Key(cmd_state_t *cmd, int key, int ascii)
 {
        switch (key)
        {
@@ -3297,7 +3287,7 @@ static void M_Quit_Key (int key, int ascii)
 
        case 'Y':
        case 'y':
-               Host_Quit_f ();
+               host.state = host_shutdown;
                break;
 
        default:
@@ -3339,7 +3329,7 @@ static int        lanConfig_port;
 static char    lanConfig_portname[6];
 static char    lanConfig_joinname[40];
 
-void M_Menu_LanConfig_f (void)
+void M_Menu_LanConfig_f(cmd_state_t *cmd)
 {
        key_dest = key_menu;
        m_state = m_lanconfig;
@@ -3399,20 +3389,20 @@ static void M_LanConfig_Draw (void)
                M_Print(basex+8, lanConfig_cursor_table[1], "OK");
        }
 
-       M_DrawCharacter (basex-8, lanConfig_cursor_table [lanConfig_cursor], 12+((int)(realtime*4)&1));
+       M_DrawCharacter (basex-8, lanConfig_cursor_table [lanConfig_cursor], 12+((int)(host.realtime*4)&1));
 
        if (lanConfig_cursor == 0)
-               M_DrawCharacter (basex+9*8 + 8*strlen(lanConfig_portname), lanConfig_cursor_table [lanConfig_cursor], 10+((int)(realtime*4)&1));
+               M_DrawCharacter (basex+9*8 + 8*strlen(lanConfig_portname), lanConfig_cursor_table [lanConfig_cursor], 10+((int)(host.realtime*4)&1));
 
        if (lanConfig_cursor == 3)
-               M_DrawCharacter (basex+16 + 8*strlen(lanConfig_joinname), lanConfig_cursor_table [lanConfig_cursor], 10+((int)(realtime*4)&1));
+               M_DrawCharacter (basex+16 + 8*strlen(lanConfig_joinname), lanConfig_cursor_table [lanConfig_cursor], 10+((int)(host.realtime*4)&1));
 
        if (*m_return_reason)
                M_Print(basex, 168, m_return_reason);
 }
 
 
-static void M_LanConfig_Key (int key, int ascii)
+static void M_LanConfig_Key(cmd_state_t *cmd, int key, int ascii)
 {
        int             l;
        char vabuf[1024];
@@ -3420,7 +3410,7 @@ static void M_LanConfig_Key (int key, int ascii)
        switch (key)
        {
        case K_ESCAPE:
-               M_Menu_MultiPlayer_f ();
+               M_Menu_MultiPlayer_f(cmd);
                break;
 
        case K_UPARROW:
@@ -3449,23 +3439,23 @@ static void M_LanConfig_Key (int key, int ascii)
 
                m_entersound = true;
 
-               Cbuf_AddText ("stopdemo\n");
+               Cbuf_AddText(cmd, "stopdemo\n");
 
-               Cvar_SetValue("port", lanConfig_port);
+               Cvar_SetValue(&cvars_all, "port", lanConfig_port);
 
                if (lanConfig_cursor == 1 || lanConfig_cursor == 2)
                {
                        if (StartingGame)
                        {
-                               M_Menu_GameOptions_f ();
+                               M_Menu_GameOptions_f(cmd);
                                break;
                        }
-                       M_Menu_ServerList_f();
+                       M_Menu_ServerList_f(cmd);
                        break;
                }
 
                if (lanConfig_cursor == 3)
-                       Cbuf_AddText(va(vabuf, sizeof(vabuf), "connect \"%s\"\n", lanConfig_joinname) );
+                       Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "connect \"%s\"\n", lanConfig_joinname) );
                break;
 
        case K_BACKSPACE:
@@ -3959,10 +3949,10 @@ static gamelevels_t *gameoptions_levels  = NULL;
 static int     startepisode;
 static int     startlevel;
 static int maxplayers;
-static qboolean m_serverInfoMessage = false;
+static qbool m_serverInfoMessage = false;
 static double m_serverInfoMessageTime;
 
-void M_Menu_GameOptions_f (void)
+void M_Menu_GameOptions_f(cmd_state_t *cmd)
 {
        int i;
        key_dest = key_menu;
@@ -4008,7 +3998,7 @@ void M_GameOptions_Draw (void)
                if (gamemode == GAME_TRANSFUSION)
                {
                        if (!coop.integer && !deathmatch.integer)
-                               Cvar_SetValue("deathmatch", 1);
+                               Cvar_SetValue(&cvars_all, "deathmatch", 1);
                        if (deathmatch.integer == 0)
                                M_Print(160, 64, "Cooperative");
                        else if (deathmatch.integer == 2)
@@ -4019,7 +4009,7 @@ void M_GameOptions_Draw (void)
                else if (gamemode == GAME_BATTLEMECH)
                {
                        if (!deathmatch.integer)
-                               Cvar_SetValue("deathmatch", 1);
+                               Cvar_SetValue(&cvars_all, "deathmatch", 1);
                        if (deathmatch.integer == 2)
                                M_Print(160, 64, "Rambo Match");
                        else
@@ -4028,7 +4018,7 @@ void M_GameOptions_Draw (void)
                else
                {
                        if (!coop.integer && !deathmatch.integer)
-                               Cvar_SetValue("deathmatch", 1);
+                               Cvar_SetValue(&cvars_all, "deathmatch", 1);
                        if (coop.integer)
                                M_Print(160, 64, "Cooperative");
                        else
@@ -4124,13 +4114,13 @@ void M_GameOptions_Draw (void)
 
 // line cursor
        if (gameoptions_cursor == 9)
-               M_DrawCharacter (8 + 8 * strlen(hostname.string), gameoptions_cursor_table[gameoptions_cursor], 10+((int)(realtime*4)&1));
+               M_DrawCharacter (8 + 8 * strlen(hostname.string), gameoptions_cursor_table[gameoptions_cursor], 10+((int)(host.realtime*4)&1));
        else
-               M_DrawCharacter (144, gameoptions_cursor_table[gameoptions_cursor], 12+((int)(realtime*4)&1));
+               M_DrawCharacter (144, gameoptions_cursor_table[gameoptions_cursor], 12+((int)(host.realtime*4)&1));
 
        if (m_serverInfoMessage)
        {
-               if ((realtime - m_serverInfoMessageTime) < 5.0)
+               if ((host.realtime - m_serverInfoMessageTime) < 5.0)
                {
                        x = (320-26*8)/2;
                        M_DrawTextBox (x, 138, 24, 4);
@@ -4158,7 +4148,7 @@ static void M_NetStart_Change (int dir)
                {
                        maxplayers = MAX_SCOREBOARD;
                        m_serverInfoMessage = true;
-                       m_serverInfoMessageTime = realtime;
+                       m_serverInfoMessageTime = host.realtime;
                }
                if (maxplayers < 2)
                        maxplayers = 2;
@@ -4306,7 +4296,7 @@ static void M_NetStart_Change (int dir)
        }
 }
 
-static void M_GameOptions_Key (int key, int ascii)
+static void M_GameOptions_Key(cmd_state_t *cmd, int key, int ascii)
 {
        int l;
        char hostnamebuf[128];
@@ -4315,7 +4305,7 @@ static void M_GameOptions_Key (int key, int ascii)
        switch (key)
        {
        case K_ESCAPE:
-               M_Menu_MultiPlayer_f ();
+               M_Menu_MultiPlayer_f(cmd);
                break;
 
        case K_UPARROW:
@@ -4351,10 +4341,10 @@ static void M_GameOptions_Key (int key, int ascii)
                if (gameoptions_cursor == 0)
                {
                        if (sv.active)
-                               Cbuf_AddText("disconnect\n");
-                       Cbuf_AddText(va(vabuf, sizeof(vabuf), "maxplayers %u\n", maxplayers) );
+                               Cbuf_AddText(cmd, "disconnect\n");
+                       Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "maxplayers %u\n", maxplayers) );
 
-                       Cbuf_AddText(va(vabuf, sizeof(vabuf), "map %s\n", gameoptions_levels->levels[gameoptions_levels->episodes[startepisode].firstLevel + startlevel].name) );
+                       Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "map %s\n", gameoptions_levels->levels[gameoptions_levels->episodes[startepisode].firstLevel + startlevel].name) );
                        return;
                }
 
@@ -4370,7 +4360,7 @@ static void M_GameOptions_Key (int key, int ascii)
                                l = min(l - 1, 37);
                                memcpy(hostnamebuf, hostname.string, l);
                                hostnamebuf[l] = 0;
-                               Cvar_Set("hostname", hostnamebuf);
+                               Cvar_Set(&cvars_all, "hostname", hostnamebuf);
                        }
                }
                break;
@@ -4386,7 +4376,7 @@ static void M_GameOptions_Key (int key, int ascii)
                                memcpy(hostnamebuf, hostname.string, l);
                                hostnamebuf[l] = ascii;
                                hostnamebuf[l+1] = 0;
-                               Cvar_Set("hostname", hostnamebuf);
+                               Cvar_Set(&cvars_all, "hostname", hostnamebuf);
                        }
                }
        }
@@ -4397,7 +4387,7 @@ static void M_GameOptions_Key (int key, int ascii)
 
 static int slist_cursor;
 
-void M_Menu_ServerList_f (void)
+void M_Menu_ServerList_f(cmd_state_t *cmd)
 {
        key_dest = key_menu;
        m_state = m_slist;
@@ -4405,9 +4395,9 @@ void M_Menu_ServerList_f (void)
        slist_cursor = 0;
        M_Update_Return_Reason("");
        if (lanConfig_cursor == 2)
-               Net_SlistQW_f();
+               Net_SlistQW_f(cmd);
        else
-               Net_Slist_f();
+               Net_Slist_f(cmd);
 }
 
 
@@ -4441,12 +4431,12 @@ static void M_ServerList_Draw (void)
                for (n = start;n < end;n++)
                {
                        serverlist_entry_t *entry = ServerList_GetViewEntry(n);
-                       DrawQ_Fill(menu_x, menu_y + y, 640, 16, n == slist_cursor ? (0.5 + 0.2 * sin(realtime * M_PI)) : 0, 0, 0, 0.5, 0);
+                       DrawQ_Fill(menu_x, menu_y + y, 640, 16, n == slist_cursor ? (0.5 + 0.2 * sin(host.realtime * M_PI)) : 0, 0, 0, 0.5, 0);
                        M_PrintColored(0, y, entry->line1);y += 8;
                        M_PrintColored(0, y, entry->line2);y += 8;
                }
        }
-       else if (realtime - masterquerytime > 10)
+       else if (host.realtime - masterquerytime > 10)
        {
                if (masterquerycount)
                        M_Print(0, y, "No servers found");
@@ -4463,20 +4453,20 @@ static void M_ServerList_Draw (void)
 }
 
 
-static void M_ServerList_Key(int k, int ascii)
+static void M_ServerList_Key(cmd_state_t *cmd, int k, int ascii)
 {
        char vabuf[1024];
        switch (k)
        {
        case K_ESCAPE:
-               M_Menu_LanConfig_f();
+               M_Menu_LanConfig_f(cmd);
                break;
 
        case K_SPACE:
                if (lanConfig_cursor == 2)
-                       Net_SlistQW_f();
+                       Net_SlistQW_f(cmd);
                else
-                       Net_Slist_f();
+                       Net_Slist_f(cmd);
                break;
 
        case K_UPARROW:
@@ -4498,7 +4488,7 @@ static void M_ServerList_Key(int k, int ascii)
        case K_ENTER:
                S_LocalSound ("sound/misc/menu2.wav");
                if (serverlist_viewcount)
-                       Cbuf_AddText(va(vabuf, sizeof(vabuf), "connect \"%s\"\n", ServerList_GetViewEntry(slist_cursor)->info.cname));
+                       Cbuf_AddText(cmd, va(vabuf, sizeof(vabuf), "connect \"%s\"\n", ServerList_GetViewEntry(slist_cursor)->info.cname));
                break;
 
        default:
@@ -4516,7 +4506,7 @@ static int modlist_numenabled;                    //number of enabled (or in process to be..) mod
 
 typedef struct modlist_entry_s
 {
-       qboolean loaded;        // used to determine whether this entry is loaded and running
+       qbool loaded;   // used to determine whether this entry is loaded and running
        int enabled;            // index to array of modlist_enabled
 
        // name of the modification, this is (will...be) displayed on the menu entry
@@ -4606,7 +4596,7 @@ static void ModList_Enable (void)
        FS_ChangeGameDirs (modlist_numenabled, gamedirs, true, true);
 }
 
-void M_Menu_ModList_f (void)
+void M_Menu_ModList_f(cmd_state_t *cmd)
 {
        key_dest = key_menu;
        m_state = m_modlist;
@@ -4676,7 +4666,7 @@ static void M_ModList_Draw (void)
        {
                for (n = start;n < end;n++)
                {
-                       DrawQ_Pic(menu_x + 40, menu_y + y, NULL, 360, 8, n == modlist_cursor ? (0.5 + 0.2 * sin(realtime * M_PI)) : 0, 0, 0, 0.5, 0);
+                       DrawQ_Pic(menu_x + 40, menu_y + y, NULL, 360, 8, n == modlist_cursor ? (0.5 + 0.2 * sin(host.realtime * M_PI)) : 0, 0, 0, 0.5, 0);
                        M_ItemPrint(80, y, modlist[n].dir, true);
                        M_DrawCheckbox(48, y, modlist[n].loaded);
                        y +=8;
@@ -4688,13 +4678,13 @@ static void M_ModList_Draw (void)
        }
 }
 
-static void M_ModList_Key(int k, int ascii)
+static void M_ModList_Key(cmd_state_t *cmd, int k, int ascii)
 {
        switch (k)
        {
        case K_ESCAPE:
                ModList_Enable ();
-               M_Menu_Options_f();
+               M_Menu_Options_f(cmd);
                break;
 
        case K_SPACE:
@@ -4738,7 +4728,7 @@ static void M_ModList_Key(int k, int ascii)
 //=============================================================================
 /* Menu Subsystem */
 
-static void M_KeyEvent(int key, int ascii, qboolean downevent);
+static void M_KeyEvent(int key, int ascii, qbool downevent);
 static void M_Draw(void);
 void M_ToggleMenu(int mode);
 static void M_Shutdown(void);
@@ -4748,25 +4738,25 @@ static void M_Init (void)
        menuplyr_load = true;
        menuplyr_pixels = NULL;
 
-       Cmd_AddCommand ("menu_main", M_Menu_Main_f, "open the main menu");
-       Cmd_AddCommand ("menu_singleplayer", M_Menu_SinglePlayer_f, "open the singleplayer menu");
-       Cmd_AddCommand ("menu_load", M_Menu_Load_f, "open the loadgame menu");
-       Cmd_AddCommand ("menu_save", M_Menu_Save_f, "open the savegame menu");
-       Cmd_AddCommand ("menu_multiplayer", M_Menu_MultiPlayer_f, "open the multiplayer menu");
-       Cmd_AddCommand ("menu_setup", M_Menu_Setup_f, "open the player setup menu");
-       Cmd_AddCommand ("menu_options", M_Menu_Options_f, "open the options menu");
-       Cmd_AddCommand ("menu_options_effects", M_Menu_Options_Effects_f, "open the effects options menu");
-       Cmd_AddCommand ("menu_options_graphics", M_Menu_Options_Graphics_f, "open the graphics options menu");
-       Cmd_AddCommand ("menu_options_colorcontrol", M_Menu_Options_ColorControl_f, "open the color control menu");
-       Cmd_AddCommand ("menu_keys", M_Menu_Keys_f, "open the key binding menu");
-       Cmd_AddCommand ("menu_video", M_Menu_Video_f, "open the video options menu");
-       Cmd_AddCommand ("menu_reset", M_Menu_Reset_f, "open the reset to defaults menu");
-       Cmd_AddCommand ("menu_mods", M_Menu_ModList_f, "open the mods browser menu");
-       Cmd_AddCommand ("help", M_Menu_Help_f, "open the help menu");
-       Cmd_AddCommand ("menu_quit", M_Menu_Quit_f, "open the quit menu");
-       Cmd_AddCommand ("menu_transfusion_episode", M_Menu_Transfusion_Episode_f, "open the transfusion episode select menu");
-       Cmd_AddCommand ("menu_transfusion_skill", M_Menu_Transfusion_Skill_f, "open the transfusion skill select menu");
-       Cmd_AddCommand ("menu_credits", M_Menu_Credits_f, "open the credits menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_main", M_Menu_Main_f, "open the main menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_singleplayer", M_Menu_SinglePlayer_f, "open the singleplayer menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_load", M_Menu_Load_f, "open the loadgame menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_save", M_Menu_Save_f, "open the savegame menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_multiplayer", M_Menu_MultiPlayer_f, "open the multiplayer menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_setup", M_Menu_Setup_f, "open the player setup menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_options", M_Menu_Options_f, "open the options menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_options_effects", M_Menu_Options_Effects_f, "open the effects options menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_options_graphics", M_Menu_Options_Graphics_f, "open the graphics options menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_options_colorcontrol", M_Menu_Options_ColorControl_f, "open the color control menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_keys", M_Menu_Keys_f, "open the key binding menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_video", M_Menu_Video_f, "open the video options menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_reset", M_Menu_Reset_f, "open the reset to defaults menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_mods", M_Menu_ModList_f, "open the mods browser menu");
+       Cmd_AddCommand(CF_CLIENT, "help", M_Menu_Help_f, "open the help menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_quit", M_Menu_Quit_f, "open the quit menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_transfusion_episode", M_Menu_Transfusion_Episode_f, "open the transfusion episode select menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_transfusion_skill", M_Menu_Transfusion_Skill_f, "open the transfusion skill select menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_credits", M_Menu_Credits_f, "open the credits menu");
 }
 
 void M_Draw (void)
@@ -4882,7 +4872,7 @@ void M_Draw (void)
                        int g, scale_x, scale_y, scale_y_repeat, top_offset;
                        float scale_y_rate;
                        scale_y_repeat = vid_conheight.integer * 2;
-                       g = (int)(realtime * 64)%96;
+                       g = (int)(host.realtime * 64)%96;
                        scale_y_rate = (float)(g+1) / 96;
                        top_offset = (g+12)/12;
                        p = Draw_CachePic (va(vabuf, sizeof(vabuf), "gfx/menu/blooddrip%i", top_offset));
@@ -4918,8 +4908,9 @@ void M_Draw (void)
 }
 
 
-void M_KeyEvent (int key, int ascii, qboolean downevent)
+void M_KeyEvent (int key, int ascii, qbool downevent)
 {
+       cmd_state_t *cmd = cmd_local;
        if (!downevent)
                return;
        switch (m_state)
@@ -4928,95 +4919,95 @@ void M_KeyEvent (int key, int ascii, qboolean downevent)
                return;
 
        case m_main:
-               M_Main_Key (key, ascii);
+               M_Main_Key(cmd, key, ascii);
                return;
 
        case m_demo:
-               M_Demo_Key (key, ascii);
+               M_Demo_Key(cmd, key, ascii);
                return;
 
        case m_singleplayer:
-               M_SinglePlayer_Key (key, ascii);
+               M_SinglePlayer_Key(cmd, key, ascii);
                return;
 
        case m_transfusion_episode:
-               M_Transfusion_Episode_Key (key, ascii);
+               M_Transfusion_Episode_Key(cmd, key, ascii);
                return;
 
        case m_transfusion_skill:
-               M_Transfusion_Skill_Key (key, ascii);
+               M_Transfusion_Skill_Key(cmd, key, ascii);
                return;
 
        case m_load:
-               M_Load_Key (key, ascii);
+               M_Load_Key(cmd, key, ascii);
                return;
 
        case m_save:
-               M_Save_Key (key, ascii);
+               M_Save_Key(cmd, key, ascii);
                return;
 
        case m_multiplayer:
-               M_MultiPlayer_Key (key, ascii);
+               M_MultiPlayer_Key(cmd, key, ascii);
                return;
 
        case m_setup:
-               M_Setup_Key (key, ascii);
+               M_Setup_Key(cmd, key, ascii);
                return;
 
        case m_options:
-               M_Options_Key (key, ascii);
+               M_Options_Key(cmd, key, ascii);
                return;
 
        case m_options_effects:
-               M_Options_Effects_Key (key, ascii);
+               M_Options_Effects_Key(cmd, key, ascii);
                return;
 
        case m_options_graphics:
-               M_Options_Graphics_Key (key, ascii);
+               M_Options_Graphics_Key(cmd, key, ascii);
                return;
 
        case m_options_colorcontrol:
-               M_Options_ColorControl_Key (key, ascii);
+               M_Options_ColorControl_Key(cmd, key, ascii);
                return;
 
        case m_keys:
-               M_Keys_Key (key, ascii);
+               M_Keys_Key(cmd, key, ascii);
                return;
 
        case m_reset:
-               M_Reset_Key (key, ascii);
+               M_Reset_Key(cmd, key, ascii);
                return;
 
        case m_video:
-               M_Video_Key (key, ascii);
+               M_Video_Key(cmd, key, ascii);
                return;
 
        case m_help:
-               M_Help_Key (key, ascii);
+               M_Help_Key(cmd, key, ascii);
                return;
 
        case m_credits:
-               M_Credits_Key (key, ascii);
+               M_Credits_Key(cmd, key, ascii);
                return;
 
        case m_quit:
-               M_Quit_Key (key, ascii);
+               M_Quit_Key(cmd, key, ascii);
                return;
 
        case m_lanconfig:
-               M_LanConfig_Key (key, ascii);
+               M_LanConfig_Key(cmd, key, ascii);
                return;
 
        case m_gameoptions:
-               M_GameOptions_Key (key, ascii);
+               M_GameOptions_Key(cmd, key, ascii);
                return;
 
        case m_slist:
-               M_ServerList_Key (key, ascii);
+               M_ServerList_Key(cmd, key, ascii);
                return;
 
        case m_modlist:
-               M_ModList_Key (key, ascii);
+               M_ModList_Key(cmd, key, ascii);
                return;
        }
 
@@ -5208,19 +5199,23 @@ static prvm_required_field_t m_required_globals[] =
 
 static int m_numrequiredglobals = sizeof(m_required_globals) / sizeof(m_required_globals[0]);
 
-void MR_SetRouting (qboolean forceold);
+void MR_SetRouting (qbool forceold);
 
 void MVM_error_cmd(const char *format, ...) DP_FUNC_PRINTF(1);
 void MVM_error_cmd(const char *format, ...)
 {
        prvm_prog_t *prog = MVM_prog;
-       static qboolean processingError = false;
+       static qbool processingError = false;
        char errorstring[MAX_INPUTLINE];
        va_list argptr;
 
        va_start (argptr, format);
        dpvsnprintf (errorstring, sizeof(errorstring), format, argptr);
        va_end (argptr);
+
+       if (host.framecount < 3)
+               Sys_Error("Menu_Error: %s\n", errorstring);
+
        Con_Printf( "Menu_Error: %s\n", errorstring );
 
        if( !processingError ) {
@@ -5239,11 +5234,12 @@ void MVM_error_cmd(const char *format, ...)
        key_dest = key_game;
 
        // init the normal menu now -> this will also correct the menu router pointers
-       MR_SetRouting (TRUE);
+       MR_SetRouting (true);
 
        // reset the active scene, too (to be on the safe side ;))
-   R_SelectScene( RST_CLIENT );
+       R_SelectScene( RST_CLIENT );
 
+       // Let video start at least
        Host_AbortCurrentFrame();
 }
 
@@ -5282,12 +5278,12 @@ static void MVM_count_edicts(prvm_prog_t *prog)
        Con_Printf("active    :%3i\n", active);
 }
 
-static qboolean MVM_load_edict(prvm_prog_t *prog, prvm_edict_t *ent)
+static qbool MVM_load_edict(prvm_prog_t *prog, prvm_edict_t *ent)
 {
        return true;
 }
 
-static void MP_KeyEvent (int key, int ascii, qboolean downevent)
+static void MP_KeyEvent (int key, int ascii, qbool downevent)
 {
        prvm_prog_t *prog = MVM_prog;
 
@@ -5316,7 +5312,10 @@ static void MP_Draw (void)
        oldquality = r_refdef.view.quality;
        r_refdef.view.quality = 1;
        // TODO: this needs to be exposed to R_SetView (or something similar) ASAP [2/5/2008 Andreas]
-       r_refdef.scene.time = realtime;
+       r_refdef.scene.time = host.realtime;
+
+       // free memory for resources that are no longer referenced
+       PRVM_GarbageCollection(prog);
 
        // FIXME: this really shouldnt error out lest we have a very broken refdef state...?
        // or does it kill the server too?
@@ -5379,7 +5378,7 @@ static void MP_Shutdown (void)
 static void MP_Init (void)
 {
        prvm_prog_t *prog = MVM_prog;
-       PRVM_Prog_Init(prog);
+       PRVM_Prog_Init(prog, cmd_local);
 
        prog->edictprivate_size = 0; // no private struct used
        prog->name = "menu";
@@ -5415,20 +5414,20 @@ static void MP_Init (void)
        prog->ExecuteProgram(prog, PRVM_menufunction(m_init),"m_init() required");
 
        // Once m_init was called, we consider menuqc code fully initialized.
-       prog->inittime = realtime;
+       prog->inittime = host.realtime;
 }
 
 //============================================================================
 // Menu router
 
-void (*MR_KeyEvent) (int key, int ascii, qboolean downevent);
+void (*MR_KeyEvent) (int key, int ascii, qbool downevent);
 void (*MR_Draw) (void);
 void (*MR_ToggleMenu) (int mode);
 void (*MR_Shutdown) (void);
 void (*MR_NewMap) (void);
 int (*MR_GetServerListEntryCategory) (const serverlist_entry_t *entry);
 
-void MR_SetRouting(qboolean forceold)
+void MR_SetRouting(qbool forceold)
 {
        // if the menu prog isnt available or forceqmenu ist set, use the old menu
        if(!FS_FileExists(menu_progs.string) || forceqmenu.integer || forceold)
@@ -5459,14 +5458,19 @@ void MR_Restart(void)
 {
        if(MR_Shutdown)
                MR_Shutdown ();
-       MR_SetRouting (FALSE);
+       MR_SetRouting (false);
+}
+
+static void MR_Restart_f(cmd_state_t *cmd)
+{
+       MR_Restart();
 }
 
-static void Call_MR_ToggleMenu_f(void)
+static void Call_MR_ToggleMenu_f(cmd_state_t *cmd)
 {
        int m;
-       m = ((Cmd_Argc() < 2) ? -1 : atoi(Cmd_Argv(1)));
-       Host_StartVideo();
+       m = ((Cmd_Argc(cmd) < 2) ? -1 : atoi(Cmd_Argv(cmd, 1)));
+       CL_StartVideo();
        if(MR_ToggleMenu)
                MR_ToggleMenu(m);
 }
@@ -5477,8 +5481,8 @@ void MR_Init_Commands(void)
        Cvar_RegisterVariable (&forceqmenu);
        Cvar_RegisterVariable (&menu_options_colorcontrol_correctionvalue);
        Cvar_RegisterVariable (&menu_progs);
-       Cmd_AddCommand ("menu_restart",MR_Restart, "restart menu system (reloads menu.dat)");
-       Cmd_AddCommand ("togglemenu", Call_MR_ToggleMenu_f, "opens or closes menu");
+       Cmd_AddCommand(CF_CLIENT, "menu_restart", MR_Restart_f, "restart menu system (reloads menu.dat)");
+       Cmd_AddCommand(CF_CLIENT, "togglemenu", Call_MR_ToggleMenu_f, "opens or closes menu");
 }
 
 void MR_Init(void)
@@ -5608,13 +5612,13 @@ void MR_Init(void)
 
        // use -forceqmenu to use always the normal quake menu (it sets forceqmenu to 1)
 // COMMANDLINEOPTION: Client: -forceqmenu disables menu.dat (same as +forceqmenu 1)
-       if(COM_CheckParm("-forceqmenu"))
+       if(Sys_CheckParm("-forceqmenu"))
                Cvar_SetValueQuick(&forceqmenu,1);
        // use -useqmenu for debugging proposes, cause it starts
        // the normal quake menu only the first time
 // COMMANDLINEOPTION: Client: -useqmenu causes the first time you open the menu to use the quake menu, then reverts to menu.dat (if forceqmenu is 0)
-       if(COM_CheckParm("-useqmenu"))
-               MR_SetRouting (TRUE);
+       if(Sys_CheckParm("-useqmenu"))
+               MR_SetRouting (true);
        else
-               MR_SetRouting (FALSE);
+               MR_SetRouting (false);
 }