]> git.xonotic.org Git - xonotic/darkplaces.git/blobdiff - menu.c
physics: fix and refactor unsticking
[xonotic/darkplaces.git] / menu.c
diff --git a/menu.c b/menu.c
index 77218e4b4b8349bed1b96230c12862734a004f2f..8034f2f3d54fe70184cd83bac3f151ec11a9b592 100644 (file)
--- a/menu.c
+++ b/menu.c
@@ -28,13 +28,12 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 #define TYPE_GAME 2
 #define TYPE_BOTH 3
 
-static cvar_t forceqmenu = {CVAR_CLIENT, "forceqmenu", "0", "enables the quake menu instead of the quakec menu.dat (if present)"};
-static cvar_t menu_progs = {CVAR_CLIENT, "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(cmd_state_t *cmd);
        void M_Menu_SinglePlayer_f(cmd_state_t *cmd);
@@ -106,14 +105,7 @@ 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 qboolean        m_entersound;           ///< play after drawing a frame, so caching won't disrupt the sound
-
-void M_Update_Return_Reason(const char *s)
-{
-       strlcpy(m_return_reason, s, sizeof(m_return_reason));
-       if (s)
-               Con_DPrintf("%s\n", s);
-}
+static qbool   m_entersound;           ///< play after drawing a frame, so caching won't disrupt the sound
 
 #define StartingGame   (m_multiplayer_cursor == 1)
 #define JoiningGame            (m_multiplayer_cursor == 0)
@@ -282,7 +274,7 @@ static void M_ToggleMenu(int mode)
        {
                if(mode == 0)
                        return; // the menu is off, and we want it off
-               M_Menu_Main_f (&cmd_client);
+               M_Menu_Main_f (cmd_local);
        }
        else
        {
@@ -305,7 +297,7 @@ 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));
 }
 
 
@@ -355,7 +347,7 @@ static void M_Demo_Key (cmd_state_t *cmd, 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
 
@@ -448,7 +440,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;
        }
 
@@ -491,7 +483,7 @@ 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));
 }
@@ -772,7 +764,7 @@ 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));
        }
@@ -858,7 +850,7 @@ static void M_ScanSaves (void)
 
        for (i=0 ; i<MAX_SAVEGAMES ; i++)
        {
-               strlcpy (m_filenames[i], "--- UNUSED SLOT ---", sizeof(m_filenames[i]));
+               dp_strlcpy (m_filenames[i], "--- UNUSED SLOT ---", sizeof(m_filenames[i]));
                loadable[i] = false;
                dpsnprintf (name, sizeof(name), "s%i.sav", (int)i);
                f = FS_OpenRealFile (name, "rb", false);
@@ -874,7 +866,7 @@ static void M_ScanSaves (void)
                //version = atoi(com_token);
                // description
                COM_ParseToken_Simple(&t, false, false, true);
-               strlcpy (m_filenames[i], com_token, sizeof (m_filenames[i]));
+               dp_strlcpy (m_filenames[i], com_token, sizeof (m_filenames[i]));
 
        // change _ back to space
                for (j=0 ; j<SAVEGAME_COMMENT_LENGTH ; j++)
@@ -929,7 +921,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));
 }
 
 
@@ -947,7 +939,7 @@ 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));
 }
 
 
@@ -1226,7 +1218,7 @@ 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));
 }
@@ -1284,14 +1276,17 @@ static int              setup_oldrate;
 
 #define        NUM_SETUP_CMDS  5
 
+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;
+       dp_strlcpy(setup_myname, cl_name.string, sizeof(setup_myname));
+       setup_top = setup_oldtop = cl_topcolor.integer;
+       setup_bottom = setup_oldbottom = cl_bottomcolor.integer;
        setup_rate = cl_rate.integer;
 }
 
@@ -1420,9 +1415,9 @@ 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));
 }
 
 
@@ -1581,7 +1576,7 @@ void M_Menu_Options_f(cmd_state_t *cmd)
        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;
@@ -1615,8 +1610,8 @@ 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));
@@ -1634,7 +1629,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;
@@ -1646,7 +1641,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);
        }
@@ -1659,7 +1654,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);
        }
@@ -1692,8 +1687,8 @@ 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);
@@ -2100,7 +2095,7 @@ static void M_Options_Graphics_Key (cmd_state_t *cmd, 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 = {CVAR_CLIENT, "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(cmd_state_t *cmd)
 {
@@ -2247,8 +2242,8 @@ static void M_Options_ColorControl_Draw (void)
 
        m_opty += 4;
        DrawQ_Fill(menu_x, menu_y + m_opty, 320, 4 + 64 + 8 + 64 + 4, 0, 0, 0, 1, 0);m_opty += 4;
-       s = (float) 312 / 2 * vid.width / vid_conwidth.integer;
-       t = (float) 4 / 2 * vid.height / vid_conheight.integer;
+       s = (float) 312 / 2 * vid.mode.width / vid_conwidth.integer;
+       t = (float) 4 / 2 * vid.mode.height / vid_conheight.integer;
        DrawQ_SuperPic(menu_x + 4, menu_y + m_opty, dither, 312, 4, 0,0, 1,0,0,1, s,0, 1,0,0,1, 0,t, 1,0,0,1, s,t, 1,0,0,1, 0);m_opty += 4;
        DrawQ_SuperPic(menu_x + 4, menu_y + m_opty, NULL  , 312, 4, 0,0, 0,0,0,1, 1,0, 1,0,0,1, 0,1, 0,0,0,1, 1,1, 1,0,0,1, 0);m_opty += 4;
        DrawQ_SuperPic(menu_x + 4, menu_y + m_opty, dither, 312, 4, 0,0, 0,1,0,1, s,0, 0,1,0,1, 0,t, 0,1,0,1, s,t, 0,1,0,1, 0);m_opty += 4;
@@ -2262,8 +2257,8 @@ static void M_Options_ColorControl_Draw (void)
        c[1] = c[0];
        c[2] = c[1];
        VID_ApplyGammaToColor(c, c);
-       s = (float) 48 / 2 * vid.width / vid_conwidth.integer;
-       t = (float) 48 / 2 * vid.height / vid_conheight.integer;
+       s = (float) 48 / 2 * vid.mode.width / vid_conwidth.integer;
+       t = (float) 48 / 2 * vid.mode.height / vid_conheight.integer;
        u = s * 0.5;
        v = t * 0.5;
        m_opty += 8;
@@ -2637,18 +2632,18 @@ static void M_Keys_Draw (void)
 
                // LadyHavoc: redesigned to print more than 2 keys, inspired by Tomaz's MiniRacer
                if (keys[0] == -1)
-                       strlcpy(keystring, "???", sizeof(keystring));
+                       dp_strlcpy(keystring, "???", sizeof(keystring));
                else
                {
-                       char tinystr[2];
+                       char tinystr[TINYSTR_LEN];
                        keystring[0] = 0;
                        for (j = 0;j < NUMKEYS;j++)
                        {
                                if (keys[j] != -1)
                                {
                                        if (j > 0)
-                                               strlcat(keystring, " or ", sizeof(keystring));
-                                       strlcat(keystring, Key_KeynumToString (keys[j], tinystr, sizeof(tinystr)), sizeof(keystring));
+                                               dp_strlcat(keystring, " or ", sizeof(keystring));
+                                       dp_strlcat(keystring, Key_KeynumToString (keys[j], tinystr, TINYSTR_LEN), sizeof(keystring));
                                }
                        }
                }
@@ -2658,7 +2653,7 @@ 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));
 }
 
 
@@ -2666,7 +2661,7 @@ static void M_Keys_Key(cmd_state_t *cmd, int k, int ascii)
 {
        char    line[80];
        int             keys[NUMKEYS];
-       char    tinystr[2];
+       char    tinystr[TINYSTR_LEN];
 
        if (bind_grab)
        {       // defining a key
@@ -2677,7 +2672,7 @@ static void M_Keys_Key(cmd_state_t *cmd, int k, int ascii)
                }
                else //if (k != '`')
                {
-                       dpsnprintf(line, sizeof(line), "bind \"%s\" \"%s\"\n", Key_KeynumToString(k, tinystr, sizeof(tinystr)), bindnames[keys_cursor][0]);
+                       dpsnprintf(line, sizeof(line), "bind \"%s\" \"%s\"\n", Key_KeynumToString(k, tinystr, TINYSTR_LEN), bindnames[keys_cursor][0]);
                        Cbuf_InsertText (cmd, line);
                }
 
@@ -2821,6 +2816,7 @@ video_resolution_t video_resolutions_hardcoded[] =
 {"WideScreen 16x9"           , 1280, 720, 640, 360, 1     },
 {"WideScreen 16x9"           , 1360, 768, 680, 384, 1     },
 {"WideScreen 16x9"           , 1366, 768, 683, 384, 1     },
+{"WideScreen 16x9"           , 1600, 900, 640, 360, 1     },
 {"WideScreen 16x9"           , 1920,1080, 640, 360, 1     },
 {"WideScreen 16x9"           , 2560,1440, 640, 360, 1     },
 {"WideScreen 16x9"           , 3840,2160, 640, 360, 1     },
@@ -2837,7 +2833,7 @@ int video_resolutions_hardcoded_count = sizeof(video_resolutions_hardcoded) / si
 
 #define VIDEO_ITEMS 11
 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, 160};
 static int menu_video_resolution;
 
 video_resolution_t *video_resolutions;
@@ -2845,7 +2841,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 +2897,7 @@ void M_Menu_Video_f(cmd_state_t *cmd)
        m_state = m_video;
        m_entersound = true;
 
-       M_Menu_Video_FindResolution(vid.width, vid.height, vid_pixelheight.value);
+       M_Menu_Video_FindResolution(vid.mode.width, vid.mode.height, vid_pixelheight.value);
 }
 
 
@@ -2928,10 +2924,10 @@ static void M_Video_Draw (void)
 
        // Current and Proposed Resolution
        M_Print(16, video_cursor_table[t] - 12, "    Current Resolution");
-       if (vid_supportrefreshrate && vid.userefreshrate && vid.fullscreen)
-               M_Print(220, video_cursor_table[t] - 12, va(vabuf, sizeof(vabuf), "%dx%d %.2fhz", vid.width, vid.height, vid.refreshrate));
+       if (vid.mode.refreshrate && vid.mode.fullscreen && !vid.mode.desktopfullscreen)
+               M_Print(220, video_cursor_table[t] - 12, va(vabuf, sizeof(vabuf), "%dx%d %.2fhz", vid.mode.width, vid.mode.height, vid.mode.refreshrate));
        else
-               M_Print(220, video_cursor_table[t] - 12, va(vabuf, sizeof(vabuf), "%dx%d", vid.width, vid.height));
+               M_Print(220, video_cursor_table[t] - 12, va(vabuf, sizeof(vabuf), "%dx%d", vid.mode.width, vid.mode.height));
        M_Print(16, video_cursor_table[t], "        New Resolution");
        M_Print(220, video_cursor_table[t], va(vabuf, sizeof(vabuf), "%dx%d", menu_video_resolutions[menu_video_resolution].width, menu_video_resolutions[menu_video_resolution].height));
        M_Print(96, video_cursor_table[t] + 8, va(vabuf, sizeof(vabuf), "Type: %s", menu_video_resolutions[menu_video_resolution].type));
@@ -2943,13 +2939,8 @@ static void M_Video_Draw (void)
        t++;
 
        // Refresh Rate
-       M_ItemPrint(16, video_cursor_table[t], "      Use Refresh Rate", vid_supportrefreshrate);
-       M_DrawCheckbox(220, video_cursor_table[t], vid_userefreshrate.integer);
-       t++;
-
-       // Refresh Rate
-       M_ItemPrint(16, video_cursor_table[t], "          Refresh Rate", vid_supportrefreshrate && vid_userefreshrate.integer);
-       M_DrawSlider(220, video_cursor_table[t], vid_refreshrate.value, 50, 150);
+       M_ItemPrint(16, video_cursor_table[t], "          Refresh Rate", vid_fullscreen.integer && !vid_desktopfullscreen.integer);
+       M_DrawSlider(220, video_cursor_table[t], vid_refreshrate.value, 50, 480);
        t++;
 
        // Fullscreen
@@ -2957,9 +2948,19 @@ static void M_Video_Draw (void)
        M_DrawCheckbox(220, video_cursor_table[t], vid_fullscreen.integer);
        t++;
 
+       // Desktop Fullscreen
+       M_ItemPrint(16, video_cursor_table[t], "    Desktop Fullscreen", vid_fullscreen.integer);
+       M_DrawCheckbox(220, video_cursor_table[t], vid_desktopfullscreen.integer);
+       t++;
+
+       // Display selection (multi-monitor)
+       M_ItemPrint(16, video_cursor_table[t], "       Display/Monitor", vid_info_displaycount.integer > 1);
+       M_DrawSlider(220, video_cursor_table[t], vid_display.integer, 0, vid_info_displaycount.integer - 1);
+       t++;
+
        // Vertical Sync
        M_ItemPrint(16, video_cursor_table[t], "         Vertical Sync", true);
-       M_DrawCheckbox(220, video_cursor_table[t], vid_vsync.integer);
+       M_DrawSlider(220, video_cursor_table[t], vid_vsync.integer, -1, 1);
        t++;
 
        M_ItemPrint(16, video_cursor_table[t], "    Anisotropic Filter", vid.support.ext_texture_filter_anisotropic);
@@ -2979,7 +2980,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));
 }
 
 
@@ -3007,14 +3008,16 @@ static void M_Menu_Video_AdjustSliders (int dir)
        }
        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++) // allow jumping from the minimum refreshrate to 0 (auto)
+               Cvar_SetValueQuick (&vid_refreshrate, vid_refreshrate.value <= 50 && dir == -1 ? 0 : bound(50, vid_refreshrate.value + dir, 480));
        else if (video_cursor == t++)
-               Cvar_SetValueQuick (&vid_userefreshrate, !vid_userefreshrate.integer);
+               Cvar_SetValueQuick (&vid_fullscreen, !vid_fullscreen.integer);
        else if (video_cursor == t++)
-               Cvar_SetValueQuick (&vid_refreshrate, bound(50, vid_refreshrate.value + dir, 150));
+               Cvar_SetValueQuick (&vid_desktopfullscreen, !vid_desktopfullscreen.integer);
        else if (video_cursor == t++)
-               Cvar_SetValueQuick (&vid_fullscreen, !vid_fullscreen.integer);
+               Cvar_SetValueQuick (&vid_display, bound(0, vid_display.integer + dir, vid_info_displaycount.integer - 1));
        else if (video_cursor == t++)
-               Cvar_SetValueQuick (&vid_vsync, !vid_vsync.integer);
+               Cvar_SetValueQuick (&vid_vsync, bound(-1, vid_vsync.integer + dir, 1));
        else if (video_cursor == t++)
                Cvar_SetValueQuick (&gl_texture_anisotropy, bound(1, gl_texture_anisotropy.value * (dir < 0 ? 0.5 : 2.0), vid.max_anisotropy));
        else if (video_cursor == t++)
@@ -3030,12 +3033,12 @@ static void M_Video_Key(cmd_state_t *cmd, int key, int ascii)
        {
                case K_ESCAPE:
                        // vid_shared.c has a copy of the current video config. We restore it
-                       Cvar_SetValueQuick(&vid_fullscreen, vid.fullscreen);
-                       Cvar_SetValueQuick(&vid_bitsperpixel, vid.bitsperpixel);
-                       Cvar_SetValueQuick(&vid_samples, vid.samples);
-                       if (vid_supportrefreshrate)
-                               Cvar_SetValueQuick(&vid_refreshrate, vid.refreshrate);
-                       Cvar_SetValueQuick(&vid_userefreshrate, vid.userefreshrate);
+                       Cvar_SetValueQuick(&vid_display, vid.mode.display);
+                       Cvar_SetValueQuick(&vid_fullscreen, vid.mode.fullscreen);
+                       Cvar_SetValueQuick(&vid_desktopfullscreen, vid.mode.desktopfullscreen);
+                       Cvar_SetValueQuick(&vid_bitsperpixel, vid.mode.bitsperpixel);
+                       Cvar_SetValueQuick(&vid_samples, vid.mode.samples);
+                       Cvar_SetValueQuick(&vid_refreshrate, vid.mode.refreshrate);
 
                        S_LocalSound ("sound/misc/menu1.wav");
                        M_Menu_Options_f(cmd);
@@ -3165,7 +3168,7 @@ static void M_Credits_Key(cmd_state_t *cmd, 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)
@@ -3284,7 +3287,7 @@ static void M_Quit_Key(cmd_state_t *cmd, int key, int ascii)
 
        case 'Y':
        case 'y':
-               Host_Quit_f(cmd);
+               host.state = host_shutdown;
                break;
 
        default:
@@ -3341,7 +3344,7 @@ void M_Menu_LanConfig_f(cmd_state_t *cmd)
        lanConfig_port = 26000;
        dpsnprintf(lanConfig_portname, sizeof(lanConfig_portname), "%u", (unsigned int) lanConfig_port);
 
-       M_Update_Return_Reason("");
+       cl_connect_status[0] = '\0';
 }
 
 
@@ -3386,16 +3389,16 @@ 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);
+       if (*cl_connect_status)
+               M_Print(basex, 168, cl_connect_status);
 }
 
 
@@ -3946,7 +3949,7 @@ 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(cmd_state_t *cmd)
@@ -4111,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);
@@ -4145,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;
@@ -4382,7 +4385,8 @@ static void M_GameOptions_Key(cmd_state_t *cmd, int key, int ascii)
 //=============================================================================
 /* SLIST MENU */
 
-static int slist_cursor;
+static unsigned slist_cursor;
+static unsigned slist_visible;
 
 void M_Menu_ServerList_f(cmd_state_t *cmd)
 {
@@ -4390,7 +4394,7 @@ void M_Menu_ServerList_f(cmd_state_t *cmd)
        m_state = m_slist;
        m_entersound = true;
        slist_cursor = 0;
-       M_Update_Return_Reason("");
+       cl_connect_status[0] = '\0';
        if (lanConfig_cursor == 2)
                Net_SlistQW_f(cmd);
        else
@@ -4400,7 +4404,7 @@ void M_Menu_ServerList_f(cmd_state_t *cmd)
 
 static void M_ServerList_Draw (void)
 {
-       int n, y, visible, start, end, statnumplayers, statmaxplayers;
+       unsigned n, y, start, end, statnumplayers, statmaxplayers;
        cachepic_t *p;
        const char *s;
        char vabuf[1024];
@@ -4412,14 +4416,14 @@ static void M_ServerList_Draw (void)
                M_Background(640, vid_conheight.integer);
        // scroll the list as the cursor moves
        ServerList_GetPlayerStatistics(&statnumplayers, &statmaxplayers);
-       s = va(vabuf, sizeof(vabuf), "%i/%i masters %i/%i servers %i/%i players", masterreplycount, masterquerycount, serverreplycount, serverquerycount, statnumplayers, statmaxplayers);
+       s = va(vabuf, sizeof(vabuf), "%u/%u masters %u/%u servers %u/%u players", masterreplycount, masterquerycount, serverreplycount, serverquerycount, statnumplayers, statmaxplayers);
        M_PrintRed((640 - strlen(s) * 8) / 2, 32, s);
-       if (*m_return_reason)
-               M_Print(16, menu_height - 8, m_return_reason);
+       if (*cl_connect_status)
+               M_Print(16, menu_height - 8, cl_connect_status);
        y = 48;
-       visible = (int)((menu_height - 16 - y) / 8 / 2);
-       start = bound(0, slist_cursor - (visible >> 1), serverlist_viewcount - visible);
-       end = min(start + visible, serverlist_viewcount);
+       slist_visible = (menu_height - 16 - y) / 8 / 2;
+       start = min(slist_cursor - min(slist_cursor, slist_visible >> 1), serverlist_viewcount - min(serverlist_viewcount, slist_visible));
+       end = min(start + slist_visible, serverlist_viewcount);
 
        p = Draw_CachePic ("gfx/p_multi");
        M_DrawPic((640 - Draw_GetPicWidth(p)) / 2, 4, "gfx/p_multi");
@@ -4428,12 +4432,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");
@@ -4466,14 +4470,18 @@ static void M_ServerList_Key(cmd_state_t *cmd, int k, int ascii)
                        Net_Slist_f(cmd);
                break;
 
+       case K_PGUP:
+               slist_cursor -= slist_visible - 2;
        case K_UPARROW:
        case K_LEFTARROW:
                S_LocalSound ("sound/misc/menu1.wav");
                slist_cursor--;
-               if (slist_cursor < 0)
+               if (slist_cursor >= serverlist_viewcount)
                        slist_cursor = serverlist_viewcount - 1;
                break;
 
+       case K_PGDN:
+               slist_cursor += slist_visible - 2;
        case K_DOWNARROW:
        case K_RIGHTARROW:
                S_LocalSound ("sound/misc/menu1.wav");
@@ -4482,6 +4490,16 @@ static void M_ServerList_Key(cmd_state_t *cmd, int k, int ascii)
                        slist_cursor = 0;
                break;
 
+       case K_HOME:
+               S_LocalSound ("sound/misc/menu1.wav");
+               slist_cursor = 0;
+               break;
+
+       case K_END:
+               S_LocalSound ("sound/misc/menu1.wav");
+               slist_cursor = serverlist_viewcount - 1;
+               break;
+
        case K_ENTER:
                S_LocalSound ("sound/misc/menu2.wav");
                if (serverlist_viewcount)
@@ -4503,10 +4521,10 @@ 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
+       // name of the modification, this is displayed on the menu entry
        char name[128];
        // directory where we will find it
        char dir[MAX_QPATH];
@@ -4531,8 +4549,7 @@ static void ModList_RebuildList(void)
        modlist_numenabled = fs_numgamedirs;
        for (i = 0;i < list.numstrings && modlist_count < MODLIST_TOTALSIZE;i++)
        {
-               // quickly skip names with dot characters - generally these are files, not directories
-               if (strchr(list.strings[i], '.')) continue;
+               int desc_len;
 
                // reject any dirs that are part of the base game
                if (gamedirname1 && !strcasecmp(gamedirname1, list.strings[i])) continue;
@@ -4544,7 +4561,15 @@ static void ModList_RebuildList(void)
                description = FS_CheckGameDir(list.strings[i]);
                if (description == NULL || description == fs_checkgamedir_missing) continue;
 
-               strlcpy (modlist[modlist_count].dir, list.strings[i], sizeof(modlist[modlist_count].dir));
+               desc_len = min(strlen(description), sizeof(modlist[modlist_count].name));
+               for (j = 0; j < desc_len; ++j)
+                       if (!ISWHITESPACE(description[j]))
+                       {
+                               dp_strlcpy(modlist[modlist_count].name, description, sizeof(modlist[modlist_count].name));
+                               break;
+                       }
+
+               dp_strlcpy (modlist[modlist_count].dir, list.strings[i], sizeof(modlist[modlist_count].dir));
                //check currently loaded mods
                modlist[modlist_count].loaded = false;
                if (fs_numgamedirs)
@@ -4570,7 +4595,7 @@ static void ModList_Enable (void)
        // copy our mod list into an array for FS_ChangeGameDirs
        numgamedirs = modlist_numenabled;
        for (i = 0; i < modlist_numenabled; i++)
-               strlcpy (gamedirs[i], modlist[modlist_enabled[i]].dir,sizeof (gamedirs[i]));
+               dp_strlcpy (gamedirs[i], modlist[modlist_enabled[i]].dir,sizeof (gamedirs[i]));
 
        // this code snippet is from FS_ChangeGameDirs
        if (fs_numgamedirs == numgamedirs)
@@ -4599,7 +4624,7 @@ void M_Menu_ModList_f(cmd_state_t *cmd)
        m_state = m_modlist;
        m_entersound = true;
        modlist_cursor = 0;
-       M_Update_Return_Reason("");
+       cl_connect_status[0] = '\0';
        ModList_RebuildList();
 }
 
@@ -4649,8 +4674,8 @@ static void M_ModList_Draw (void)
        for (y = 0; y < modlist_numenabled; y++)
                M_PrintRed(432, 48 + y * 8, modlist[modlist_enabled[y]].dir);
 
-       if (*m_return_reason)
-               M_Print(16, menu_height - 8, m_return_reason);
+       if (*cl_connect_status)
+               M_Print(16, menu_height - 8, cl_connect_status);
        // scroll the list as the cursor moves
        y = 48;
        visible = (int)((menu_height - 16 - y) / 8 / 2);
@@ -4663,8 +4688,10 @@ 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);
-                       M_ItemPrint(80, y, modlist[n].dir, true);
+                       const char *item_label = (modlist[n].name[0] != '\0') ? modlist[n].name : modlist[n].dir;
+
+                       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, item_label, true);
                        M_DrawCheckbox(48, y, modlist[n].loaded);
                        y +=8;
                }
@@ -4725,7 +4752,7 @@ static void M_ModList_Key(cmd_state_t *cmd, 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);
@@ -4735,25 +4762,25 @@ static void M_Init (void)
        menuplyr_load = true;
        menuplyr_pixels = NULL;
 
-       Cmd_AddCommand(&cmd_client, "menu_main", M_Menu_Main_f, "open the main menu");
-       Cmd_AddCommand(&cmd_client, "menu_singleplayer", M_Menu_SinglePlayer_f, "open the singleplayer menu");
-       Cmd_AddCommand(&cmd_client, "menu_load", M_Menu_Load_f, "open the loadgame menu");
-       Cmd_AddCommand(&cmd_client, "menu_save", M_Menu_Save_f, "open the savegame menu");
-       Cmd_AddCommand(&cmd_client, "menu_multiplayer", M_Menu_MultiPlayer_f, "open the multiplayer menu");
-       Cmd_AddCommand(&cmd_client, "menu_setup", M_Menu_Setup_f, "open the player setup menu");
-       Cmd_AddCommand(&cmd_client, "menu_options", M_Menu_Options_f, "open the options menu");
-       Cmd_AddCommand(&cmd_client, "menu_options_effects", M_Menu_Options_Effects_f, "open the effects options menu");
-       Cmd_AddCommand(&cmd_client, "menu_options_graphics", M_Menu_Options_Graphics_f, "open the graphics options menu");
-       Cmd_AddCommand(&cmd_client, "menu_options_colorcontrol", M_Menu_Options_ColorControl_f, "open the color control menu");
-       Cmd_AddCommand(&cmd_client, "menu_keys", M_Menu_Keys_f, "open the key binding menu");
-       Cmd_AddCommand(&cmd_client, "menu_video", M_Menu_Video_f, "open the video options menu");
-       Cmd_AddCommand(&cmd_client, "menu_reset", M_Menu_Reset_f, "open the reset to defaults menu");
-       Cmd_AddCommand(&cmd_client, "menu_mods", M_Menu_ModList_f, "open the mods browser menu");
-       Cmd_AddCommand(&cmd_client, "help", M_Menu_Help_f, "open the help menu");
-       Cmd_AddCommand(&cmd_client, "menu_quit", M_Menu_Quit_f, "open the quit menu");
-       Cmd_AddCommand(&cmd_client, "menu_transfusion_episode", M_Menu_Transfusion_Episode_f, "open the transfusion episode select menu");
-       Cmd_AddCommand(&cmd_client, "menu_transfusion_skill", M_Menu_Transfusion_Skill_f, "open the transfusion skill select menu");
-       Cmd_AddCommand(&cmd_client, "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)
@@ -4869,7 +4896,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));
@@ -4905,9 +4932,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_client;
+       cmd_state_t *cmd = cmd_local;
        if (!downevent)
                return;
        switch (m_state)
@@ -5028,15 +5055,22 @@ void M_Shutdown(void)
 //============================================================================
 // Menu prog handling
 
-static const char *m_required_func[] = {
-"m_init",
-"m_keydown",
-"m_draw",
-"m_toggle",
-"m_shutdown",
-};
+static void MP_CheckRequiredFuncs(prvm_prog_t *prog, const char *filename)
+{
+       int i;
+       const char *m_required_func[] = {
+               "m_init",
+               "m_keydown",
+               "m_draw",
+               "m_toggle",
+               "m_shutdown",
+       };
+       int m_numrequiredfunc = sizeof(m_required_func) / sizeof(char*);
 
-static int m_numrequiredfunc = sizeof(m_required_func) / sizeof(char*);
+       for(i = 0; i < m_numrequiredfunc; ++i)
+               if(PRVM_ED_FindFunction(prog, m_required_func[i]) == 0)
+                       prog->error_cmd("%s: %s not found in %s",prog->name, m_required_func[i], filename);
+}
 
 static prvm_required_field_t m_required_fields[] =
 {
@@ -5196,42 +5230,51 @@ 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;
+       int outfd = sys.outfd;
+
+       // set output to stderr
+       sys.outfd = fileno(stderr);
 
        va_start (argptr, format);
        dpvsnprintf (errorstring, sizeof(errorstring), format, argptr);
        va_end (argptr);
-       Con_Printf( "Menu_Error: %s\n", errorstring );
 
-       if( !processingError ) {
+       if (host.framecount < 3)
+               Sys_Error("Menu_Error: %s", errorstring);
+
+       Con_Printf(CON_ERROR "Menu_Error: %s\n", errorstring);
+
+       if(!processingError)
+       {
                processingError = true;
-               PRVM_Crash(prog);
+               PRVM_Crash();
                processingError = false;
-       } else {
-               Con_Printf( "Menu_Error: Recursive call to MVM_error_cmd (from PRVM_Crash)!\n" );
        }
+       else
+               Sys_Error("Menu_Error: Recursive call to MVM_error_cmd (from PRVM_Crash)!");
 
-       // fall back to the normal menu
-
-       // say it
-       Con_Print("Falling back to normal menu\n");
-
+       Con_Print("Falling back to engine menu\n");
        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 );
+
+       // prevent an endless loop if the error was triggered by a command
+       Cbuf_Clear(cmd_local->cbuf);
 
+       // restore configured outfd
+       sys.outfd = outfd;
+
+       // Let video start at least
        Host_AbortCurrentFrame();
 }
 
@@ -5261,7 +5304,7 @@ static void MVM_count_edicts(prvm_prog_t *prog)
        for (i=0 ; i<prog->num_edicts ; i++)
        {
                ent = PRVM_EDICT_NUM(i);
-               if (ent->priv.required->free)
+               if (ent->free)
                        continue;
                active++;
        }
@@ -5270,12 +5313,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;
 
@@ -5291,10 +5334,12 @@ static void MP_KeyEvent (int key, int ascii, qboolean downevent)
 static void MP_Draw (void)
 {
        prvm_prog_t *prog = MVM_prog;
-       // declarations that are needed right now
-
        float oldquality;
 
+       // don't crash if we draw a frame between prog shutdown and restart, see Host_LoadConfig_f
+       if (!prog->loaded)
+               return;
+
        R_SelectScene( RST_MENU );
 
        // reset the temp entities each frame
@@ -5304,12 +5349,15 @@ 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?
-       PRVM_G_FLOAT(OFS_PARM0) = vid.width;
-       PRVM_G_FLOAT(OFS_PARM1) = vid.height;
+       PRVM_G_FLOAT(OFS_PARM0) = vid.mode.width;
+       PRVM_G_FLOAT(OFS_PARM1) = vid.mode.height;
        prog->ExecuteProgram(prog, PRVM_menufunction(m_draw),"m_draw() required");
 
        // TODO: imo this should be moved into scene, too [1/27/2008 Andreas]
@@ -5367,7 +5415,7 @@ static void MP_Shutdown (void)
 static void MP_Init (void)
 {
        prvm_prog_t *prog = MVM_prog;
-       PRVM_Prog_Init(prog, &cmd_client);
+       PRVM_Prog_Init(prog, cmd_local);
 
        prog->edictprivate_size = 0; // no private struct used
        prog->name = "menu";
@@ -5392,7 +5440,7 @@ static void MP_Init (void)
        // allocate the mempools
        prog->progs_mempool = Mem_AllocPool(menu_progs.string, 0, NULL);
 
-       PRVM_Prog_Load(prog, menu_progs.string, NULL, 0, m_numrequiredfunc, m_required_func, m_numrequiredfields, m_required_fields, m_numrequiredglobals, m_required_globals);
+       PRVM_Prog_Load(prog, menu_progs.string, NULL, 0, MP_CheckRequiredFuncs, m_numrequiredfields, m_required_fields, m_numrequiredglobals, m_required_globals);
 
        // note: OP_STATE is not supported by menu qc, we don't even try to detect
        // it here
@@ -5403,20 +5451,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)
@@ -5447,7 +5495,7 @@ void MR_Restart(void)
 {
        if(MR_Shutdown)
                MR_Shutdown ();
-       MR_SetRouting (FALSE);
+       MR_SetRouting (false);
 }
 
 static void MR_Restart_f(cmd_state_t *cmd)
@@ -5459,7 +5507,7 @@ static void Call_MR_ToggleMenu_f(cmd_state_t *cmd)
 {
        int m;
        m = ((Cmd_Argc(cmd) < 2) ? -1 : atoi(Cmd_Argv(cmd, 1)));
-       Host_StartVideo();
+       CL_StartVideo();
        if(MR_ToggleMenu)
                MR_ToggleMenu(m);
 }
@@ -5470,8 +5518,8 @@ void MR_Init_Commands(void)
        Cvar_RegisterVariable (&forceqmenu);
        Cvar_RegisterVariable (&menu_options_colorcontrol_correctionvalue);
        Cvar_RegisterVariable (&menu_progs);
-       Cmd_AddCommand(&cmd_client, "menu_restart", MR_Restart_f, "restart menu system (reloads menu.dat)");
-       Cmd_AddCommand(&cmd_client, "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)
@@ -5597,17 +5645,17 @@ void MR_Init(void)
        }
 
        menu_video_resolutions_forfullscreen = !!vid_fullscreen.integer;
-       M_Menu_Video_FindResolution(vid.width, vid.height, vid_pixelheight.value);
+       M_Menu_Video_FindResolution(vid.mode.width, vid.mode.height, vid_pixelheight.value);
 
        // 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);
 }