Esempio n. 1
0
        public Cvar(string name, string value, bool archive, bool server)
        {
            if (String.IsNullOrEmpty(name))
            {
                throw new ArgumentNullException("name");
            }
            Cvar var = Find(name);
            if (var != null)
            {
                throw new ArgumentException(String.Format("Can't register variable {0}, already defined!\n", name));
                //Con_Printf("Can't register variable %s, allready defined\n", variable->name);
                //return;
            }
            if (Cmd.Exists(name))
            {
                throw new ArgumentException(String.Format("Can't register variable: {0} is a command!\n", name));
            }
            _Next = _Vars;
            _Vars = this;

            _Name = name;
            _String = value;
            _Flags[Flags.Archive] = archive;
            _Flags[Flags.Server] = server;
            _Value = Common.atof(_String);
        }
Esempio n. 2
0
 // Chase_Init
 public static void Init()
 {
     if (_Back == null)
     {
         _Back = new Cvar("chase_back", "100");
         _Up = new Cvar("chase_up", "16");
         _Right = new Cvar("chase_right", "0");
         _Active = new Cvar("chase_active", "0");
     }
 }
Esempio n. 3
0
        // Host_InitLocal
        static void InitLocal()
        {
            InitCommands();

            if (_Sys_TickRate == null)
            {
                _Sys_TickRate = new Cvar("sys_ticrate", "0.05");
                _Developer = new Cvar("developer", "0");
                _FrameRate = new Cvar("host_framerate", "0"); // set for slow motion
                _Speeds = new Cvar("host_speeds", "0");	// set for running times
                _ServerProfile = new Cvar("serverprofile", "0");
                _FragLimit = new Cvar("fraglimit", "0", false, true);
                _TimeLimit = new Cvar("timelimit", "0", false, true);
                _Teamplay = new Cvar("teamplay", "0", false, true);
                _SameLevel = new Cvar("samelevel", "0");
                _NoExit = new Cvar("noexit", "0", false, true);
                _Skill = new Cvar("skill", "1"); // 0 - 3
                _Deathmatch = new Cvar("deathmatch", "0"); // 0, 1, or 2
                _Coop = new Cvar("coop", "0"); // 0 or 1
                _Pausable = new Cvar("pausable", "1");
                _Temp1 = new Cvar("temp1", "0");
            }

            FindMaxClients ();

            _Time = 1.0;		// so a think at time 0 won't get called
        }
Esempio n. 4
0
        // VID_Init (unsigned char *palette)
        // Called at startup to set up translation tables, takes 256 8 bit RGB values
        // the palette data will go away after the call, so it must be copied off if
        // the video driver will need it again
        public static void Init(byte[] palette)
        {
            if (_glZTrick == null)
            {
                _glZTrick       = new Cvar("gl_ztrick", "1");
                _Mode           = new Cvar("vid_mode", "0", false);
                _DefaultMode    = new Cvar("_vid_default_mode", "0", true);
                _DefaultModeWin = new Cvar("_vid_default_mode_win", "3", true);
                _Wait           = new Cvar("vid_wait", "0");
                _NoPageFlip     = new Cvar("vid_nopageflip", "0", true);
                _WaitOverride   = new Cvar("_vid_wait_override", "0", true);
                _ConfigX        = new Cvar("vid_config_x", "800", true);
                _ConfigY        = new Cvar("vid_config_y", "600", true);
                _StretchBy2     = new Cvar("vid_stretch_by_2", "1", true);
                _WindowedMouse  = new Cvar("_windowed_mouse", "1", true);
            }

            Cmd.Add("vid_nummodes", NumModes_f);
            Cmd.Add("vid_describecurrentmode", DescribeCurrentMode_f);
            Cmd.Add("vid_describemode", DescribeMode_f);
            Cmd.Add("vid_describemodes", DescribeModes_f);

            DisplayDevice dev = MainForm.DisplayDevice;

            // Enumerate available modes, skip 8 bpp modes, and group by refresh rates
            List <mode_t> tmp = new List <mode_t>(dev.AvailableResolutions.Count);

            foreach (DisplayResolution res in dev.AvailableResolutions)
            {
                if (res.BitsPerPixel <= 8)
                {
                    continue;
                }

                Predicate <mode_t> SameMode = delegate(mode_t m)
                {
                    return(m.width == res.Width && m.height == res.Height && m.bpp == res.BitsPerPixel);
                };
                if (tmp.Exists(SameMode))
                {
                    continue;
                }

                mode_t mode = new mode_t();
                mode.width       = res.Width;
                mode.height      = res.Height;
                mode.bpp         = res.BitsPerPixel;
                mode.refreshRate = res.RefreshRate;
                tmp.Add(mode);
            }
            _Modes = tmp.ToArray();

            mode_t mode1 = new mode_t();

            mode1.width       = dev.Width;
            mode1.height      = dev.Height;
            mode1.bpp         = dev.BitsPerPixel;
            mode1.refreshRate = dev.RefreshRate;
            mode1.fullScreen  = true;

            int width = dev.Width, height = dev.Height;
            int i = Common.CheckParm("-width");

            if (i > 0 && i < Common.Argc - 1)
            {
                width = Common.atoi(Common.Argv(i + 1));

                foreach (DisplayResolution res in dev.AvailableResolutions)
                {
                    if (res.Width == width)
                    {
                        height = res.Height;
                        break;
                    }
                }
            }

            i = Common.CheckParm("-height");
            if (i > 0 && i < Common.Argc - 1)
            {
                height = Common.atoi(Common.Argv(i + 1));
            }

            mode1.width  = width;
            mode1.height = height;

            if (Common.HasParam("-window"))
            {
                _Windowed = true;
            }
            else
            {
                _Windowed = false;

                if (Common.HasParam("-current"))
                {
                    mode1.width  = dev.Width;
                    mode1.height = dev.Height;
                }
                else
                {
                    int bpp = mode1.bpp;
                    i = Common.CheckParm("-bpp");
                    if (i > 0 && i < Common.Argc - 1)
                    {
                        bpp = Common.atoi(Common.Argv(i + 1));
                    }
                    mode1.bpp = bpp;
                }
            }

            int i2 = Common.CheckParm("-conwidth");

            if (i2 > 0)
            {
                Scr.vid.conwidth = Common.atoi(Common.Argv(i2 + 1));
            }
            else
            {
                Scr.vid.conwidth = 640;
            }

            Scr.vid.conwidth &= 0xfff8; // make it a multiple of eight

            if (Scr.vid.conwidth < 320)
            {
                Scr.vid.conwidth = 320;
            }

            // pick a conheight that matches with correct aspect
            Scr.vid.conheight = Scr.vid.conwidth * 3 / 4;

            i2 = Common.CheckParm("-conheight");
            if (i2 > 0)
            {
                Scr.vid.conheight = Common.atoi(Common.Argv(i2 + 1));
            }
            if (Scr.vid.conheight < 200)
            {
                Scr.vid.conheight = 200;
            }

            Scr.vid.maxwarpwidth  = WARP_WIDTH;
            Scr.vid.maxwarpheight = WARP_HEIGHT;
            Scr.vid.colormap      = Host.ColorMap;
            int v = BitConverter.ToInt32(Host.ColorMap, 2048);

            Scr.vid.fullbright = 256 - Common.LittleLong(v);

            CheckGamma(palette);
            SetPalette(palette);

            mode1.fullScreen = !_Windowed;

            _DefModeNum = -1;
            for (i = 0; i < _Modes.Length; i++)
            {
                mode_t m = _Modes[i];
                if (m.width != mode1.width || m.height != mode1.height)
                {
                    continue;
                }

                _DefModeNum = i;

                if (m.bpp == mode1.bpp && m.refreshRate == mode1.refreshRate)
                {
                    break;
                }
            }
            if (_DefModeNum == -1)
            {
                _DefModeNum = 0;
            }

            SetMode(_DefModeNum, palette);

            InitOpenGL();

            Directory.CreateDirectory(Path.Combine(Common.GameDir, "glquake"));
        }
Esempio n. 5
0
        /// <summary>
        /// R_Init
        /// </summary>
        public static void Init()
        {
            for (int i = 0; i < _Frustum.Length; i++)
                _Frustum[i] = new mplane_t();

            Cmd.Add("timerefresh", TimeRefresh_f);
            //Cmd.Add("envmap", Envmap_f);
            //Cmd.Add("pointfile", ReadPointFile_f);

            if (_NoRefresh == null)
            {
                _NoRefresh = new Cvar("r_norefresh", "0");
                _DrawEntities = new Cvar("r_drawentities", "1");
                _DrawViewModel = new Cvar("r_drawviewmodel", "1");
                _Speeds = new Cvar("r_speeds", "0");
                _FullBright = new Cvar("r_fullbright", "0");
                _LightMap = new Cvar("r_lightmap", "0");
                _Shadows = new Cvar("r_shadows", "0");
                _MirrorAlpha = new Cvar("r_mirroralpha", "1");
                _WaterAlpha = new Cvar("r_wateralpha", "1");
                _Dynamic = new Cvar("r_dynamic", "1");
                _NoVis = new Cvar("r_novis", "0");

                _glFinish = new Cvar("gl_finish", "0");
                _glClear = new Cvar("gl_clear", "0");
                _glCull = new Cvar("gl_cull", "1");
                _glTexSort = new Cvar("gl_texsort", "1");
                _glSmoothModels = new Cvar("gl_smoothmodels", "1");
                _glAffineModels = new Cvar("gl_affinemodels", "0");
                _glPolyBlend = new Cvar("gl_polyblend", "1");
                _glFlashBlend = new Cvar("gl_flashblend", "1");
                _glPlayerMip = new Cvar("gl_playermip", "0");
                _glNoColors = new Cvar("gl_nocolors", "0");
                _glKeepTJunctions = new Cvar("gl_keeptjunctions", "0");
                _glReportTJunctions = new Cvar("gl_reporttjunctions", "0");
                _glDoubleEyes = new Cvar("gl_doubleeys", "1");
            }

             	        if (Vid.glMTexable)
                Cvar.Set("gl_texsort", 0.0f);

            InitParticles();
            InitParticleTexture();

            // reserve 16 textures
            _PlayerTextures = Drawer.GenerateTextureNumberRange(16);
        }
Esempio n. 6
0
        /*
         * =================
         * PF_cvar
         *
         * float cvar (string)
         * =================
         */
        static void PF_cvar()
        {
            string str = GetString(OFS.OFS_PARM0);

            ReturnFloat(Cvar.GetValue(str));
        }
Esempio n. 7
0
        /// <summary>
        /// V_RenderView
        /// The player's clipping box goes from (-16 -16 -24) to (16 16 32) from
        /// the entity origin, so any view position inside that will be valid
        /// </summary>
        public static void RenderView()
        {
            if (Con.ForcedUp)
            {
                return;
            }

            // don't allow cheats in multiplayer
            if (Client.Cl.maxclients > 1)
            {
                Cvar.Set("scr_ofsx", "0");
                Cvar.Set("scr_ofsy", "0");
                Cvar.Set("scr_ofsz", "0");
            }

            if (Client.Cl.intermission > 0)
            {
                // intermission / finale rendering
                CalcIntermissionRefDef();
            }
            else if (!Client.Cl.paused)
            {
                CalcRefDef();
            }

            Render.PushDlights();

            if (_LcdX.Value != 0)
            {
                //
                // render two interleaved views
                //
                viddef_t vid  = Scr.vid;
                Refdef_t rdef = Render.RefDef;

                vid.rowbytes <<= 1;
                vid.aspect    *= 0.5f;

                rdef.viewangles.Y -= _LcdYaw.Value;
                rdef.vieworg      -= _Right * _LcdX.Value;

                Render.RenderView();

                // ???????? vid.buffer += vid.rowbytes>>1;

                Render.PushDlights();

                rdef.viewangles.Y += _LcdYaw.Value * 2;
                rdef.vieworg      += _Right * _LcdX.Value * 2;

                Render.RenderView();

                // ????????? vid.buffer -= vid.rowbytes>>1;

                rdef.vrect.height <<= 1;

                vid.rowbytes >>= 1;
                vid.aspect    *= 2;
            }
            else
            {
                Render.RenderView();
            }
        }
Esempio n. 8
0
 // SCR_SizeDown_f
 //
 // Keybinding command
 static void SizeDown_f()
 {
     Cvar.Set("viewsize", _ViewSize.Value - 10);
     _VidDef.recalc_refdef = true;
 }
Esempio n. 9
0
        // SCR_CalcRefdef
        //
        // Must be called whenever vid changes
        // Internal use only
        static void CalcRefdef()
        {
            Scr.FullUpdate        = 0; // force a background redraw
            _VidDef.recalc_refdef = false;

            // force the status bar to redraw
            Sbar.Changed();

            // bound viewsize
            if (_ViewSize.Value < 30)
            {
                Cvar.Set("viewsize", "30");
            }

            if (_ViewSize.Value > 120)
            {
                Cvar.Set("viewsize", "120");
            }

            // bound field of view
            if (_Fov.Value < 10)
            {
                Cvar.Set("fov", "10");
            }

            if (_Fov.Value > 170)
            {
                Cvar.Set("fov", "170");
            }

            // intermission is always full screen
            float size;

            if (Client.Cl.intermission > 0)
            {
                size = 120;
            }
            else
            {
                size = _ViewSize.Value;
            }

            if (size >= 120)
            {
                Sbar.Lines = 0; // no status bar at all
            }
            else if (size >= 110)
            {
                Sbar.Lines = 24; // no inventory
            }
            else
            {
                Sbar.Lines = 24 + 16 + 8;
            }

            bool full = false;

            if (_ViewSize.Value >= 100.0)
            {
                full = true;
                size = 100.0f;
            }
            else
            {
                size = _ViewSize.Value;
            }

            if (Client.Cl.intermission > 0)
            {
                full       = true;
                size       = 100;
                Sbar.Lines = 0;
            }
            size /= 100.0f;

            int h = _VidDef.height - Sbar.Lines;

            Refdef_t rdef = Render.RefDef;

            rdef.vrect.width = (int)(_VidDef.width * size);
            if (rdef.vrect.width < 96)
            {
                size             = 96.0f / rdef.vrect.width;
                rdef.vrect.width = 96;          // min for icons
            }

            rdef.vrect.height = (int)(_VidDef.height * size);
            if (rdef.vrect.height > _VidDef.height - Sbar.Lines)
            {
                rdef.vrect.height = _VidDef.height - Sbar.Lines;
            }

            if (rdef.vrect.height > _VidDef.height)
            {
                rdef.vrect.height = _VidDef.height;
            }

            rdef.vrect.x = (_VidDef.width - rdef.vrect.width) / 2;
            if (full)
            {
                rdef.vrect.y = 0;
            }
            else
            {
                rdef.vrect.y = (h - rdef.vrect.height) / 2;
            }

            rdef.fov_x = _Fov.Value;
            rdef.fov_y = CalcFov(rdef.fov_x, rdef.vrect.width, rdef.vrect.height);

            _VRect = rdef.vrect;
        }
Esempio n. 10
0
        // vcrSendMessage
        // NET_Init (void)
        public static void Init()
        {
            for (int i2 = 0; i2 < _HostCache.Length; i2++)
            {
                _HostCache[i2] = new hostcache_t();
            }

            if (_Drivers == null)
            {
                if (Common.HasParam("-playback"))
                {
                    _Drivers = new INetDriver[]
                    {
                        new NetVcr()
                    };
                }
                else
                {
                    _Drivers = new INetDriver[]
                    {
                        new NetLoop(),
                        NetDatagram.Instance
                    };
                }
            }

            if (_LanDrivers == null)
            {
                _LanDrivers = new INetLanDriver[]
                {
                    NetTcpIp.Instance
                };
            }

            if (Common.HasParam("-record"))
            {
                _IsRecording = true;
            }

            int i = Common.CheckParm("-port");

            if (i == 0)
            {
                i = Common.CheckParm("-udpport");
            }
            if (i == 0)
            {
                i = Common.CheckParm("-ipxport");
            }

            if (i > 0)
            {
                if (i < Common.Argc - 1)
                {
                    _DefHostPort = Common.atoi(Common.Argv(i + 1));
                }
                else
                {
                    Sys.Error("Net.Init: you must specify a number after -port!");
                }
            }
            HostPort = _DefHostPort;

            if (Common.HasParam("-listen") || Client.cls.state == cactive_t.ca_dedicated)
            {
                _IsListening = true;
            }
            int numsockets = Server.svs.maxclientslimit;

            if (Client.cls.state != cactive_t.ca_dedicated)
            {
                numsockets++;
            }

            _FreeSockets   = new List <qsocket_t>(numsockets);
            _ActiveSockets = new List <qsocket_t>(numsockets);

            for (i = 0; i < numsockets; i++)
            {
                _FreeSockets.Add(new qsocket_t());
            }

            SetNetTime();

            // allocate space for network message buffer
            Message = new MsgWriter(NET_MAXMESSAGE);   // SZ_Alloc (&net_message, NET_MAXMESSAGE);
            Reader  = new MsgReader(Net.Message);

            if (_MessageTimeout == null)
            {
                _MessageTimeout = new Cvar("net_messagetimeout", "300");
                _HostName       = new Cvar("hostname", "UNNAMED");
            }

            Cmd.Add("slist", Slist_f);
            Cmd.Add("listen", Listen_f);
            Cmd.Add("maxplayers", MaxPlayers_f);
            Cmd.Add("port", Port_f);

            // initialize all the drivers
            _DriverLevel = 0;
            foreach (INetDriver driver in _Drivers)
            {
                driver.Init();
                if (driver.IsInitialized && _IsListening)
                {
                    driver.Listen(true);
                }
                _DriverLevel++;
            }

            //if (*my_ipx_address)
            //    Con_DPrintf("IPX address %s\n", my_ipx_address);
            if (!String.IsNullOrEmpty(_MyTcpIpAddress))
            {
                Con.DPrint("TCP/IP address {0}\n", _MyTcpIpAddress);
            }
        }
Esempio n. 11
0
        /// <summary>
        /// Mod_Init
        /// </summary>
        public static void Init()
        {
            if (_glSubDivideSize == null)
            {
                _glSubDivideSize = new Cvar("gl_subdivide_size", "128", true);
            }

            for (int i = 0; i < _Known.Length; i++)
                _Known[i] = new model_t();

            Common.FillArray(_Novis, (byte)0xff);
        }
Esempio n. 12
0
        // V_Init
        public static void Init()
        {
            Cmd.Add("v_cshift", CShift_f);
            Cmd.Add("bf", BonusFlash_f);
            Cmd.Add("centerview", StartPitchDrift);

            if (_LcdX == null)
            {
                _LcdX = new Cvar("lcd_x", "0");
                _LcdYaw = new Cvar("lcd_yaw", "0");

                _ScrOfsX = new Cvar("scr_ofsx", "0", false);
                _ScrOfsY = new Cvar("scr_ofsy", "0", false);
                _ScrOfsZ = new Cvar("scr_ofsz", "0", false);

                _ClRollSpeed = new Cvar("cl_rollspeed", "200");
                _ClRollAngle = new Cvar("cl_rollangle", "2.0");

                _ClBob = new Cvar("cl_bob", "0.02", false);
                _ClBobCycle = new Cvar("cl_bobcycle", "0.6", false);
                _ClBobUp = new Cvar("cl_bobup", "0.5", false);

                _KickTime = new Cvar("v_kicktime", "0.5", false);
                _KickRoll = new Cvar("v_kickroll", "0.6", false);
                _KickPitch = new Cvar("v_kickpitch", "0.6", false);

                _IYawCycle = new Cvar("v_iyaw_cycle", "2", false);
                _IRollCycle = new Cvar("v_iroll_cycle", "0.5", false);
                _IPitchCycle = new Cvar("v_ipitch_cycle", "1", false);
                _IYawLevel = new Cvar("v_iyaw_level", "0.3", false);
                _IRollLevel = new Cvar("v_iroll_level", "0.1", false);
                _IPitchLevel = new Cvar("v_ipitch_level", "0.3", false);

                _IdleScale = new Cvar("v_idlescale", "0", false);

                _Crosshair = new Cvar("crosshair", "0", true);
                _ClCrossX = new Cvar("cl_crossx", "0", false);
                _ClCrossY = new Cvar("cl_crossy", "0", false);

                _glCShiftPercent = new Cvar("gl_cshiftpercent", "100", false);

                _CenterMove = new Cvar("v_centermove", "0.15", false);
                _CenterSpeed = new Cvar("v_centerspeed", "500");

                BuildGammaTable(1.0f);	// no gamma yet
                _Gamma = new Cvar("gamma", "1", true);
            }
        }
Esempio n. 13
0
        // NET_Init (void)
        public static void Init()
        {
            for (int i2 = 0; i2 < _HostCache.Length; i2++)
                _HostCache[i2] = new hostcache_t();

            if (_Drivers == null)
            {
                if(Common.HasParam("-playback"))
                {
                    _Drivers = new INetDriver[]
                    {
                        new NetVcr()
                    };
                }
                else
                {
                    _Drivers = new INetDriver[]
                    {
                        new NetLoop(),
                        NetDatagram.Instance
                    };
                }
            }

            if (_LanDrivers == null)
            {
                _LanDrivers = new INetLanDriver[]
                {
                    NetTcpIp.Instance
                };
            }

            if (Common.HasParam("-record"))
                _IsRecording = true;

            int i = Common.CheckParm("-port");
            if (i == 0)
                i = Common.CheckParm("-udpport");
            if (i == 0)
                i = Common.CheckParm("-ipxport");

            if (i > 0)
            {
                if (i < Common.Argc - 1)
                    _DefHostPort = Common.atoi(Common.Argv(i + 1));
                else
                    Sys.Error("Net.Init: you must specify a number after -port!");
            }
            HostPort = _DefHostPort;

            if (Common.HasParam("-listen") || Client.cls.state == cactive_t.ca_dedicated)
                _IsListening = true;
            int numsockets = Server.svs.maxclientslimit;
            if (Client.cls.state != cactive_t.ca_dedicated)
                numsockets++;

            _FreeSockets = new List<qsocket_t>(numsockets);
            _ActiveSockets = new List<qsocket_t>(numsockets);

            for (i = 0; i < numsockets; i++)
                _FreeSockets.Add(new qsocket_t());

            SetNetTime();

            // allocate space for network message buffer
            Message = new MsgWriter(NET_MAXMESSAGE); // SZ_Alloc (&net_message, NET_MAXMESSAGE);
            Reader = new MsgReader(Net.Message);

            if (_MessageTimeout == null)
            {
                _MessageTimeout = new Cvar("net_messagetimeout", "300");
                _HostName = new Cvar("hostname", "UNNAMED");
            }

            Cmd.Add("slist", Slist_f);
            Cmd.Add("listen", Listen_f);
            Cmd.Add("maxplayers", MaxPlayers_f);
            Cmd.Add("port", Port_f);

            // initialize all the drivers
            _DriverLevel = 0;
            foreach (INetDriver driver in _Drivers)
            {
                driver.Init();
                if (driver.IsInitialized && _IsListening)
                {
                    driver.Listen(true);
                }
                _DriverLevel++;
            }

            //if (*my_ipx_address)
            //    Con_DPrintf("IPX address %s\n", my_ipx_address);
            if (!String.IsNullOrEmpty(_MyTcpIpAddress))
                Con.DPrint("TCP/IP address {0}\n", _MyTcpIpAddress);
        }
Esempio n. 14
0
        // VID_Init (unsigned char *palette)
        // Called at startup to set up translation tables, takes 256 8 bit RGB values
        // the palette data will go away after the call, so it must be copied off if
        // the video driver will need it again
        public static void Init(byte[] palette)
        {
            if (_glZTrick == null)
            {
                _glZTrick = new Cvar("gl_ztrick", "1");
                _Mode = new Cvar("vid_mode", "0", false);
                _DefaultMode = new Cvar("_vid_default_mode", "0", true);
                _DefaultModeWin = new Cvar("_vid_default_mode_win", "3", true);
                _Wait = new Cvar("vid_wait", "0");
                _NoPageFlip = new Cvar("vid_nopageflip", "0", true);
                _WaitOverride = new Cvar("_vid_wait_override", "0", true);
                _ConfigX = new Cvar("vid_config_x", "800", true);
                _ConfigY = new Cvar("vid_config_y", "600", true);
                _StretchBy2 = new Cvar("vid_stretch_by_2", "1", true);
                _WindowedMouse = new Cvar("_windowed_mouse", "1", true);
            }

            Cmd.Add("vid_nummodes", NumModes_f);
            Cmd.Add("vid_describecurrentmode", DescribeCurrentMode_f);
            Cmd.Add("vid_describemode", DescribeMode_f);
            Cmd.Add("vid_describemodes", DescribeModes_f);

            DisplayDevice dev = MainForm.DisplayDevice;

            // Enumerate available modes, skip 8 bpp modes, and group by refresh rates
            List<mode_t> tmp = new List<mode_t>(dev.AvailableResolutions.Count);
            foreach (DisplayResolution res in dev.AvailableResolutions)
            {
                if (res.BitsPerPixel <= 8)
                    continue;

                Predicate<mode_t> SameMode = delegate(mode_t m)
                {
                    return (m.width == res.Width && m.height == res.Height && m.bpp == res.BitsPerPixel);
                };
                if (tmp.Exists(SameMode))
                    continue;

                mode_t mode = new mode_t();
                mode.width = res.Width;
                mode.height = res.Height;
                mode.bpp = res.BitsPerPixel;
                mode.refreshRate = res.RefreshRate;
                tmp.Add(mode);
            }
            _Modes = tmp.ToArray();

            mode_t mode1 = new mode_t();
            mode1.width = dev.Width;
            mode1.height = dev.Height;
            mode1.bpp = dev.BitsPerPixel;
            mode1.refreshRate = dev.RefreshRate;
            mode1.fullScreen = true;

            int width = dev.Width, height = dev.Height;
            int i = Common.CheckParm("-width");
            if (i > 0 && i < Common.Argc - 1)
            {
                width = Common.atoi(Common.Argv(i + 1));

                foreach (DisplayResolution res in dev.AvailableResolutions)
                {
                    if (res.Width == width)
                    {
                        height = res.Height;
                        break;
                    }
                }
            }

            i = Common.CheckParm("-height");
            if (i > 0 && i < Common.Argc - 1)
                height = Common.atoi(Common.Argv(i + 1));

            mode1.width = width;
            mode1.height = height;

            if (Common.HasParam("-window"))
            {
                _Windowed = true;
            }
            else
            {
                _Windowed = false;

                if (Common.HasParam("-current"))
                {
                    mode1.width = dev.Width;
                    mode1.height = dev.Height;
                }
                else
                {
                    int bpp = mode1.bpp;
                    i = Common.CheckParm("-bpp");
                    if (i > 0 && i < Common.Argc - 1)
                    {
                        bpp = Common.atoi(Common.Argv(i + 1));
                    }
                    mode1.bpp = bpp;
                }
            }

            _IsInitialized = true;

            int i2 = Common.CheckParm("-conwidth");
            if (i2 > 0)
                Scr.vid.conwidth = Common.atoi(Common.Argv(i2 + 1));
            else
                Scr.vid.conwidth = 640;

            Scr.vid.conwidth &= 0xfff8; // make it a multiple of eight

            if (Scr.vid.conwidth < 320)
                Scr.vid.conwidth = 320;

            // pick a conheight that matches with correct aspect
            Scr.vid.conheight = Scr.vid.conwidth * 3 / 4;

            i2 = Common.CheckParm("-conheight");
            if (i2 > 0)
                Scr.vid.conheight = Common.atoi(Common.Argv(i2 + 1));
            if (Scr.vid.conheight < 200)
                Scr.vid.conheight = 200;

            Scr.vid.maxwarpwidth = WARP_WIDTH;
            Scr.vid.maxwarpheight = WARP_HEIGHT;
            Scr.vid.colormap = Host.ColorMap;
            int v = BitConverter.ToInt32(Host.ColorMap, 2048);
            Scr.vid.fullbright = 256 - Common.LittleLong(v);

            CheckGamma(palette);
            SetPalette(palette);

            mode1.fullScreen = !_Windowed;

            _DefModeNum = -1;
            for (i = 0; i < _Modes.Length; i++)
            {
                mode_t m = _Modes[i];
                if (m.width != mode1.width || m.height != mode1.height)
                    continue;

                _DefModeNum = i;

                if (m.bpp == mode1.bpp && m.refreshRate == mode1.refreshRate)
                    break;
            }
            if (_DefModeNum == -1)
                _DefModeNum = 0;

            SetMode(_DefModeNum, palette);

            InitOpenGL();

            Directory.CreateDirectory(Path.Combine(Common.GameDir, "glquake"));
        }
Esempio n. 15
0
        /// <summary>
        /// Key_Console
        /// Interactive line editing and console scrollback
        /// </summary>
        private static void KeyConsole(int key)
        {
            if (key == K_ENTER)
            {
                string line = new String(_Lines[_EditLine]).TrimEnd('\0', ' ');
                string cmd  = line.Substring(1);
                Cbuf.AddText(cmd);      // skip the >
                Cbuf.AddText("\n");
                Con.Print("{0}\n", line);
                _EditLine            = (_EditLine + 1) & 31;
                _HistoryLine         = _EditLine;
                _Lines[_EditLine][0] = ']';
                Key.LinePos          = 1;
                if (Client.cls.state == cactive_t.ca_disconnected)
                {
                    Scr.UpdateScreen(); // force an update, because the command
                }
                // may take some time
                return;
            }

            if (key == K_TAB)
            {
                // command completion
                string   txt   = new String(_Lines[_EditLine], 1, MAXCMDLINE - 1).TrimEnd('\0', ' ');
                string[] cmds  = Cmd.Complete(txt);
                string[] vars  = Cvar.CompleteName(txt);
                string   match = null;
                if (cmds != null)
                {
                    if (cmds.Length > 1 || vars != null)
                    {
                        Con.Print("\nCommands:\n");
                        foreach (string s in cmds)
                        {
                            Con.Print("  {0}\n", s);
                        }
                    }
                    else
                    {
                        match = cmds[0];
                    }
                }
                if (vars != null)
                {
                    if (vars.Length > 1 || cmds != null)
                    {
                        Con.Print("\nVariables:\n");
                        foreach (string s in vars)
                        {
                            Con.Print("  {0}\n", s);
                        }
                    }
                    else if (match == null)
                    {
                        match = vars[0];
                    }
                }
                if (!String.IsNullOrEmpty(match))
                {
                    int len = Math.Min(match.Length, MAXCMDLINE - 3);
                    for (int i = 0; i < len; i++)
                    {
                        _Lines[_EditLine][i + 1] = match[i];
                    }
                    Key.LinePos = len + 1;
                    _Lines[_EditLine][Key.LinePos] = ' ';
                    Key.LinePos++;
                    _Lines[_EditLine][Key.LinePos] = '\0';
                    return;
                }
            }

            if (key == K_BACKSPACE || key == K_LEFTARROW)
            {
                if (Key.LinePos > 1)
                {
                    Key.LinePos--;
                }
                return;
            }

            if (key == K_UPARROW)
            {
                do
                {
                    _HistoryLine = (_HistoryLine - 1) & 31;
                } while(_HistoryLine != _EditLine && (_Lines[_HistoryLine][1] == 0));
                if (_HistoryLine == _EditLine)
                {
                    _HistoryLine = (_EditLine + 1) & 31;
                }
                Array.Copy(_Lines[_HistoryLine], _Lines[_EditLine], MAXCMDLINE);
                Key.LinePos = 0;
                while (_Lines[_EditLine][Key.LinePos] != '\0' && Key.LinePos < MAXCMDLINE)
                {
                    Key.LinePos++;
                }
                return;
            }

            if (key == K_DOWNARROW)
            {
                if (_HistoryLine == _EditLine)
                {
                    return;
                }
                do
                {
                    _HistoryLine = (_HistoryLine + 1) & 31;
                }while(_HistoryLine != _EditLine && (_Lines[_HistoryLine][1] == '\0'));
                if (_HistoryLine == _EditLine)
                {
                    _Lines[_EditLine][0] = ']';
                    Key.LinePos          = 1;
                }
                else
                {
                    Array.Copy(_Lines[_HistoryLine], _Lines[_EditLine], MAXCMDLINE);
                    Key.LinePos = 0;
                    while (_Lines[_EditLine][Key.LinePos] != '\0' && Key.LinePos < MAXCMDLINE)
                    {
                        Key.LinePos++;
                    }
                }
                return;
            }

            if (key == K_PGUP || key == K_MWHEELUP)
            {
                Con.BackScroll += 2;
                if (Con.BackScroll > Con.TotalLines - (Scr.vid.height >> 3) - 1)
                {
                    Con.BackScroll = Con.TotalLines - (Scr.vid.height >> 3) - 1;
                }
                return;
            }

            if (key == K_PGDN || key == K_MWHEELDOWN)
            {
                Con.BackScroll -= 2;
                if (Con.BackScroll < 0)
                {
                    Con.BackScroll = 0;
                }
                return;
            }

            if (key == K_HOME)
            {
                Con.BackScroll = Con.TotalLines - (Scr.vid.height >> 3) - 1;
                return;
            }

            if (key == K_END)
            {
                Con.BackScroll = 0;
                return;
            }

            if (key < 32 || key > 127)
            {
                return; // non printable
            }
            if (Key.LinePos < MAXCMDLINE - 1)
            {
                _Lines[_EditLine][Key.LinePos] = (char)key;
                Key.LinePos++;
                _Lines[_EditLine][Key.LinePos] = '\0';
            }
        }
Esempio n. 16
0
        /// <summary>
        /// Host_FindMaxClients
        /// </summary>
        static void FindMaxClients()
        {
            server_static_t svs = Server.svs;
            ClientStatic    cls = Client.Cls;

            svs.maxclients = 1;

            int i = Common.CheckParm("-dedicated");

            if (i > 0)
            {
                cls.state = ClientActivityState.Dedicated;
                if (i != (Common.Argc - 1))
                {
                    svs.maxclients = Common.atoi(Common.Argv(i + 1));
                }
                else
                {
                    svs.maxclients = 8;
                }
            }
            else
            {
                cls.state = ClientActivityState.Disconnected;
            }

            i = Common.CheckParm("-listen");
            if (i > 0)
            {
                if (cls.state == ClientActivityState.Dedicated)
                {
                    Sys.Error("Only one of -dedicated or -listen can be specified");
                }

                if (i != (Common.Argc - 1))
                {
                    svs.maxclients = Common.atoi(Common.Argv(i + 1));
                }
                else
                {
                    svs.maxclients = 8;
                }
            }
            if (svs.maxclients < 1)
            {
                svs.maxclients = 8;
            }
            else if (svs.maxclients > QDef.MAX_SCOREBOARD)
            {
                svs.maxclients = QDef.MAX_SCOREBOARD;
            }

            svs.maxclientslimit = svs.maxclients;
            if (svs.maxclientslimit < 4)
            {
                svs.maxclientslimit = 4;
            }

            svs.clients = new client_t[svs.maxclientslimit]; // Hunk_AllocName (svs.maxclientslimit*sizeof(client_t), "clients");
            for (i = 0; i < svs.clients.Length; i++)
            {
                svs.clients[i] = new client_t();
            }

            if (svs.maxclients > 1)
            {
                Cvar.Set("deathmatch", 1.0f);
            }
            else
            {
                Cvar.Set("deathmatch", 0.0f);
            }
        }
Esempio n. 17
0
        // Draw_Init
        public static void Init()
        {
            for (int i = 0; i < _MenuCachePics.Length; i++)
            {
                _MenuCachePics[i] = new cachepic_t();
            }

            if (_glNoBind == null)
            {
                _glNoBind  = new Cvar("gl_nobind", "0");
                _glMaxSize = new Cvar("gl_max_size", "1024");
                _glPicMip  = new Cvar("gl_picmip", "0");
            }

            // 3dfx can only handle 256 wide textures
            string renderer = GL.GetString(StringName.Renderer);

            if (renderer.Contains("3dfx") || renderer.Contains("Glide"))
            {
                Cvar.Set("gl_max_size", "256");
            }

            Cmd.Add("gl_texturemode", TextureMode_f);

            // load the console background and the charset
            // by hand, because we need to write the version
            // string into the background before turning
            // it into a texture
            int offset = Wad.GetLumpNameOffset("conchars");

            byte[] draw_chars = Wad.Data; // draw_chars
            for (int i = 0; i < 256 * 64; i++)
            {
                if (draw_chars[offset + i] == 0)
                {
                    draw_chars[offset + i] = 255;   // proper transparent color
                }
            }

            // now turn them into textures
            _CharTexture = LoadTexture("charset", 128, 128, new ByteArraySegment(draw_chars, offset), false, true);

            byte[] buf = Common.LoadFile("gfx/conback.lmp");
            if (buf == null)
            {
                Sys.Error("Couldn't load gfx/conback.lmp");
            }

            dqpicheader_t cbHeader = Sys.BytesToStructure <dqpicheader_t>(buf, 0);

            Wad.SwapPic(cbHeader);

            // hack the version number directly into the pic
            string ver     = String.Format("(c# {0,7:F2}) {1,7:F2}", (float)QDef.CSQUAKE_VERSION, (float)QDef.VERSION);
            int    offset2 = Marshal.SizeOf(typeof(dqpicheader_t)) + 320 * 186 + 320 - 11 - 8 * ver.Length;
            int    y       = ver.Length;

            for (int x = 0; x < y; x++)
            {
                CharToConback(ver[x], new ByteArraySegment(buf, offset2 + (x << 3)), new ByteArraySegment(draw_chars, offset));
            }

            _ConBack        = new glpic_t();
            _ConBack.width  = cbHeader.width;
            _ConBack.height = cbHeader.height;
            int ncdataIndex = Marshal.SizeOf(typeof(dqpicheader_t)); // cb->data;

            SetTextureFilters(TextureMinFilter.Nearest, TextureMagFilter.Nearest);

            _ConBack.texnum = LoadTexture("conback", _ConBack.width, _ConBack.height, new ByteArraySegment(buf, ncdataIndex), false, false);
            _ConBack.width  = Scr.vid.width;
            _ConBack.height = Scr.vid.height;

            // save a texture slot for translated picture
            _TranslateTexture = _TextureExtensionNumber++;

            // save slots for scraps
            _ScrapTexNum             = _TextureExtensionNumber;
            _TextureExtensionNumber += MAX_SCRAPS;

            //
            // get the other pics we need
            //
            _Disc     = PicFromWad("disc");
            _BackTile = PicFromWad("backtile");
        }
Esempio n. 18
0
        /// <summary>
        /// UDP_Init
        /// </summary>
        public bool Init()
        {
            _IsInitialized = false;

            if (Common.HasParam("-noudp"))
            {
                return(false);
            }

            // determine my name
            string hostName;

            try
            {
                hostName = Dns.GetHostName();
            }
            catch (SocketException se)
            {
                Con.DPrint("Cannot get host name: {0}\n", se.Message);
                return(false);
            }

            // if the quake hostname isn't set, set it to the machine name
            if (Net.HostName == "UNNAMED")
            {
                IPAddress addr;
                if (!IPAddress.TryParse(hostName, out addr))
                {
                    int i = hostName.IndexOf('.');
                    if (i != -1)
                    {
                        hostName = hostName.Substring(0, i);
                    }
                }
                Cvar.Set("hostname", hostName);
            }

            int i2 = Common.CheckParm("-ip");

            if (i2 > 0)
            {
                if (i2 < Common.Argc - 1)
                {
                    string ipaddr = Common.Argv(i2 + 1);
                    if (!IPAddress.TryParse(ipaddr, out _MyAddress))
                    {
                        Sys.Error("{0} is not a valid IP address!", ipaddr);
                    }
                    Net.MyTcpIpAddress = ipaddr;
                }
                else
                {
                    Sys.Error("Net.Init: you must specify an IP address after -ip");
                }
            }
            else
            {
                _MyAddress         = IPAddress.Any;
                Net.MyTcpIpAddress = "INADDR_ANY";
            }

            _ControlSocket = OpenSocket(0);
            if (_ControlSocket == null)
            {
                Con.Print("TCP/IP: Unable to open control socket\n");
                return(false);
            }

            _BroadcastAddress = new IPEndPoint(IPAddress.Broadcast, Net.HostPort);

            _IsInitialized = true;
            Con.Print("TCP/IP Initialized\n");
            return(true);
        }
Esempio n. 19
0
 /*
  * =================
  * PF_cvar_set
  *
  * float cvar (string)
  * =================
  */
 static void PF_cvar_set()
 {
     Cvar.Set(GetString(OFS.OFS_PARM0), GetString(OFS.OFS_PARM1));
 }
Esempio n. 20
0
        /// <summary>
        /// Host_Loadgame_f
        /// </summary>
        static void Loadgame_f()
        {
            if (Cmd.Source != cmd_source_t.src_command)
            {
                return;
            }

            if (Cmd.Argc != 2)
            {
                Con.Print("load <savename> : load a game\n");
                return;
            }

            Client.Cls.demonum = -1;            // stop demo loop in case this fails

            string name = Path.ChangeExtension(Path.Combine(Common.GameDir, Cmd.Argv(1)), ".sav");

            // we can't call SCR_BeginLoadingPlaque, because too much stack space has
            // been used.  The menu calls it before stuffing loadgame command
            //	SCR_BeginLoadingPlaque ();

            Con.Print("Loading game from {0}...\n", name);
            FileStream fs = Sys.FileOpenRead(name);

            if (fs == null)
            {
                Con.Print("ERROR: couldn't open.\n");
                return;
            }

            using (StreamReader reader = new StreamReader(fs, Encoding.ASCII))
            {
                string line    = reader.ReadLine();
                int    version = Common.atoi(line);
                if (version != SAVEGAME_VERSION)
                {
                    Con.Print("Savegame is version {0}, not {1}\n", version, SAVEGAME_VERSION);
                    return;
                }
                line = reader.ReadLine();

                float[] spawn_parms = new float[Server.NUM_SPAWN_PARMS];
                for (int i = 0; i < spawn_parms.Length; i++)
                {
                    line           = reader.ReadLine();
                    spawn_parms[i] = Common.atof(line);
                }
                // this silliness is so we can load 1.06 save files, which have float skill values
                line = reader.ReadLine();
                float tfloat = Common.atof(line);
                Host.CurrentSkill = (int)(tfloat + 0.1);
                Cvar.Set("skill", (float)Host.CurrentSkill);

                string mapname = reader.ReadLine();
                line = reader.ReadLine();
                float time = Common.atof(line);

                Client.Disconnect_f();
                Server.SpawnServer(mapname);

                if (!Server.sv.active)
                {
                    Con.Print("Couldn't load map\n");
                    return;
                }
                Server.sv.paused   = true;              // pause until all clients connect
                Server.sv.loadgame = true;

                // load the light styles

                for (int i = 0; i < QDef.MAX_LIGHTSTYLES; i++)
                {
                    line = reader.ReadLine();
                    Server.sv.lightstyles[i] = line;
                }

                // load the edicts out of the savegame file
                int           entnum = -1;      // -1 is the globals
                StringBuilder sb     = new StringBuilder(32768);
                while (!reader.EndOfStream)
                {
                    line = reader.ReadLine();
                    if (line == null)
                    {
                        Sys.Error("EOF without closing brace");
                    }

                    sb.AppendLine(line);
                    int idx = line.IndexOf('}');
                    if (idx != -1)
                    {
                        int    length = 1 + sb.Length - (line.Length - idx);
                        string data   = Common.Parse(sb.ToString(0, length));
                        if (String.IsNullOrEmpty(Common.Token))
                        {
                            break; // end of file
                        }

                        if (Common.Token != "{")
                        {
                            Sys.Error("First token isn't a brace");
                        }

                        if (entnum == -1)
                        {
                            // parse the global vars
                            Progs.ParseGlobals(data);
                        }
                        else
                        {
                            // parse an edict
                            edict_t ent = Server.EdictNum(entnum);
                            ent.Clear();
                            Progs.ParseEdict(data, ent);

                            // link it into the bsp tree
                            if (!ent.free)
                            {
                                Server.LinkEdict(ent, false);
                            }
                        }

                        entnum++;
                        sb.Remove(0, length);
                    }
                }

                Server.sv.num_edicts = entnum;
                Server.sv.time       = time;

                for (int i = 0; i < Server.NUM_SPAWN_PARMS; i++)
                {
                    Server.svs.clients[0].spawn_parms[i] = spawn_parms[i];
                }
            }

            if (Client.Cls.state != ClientActivityState.Dedicated)
            {
                Client.EstablishConnection("local");
                Reconnect_f();
            }
        }
Esempio n. 21
0
        /// <summary>
        /// _Datagram_CheckNewConnections
        /// </summary>
        public qsocket_t InternalCheckNewConnections()
        {
            Socket acceptsock = Net.LanDriver.CheckNewConnections();

            if (acceptsock == null)
            {
                return(null);
            }

            EndPoint clientaddr = new IPEndPoint(IPAddress.Any, 0);

            Net.Message.FillFrom(acceptsock, ref clientaddr);

            if (Net.Message.Length < sizeof(int))
            {
                return(null);
            }

            Net.Reader.Reset();
            int control = Common.BigLong(Net.Reader.ReadLong());

            if (control == -1)
            {
                return(null);
            }
            if ((control & (~NetFlags.NETFLAG_LENGTH_MASK)) != NetFlags.NETFLAG_CTL)
            {
                return(null);
            }
            if ((control & NetFlags.NETFLAG_LENGTH_MASK) != Net.Message.Length)
            {
                return(null);
            }

            int command = Net.Reader.ReadByte();

            if (command == CCReq.CCREQ_SERVER_INFO)
            {
                string tmp = Net.Reader.ReadString();
                if (tmp != "QUAKE")
                {
                    return(null);
                }

                Net.Message.Clear();

                // save space for the header, filled in later
                Net.Message.WriteLong(0);
                Net.Message.WriteByte(CCRep.CCREP_SERVER_INFO);
                EndPoint newaddr = acceptsock.LocalEndPoint; //dfunc.GetSocketAddr(acceptsock, &newaddr);
                Net.Message.WriteString(newaddr.ToString()); // dfunc.AddrToString(&newaddr));
                Net.Message.WriteString(Net.HostName);
                Net.Message.WriteString(Server.sv.name);
                Net.Message.WriteByte(Net.ActiveConnections);
                Net.Message.WriteByte(Server.svs.maxclients);
                Net.Message.WriteByte(Net.NET_PROTOCOL_VERSION);
                Common.WriteInt(Net.Message.Data, 0, Common.BigLong(NetFlags.NETFLAG_CTL |
                                                                    (Net.Message.Length & NetFlags.NETFLAG_LENGTH_MASK)));
                Net.LanDriver.Write(acceptsock, Net.Message.Data, Net.Message.Length, clientaddr);
                Net.Message.Clear();
                return(null);
            }

            if (command == CCReq.CCREQ_PLAYER_INFO)
            {
                int      playerNumber = Net.Reader.ReadByte();
                int      clientNumber, activeNumber = -1;
                client_t client = null;
                for (clientNumber = 0; clientNumber < Server.svs.maxclients; clientNumber++)
                {
                    client = Server.svs.clients[clientNumber];
                    if (client.active)
                    {
                        activeNumber++;
                        if (activeNumber == playerNumber)
                        {
                            break;
                        }
                    }
                }
                if (clientNumber == Server.svs.maxclients)
                {
                    return(null);
                }

                Net.Message.Clear();
                // save space for the header, filled in later
                Net.Message.WriteLong(0);
                Net.Message.WriteByte(CCRep.CCREP_PLAYER_INFO);
                Net.Message.WriteByte(playerNumber);
                Net.Message.WriteString(client.name);
                Net.Message.WriteLong(client.colors);
                Net.Message.WriteLong((int)client.edict.v.frags);
                Net.Message.WriteLong((int)(Net.Time - client.netconnection.connecttime));
                Net.Message.WriteString(client.netconnection.address);
                Common.WriteInt(Net.Message.Data, 0, Common.BigLong(NetFlags.NETFLAG_CTL |
                                                                    (Net.Message.Length & NetFlags.NETFLAG_LENGTH_MASK)));
                Net.LanDriver.Write(acceptsock, Net.Message.Data, Net.Message.Length, clientaddr);
                Net.Message.Clear();

                return(null);
            }

            if (command == CCReq.CCREQ_RULE_INFO)
            {
                // find the search start location
                string prevCvarName = Net.Reader.ReadString();
                Cvar   var;
                if (!String.IsNullOrEmpty(prevCvarName))
                {
                    var = Cvar.Find(prevCvarName);
                    if (var == null)
                    {
                        return(null);
                    }
                    var = var.Next;
                }
                else
                {
                    var = Cvar.First;
                }

                // search for the next server cvar
                while (var != null)
                {
                    if (var.IsServer)
                    {
                        break;
                    }
                    var = var.Next;
                }

                // send the response
                Net.Message.Clear();

                // save space for the header, filled in later
                Net.Message.WriteLong(0);
                Net.Message.WriteByte(CCRep.CCREP_RULE_INFO);
                if (var != null)
                {
                    Net.Message.WriteString(var.Name);
                    Net.Message.WriteString(var.String);
                }
                Common.WriteInt(Net.Message.Data, 0, Common.BigLong(NetFlags.NETFLAG_CTL |
                                                                    (Net.Message.Length & NetFlags.NETFLAG_LENGTH_MASK)));
                Net.LanDriver.Write(acceptsock, Net.Message.Data, Net.Message.Length, clientaddr);
                Net.Message.Clear();

                return(null);
            }

            if (command != CCReq.CCREQ_CONNECT)
            {
                return(null);
            }

            if (Net.Reader.ReadString() != "QUAKE")
            {
                return(null);
            }

            if (Net.Reader.ReadByte() != Net.NET_PROTOCOL_VERSION)
            {
                Net.Message.Clear();
                // save space for the header, filled in later
                Net.Message.WriteLong(0);
                Net.Message.WriteByte(CCRep.CCREP_REJECT);
                Net.Message.WriteString("Incompatible version.\n");
                Common.WriteInt(Net.Message.Data, 0, Common.BigLong(NetFlags.NETFLAG_CTL |
                                                                    (Net.Message.Length & NetFlags.NETFLAG_LENGTH_MASK)));
                Net.LanDriver.Write(acceptsock, Net.Message.Data, Net.Message.Length, clientaddr);
                Net.Message.Clear();
                return(null);
            }

#if BAN_TEST
            // check for a ban
            if (clientaddr.sa_family == AF_INET)
            {
                unsigned long testAddr;
                testAddr = ((struct sockaddr_in *)&clientaddr)->sin_addr.s_addr;
Esempio n. 22
0
        /// <summary>
        /// Host_Status_f
        /// </summary>
        static void Status_f()
        {
            bool flag = true;

            if (Cmd.Source == cmd_source_t.src_command)
            {
                if (!Server.sv.active)
                {
                    Cmd.ForwardToServer();
                    return;
                }
            }
            else
            {
                flag = false;
            }

            StringBuilder sb = new StringBuilder(256);

            sb.Append(String.Format("host:    {0}\n", Cvar.GetString("hostname")));
            sb.Append(String.Format("version: {0:F2}\n", QDef.VERSION));
            if (Net.TcpIpAvailable)
            {
                sb.Append("tcp/ip:  ");
                sb.Append(Net.MyTcpIpAddress);
                sb.Append('\n');
            }

            sb.Append("map:     ");
            sb.Append(Server.sv.name);
            sb.Append('\n');
            sb.Append(String.Format("players: {0} active ({1} max)\n\n", Net.ActiveConnections, Server.svs.maxclients));
            for (int j = 0; j < Server.svs.maxclients; j++)
            {
                client_t client = Server.svs.clients[j];
                if (!client.active)
                {
                    continue;
                }

                int seconds = (int)(Net.Time - client.netconnection.connecttime);
                int hours, minutes = seconds / 60;
                if (minutes > 0)
                {
                    seconds -= (minutes * 60);
                    hours    = minutes / 60;
                    if (hours > 0)
                    {
                        minutes -= (hours * 60);
                    }
                }
                else
                {
                    hours = 0;
                }

                sb.Append(String.Format("#{0,-2} {1,-16}  {2}  {2}:{4,2}:{5,2}",
                                        j + 1, client.name, (int)client.edict.v.frags, hours, minutes, seconds));
                sb.Append("   ");
                sb.Append(client.netconnection.address);
                sb.Append('\n');
            }

            if (flag)
            {
                Con.Print(sb.ToString());
            }
            else
            {
                Server.ClientPrint(sb.ToString());
            }
        }
Esempio n. 23
0
        // VID_SetMode (int modenum, unsigned char *palette)
        // sets the mode; only used by the Quake engine for resetting to mode 0 (the
        // base mode) on memory allocation failures
        public static void SetMode(int modenum, byte[] palette)
        {
            if (modenum < 0 || modenum >= _Modes.Length)
            {
                Sys.Error("Bad video mode\n");
            }

            mode_t mode = _Modes[modenum];

            // so Con_Printfs don't mess us up by forcing vid and snd updates
            bool temp = Scr.IsDisabledForLoading;

            Scr.IsDisabledForLoading = true;

            CDAudio.Pause();

            // Set either the fullscreen or windowed mode
            DisplayDevice dev  = MainForm.DisplayDevice;
            MainForm      form = MainForm.Instance;

            if (_Windowed)
            {
                form.WindowState  = WindowState.Normal;
                form.WindowBorder = WindowBorder.Fixed;
                form.Location     = new Point((mode.width - form.Width) / 2, (mode.height - form.Height) / 2);
                if (_WindowedMouse.Value != 0 && Key.Destination == keydest_t.key_game)
                {
                    Input.ActivateMouse();
                    Input.HideMouse();
                }
                else
                {
                    Input.DeactivateMouse();
                    Input.ShowMouse();
                }
            }
            else
            {
                try
                {
                    dev.ChangeResolution(mode.width, mode.height, mode.bpp, mode.refreshRate);
                }
                catch (Exception ex)
                {
                    Sys.Error("Couldn't set video mode: " + ex.Message);
                }
                form.WindowState  = WindowState.Fullscreen;
                form.WindowBorder = WindowBorder.Hidden;
            }

            viddef_t vid = Scr.vid;

            if (vid.conheight > dev.Height)
            {
                vid.conheight = dev.Height;
            }
            if (vid.conwidth > dev.Width)
            {
                vid.conwidth = dev.Width;
            }

            vid.width  = vid.conwidth;
            vid.height = vid.conheight;

            vid.numpages = 2;

            CDAudio.Resume();
            Scr.IsDisabledForLoading = temp;

            _ModeNum = modenum;
            Cvar.Set("vid_mode", (float)_ModeNum);

            // fix the leftover Alt from any Alt-Tab or the like that switched us away
            ClearAllStates();

            Con.SafePrint("Video mode {0} initialized.\n", GetModeDescription(_ModeNum));

            SetPalette(palette);

            vid.recalc_refdef = true;
        }
Esempio n. 24
0
        // PR_Init
        public static void Init()
        {
            Cmd.Add("edict", PrintEdict_f);
            Cmd.Add("edicts", PrintEdicts);
            Cmd.Add("edictcount", EdictCount);
            Cmd.Add("profile", Profile_f);
            Cmd.Add("test5", Test5_f);

            if (_NoMonsters == null)
            {
                _NoMonsters = new Cvar("nomonsters", "0");
                _GameCfg = new Cvar("gamecfg", "0");
                _Scratch1 = new Cvar("scratch1", "0");
                _Scratch2 = new Cvar("scratch2", "0");
                _Scratch3 = new Cvar("scratch3", "0");
                _Scratch4 = new Cvar("scratch4", "0");
                _SavedGameCfg = new Cvar("savedgamecfg", "0", true);
                _Saved1 = new Cvar("saved1", "0", true);
                _Saved2 = new Cvar("saved2", "0", true);
                _Saved3 = new Cvar("saved3", "0", true);
                _Saved4 = new Cvar("saved4", "0", true);
            }
        }
Esempio n. 25
0
        // IN_Init
        public static void Init()
        {
            if (_MouseFilter == null)
            {
                _MouseFilter = new Cvar("m_filter", "0");
            }

            _IsMouseActive = (MainForm.Instance.Mouse != null);
            if (_IsMouseActive)
            {
                _MouseButtons = MainForm.Instance.Mouse.NumberOfButtons;
            }
        }
Esempio n. 26
0
        // SCR_Init
        public static void Init()
        {
            if (_ViewSize == null)
            {
                _ViewSize = new Cvar("viewsize", "100", true);
                _Fov = new Cvar("fov", "90");	// 10 - 170
                _ConSpeed = new Cvar("scr_conspeed", "3000");
                _CenterTime = new Cvar("scr_centertime", "2");
                _ShowRam = new Cvar("showram", "1");
                _ShowTurtle = new Cvar("showturtle", "0");
                _ShowPause = new Cvar("showpause", "1");
                _PrintSpeed = new Cvar("scr_printspeed", "8");
                _glTripleBuffer = new Cvar("gl_triplebuffer", "1", true);
            }

            //
            // register our commands
            //
            Cmd.Add("screenshot", ScreenShot_f);
            Cmd.Add("sizeup", SizeUp_f);
            Cmd.Add("sizedown", SizeDown_f);

            _Ram = Drawer.PicFromWad("ram");
            _Net = Drawer.PicFromWad("net");
            _Turtle = Drawer.PicFromWad("turtle");

            if (Common.HasParam("-fullsbar"))
                FullSbarDraw = true;

            _IsInitialized = true;
        }
Esempio n. 27
0
        // Draw_Init
        public static void Init()
        {
            for (int i = 0; i < _MenuCachePics.Length; i++)
                _MenuCachePics[i] = new cachepic_t();

            if (_glNoBind == null)
            {
                _glNoBind = new Cvar("gl_nobind", "0");
                _glMaxSize = new Cvar("gl_max_size", "1024");
                _glPicMip = new Cvar("gl_picmip", "0");
            }

            // 3dfx can only handle 256 wide textures
            string renderer = GL.GetString(StringName.Renderer);
            if (renderer.Contains("3dfx") || renderer.Contains("Glide"))
                Cvar.Set("gl_max_size", "256");

            Cmd.Add("gl_texturemode", TextureMode_f);

            // load the console background and the charset
            // by hand, because we need to write the version
            // string into the background before turning
            // it into a texture
            int offset = Wad.GetLumpNameOffset("conchars");
            byte[] draw_chars = Wad.Data; // draw_chars
            for (int i = 0; i < 256 * 64; i++)
            {
                if (draw_chars[offset + i] == 0)
                    draw_chars[offset + i] = 255;	// proper transparent color
            }

            // now turn them into textures
            _CharTexture = LoadTexture("charset", 128, 128, new ByteArraySegment(draw_chars, offset), false, true);

            byte[] buf = Common.LoadFile("gfx/conback.lmp");
            if (buf == null)
                Sys.Error("Couldn't load gfx/conback.lmp");

            dqpicheader_t cbHeader = Sys.BytesToStructure<dqpicheader_t>(buf, 0);
            Wad.SwapPic(cbHeader);

            // hack the version number directly into the pic
            string ver = String.Format("(c# {0,7:F2}) {1,7:F2}", (float)QDef.CSQUAKE_VERSION, (float)QDef.VERSION);
            int offset2 = Marshal.SizeOf(typeof(dqpicheader_t)) + 320 * 186 + 320 - 11 - 8 * ver.Length;
            int y = ver.Length;
            for (int x = 0; x < y; x++)
                CharToConback(ver[x], new ByteArraySegment(buf, offset2 + (x << 3)), new ByteArraySegment(draw_chars, offset));

            _ConBack = new glpic_t();
            _ConBack.width = cbHeader.width;
            _ConBack.height = cbHeader.height;
            int ncdataIndex = Marshal.SizeOf(typeof(dqpicheader_t)); // cb->data;

            SetTextureFilters(TextureMinFilter.Nearest, TextureMagFilter.Nearest);

            _ConBack.texnum = LoadTexture("conback", _ConBack.width, _ConBack.height, new ByteArraySegment(buf, ncdataIndex), false, false);
            _ConBack.width = Scr.vid.width;
            _ConBack.height = Scr.vid.height;

            // save a texture slot for translated picture
            _TranslateTexture = _TextureExtensionNumber++;

            // save slots for scraps
            _ScrapTexNum = _TextureExtensionNumber;
            _TextureExtensionNumber += MAX_SCRAPS;

            //
            // get the other pics we need
            //
            _Disc = PicFromWad ("disc");
            _BackTile = PicFromWad ("backtile");
        }
Esempio n. 28
0
        // CL_Init
        public static void Init()
        {
            InitInput();
            InitTempEntities();

            if (_Name == null)
            {
                _Name = new Cvar("_cl_name", "player", true);
                _Color = new Cvar("_cl_color", "0", true);
                _ShowNet = new Cvar("cl_shownet", "0");	// can be 0, 1, or 2
                _NoLerp = new Cvar("cl_nolerp", "0");
                _LookSpring = new Cvar("lookspring", "0", true);
                _LookStrafe = new Cvar("lookstrafe", "0", true);
                _Sensitivity = new Cvar("sensitivity", "3", true);
                _MPitch = new Cvar("m_pitch", "0.022", true);
                _MYaw = new Cvar("m_yaw", "0.022", true);
                _MForward = new Cvar("m_forward", "1", true);
                _MSide = new Cvar("m_side", "0.8", true);
                _UpSpeed = new Cvar("cl_upspeed", "200");
                _ForwardSpeed = new Cvar("cl_forwardspeed", "200", true);
                _BackSpeed = new Cvar("cl_backspeed", "200", true);
                _SideSpeed = new Cvar("cl_sidespeed", "350");
                _MoveSpeedKey = new Cvar("cl_movespeedkey", "2.0");
                _YawSpeed = new Cvar("cl_yawspeed", "140");
                _PitchSpeed = new Cvar("cl_pitchspeed", "150");
                _AngleSpeedKey = new Cvar("cl_anglespeedkey", "1.5");
            }

            for (int i = 0; i < _EFrags.Length; i++)
                _EFrags[i] = new efrag_t();

            for (int i = 0; i < _Entities.Length; i++)
                _Entities[i] = new entity_t();

            for (int i = 0; i < _StaticEntities.Length; i++)
                _StaticEntities[i] = new entity_t();

            for (int i = 0; i < _DLights.Length; i++)
                _DLights[i] = new dlight_t();

            //
            // register our commands
            //
            Cmd.Add("entities", PrintEntities_f);
            Cmd.Add("disconnect", Disconnect_f);
            Cmd.Add("record", Record_f);
            Cmd.Add("stop", Stop_f);
            Cmd.Add("playdemo", PlayDemo_f);
            Cmd.Add("timedemo", TimeDemo_f);
        }
Esempio n. 29
0
        // Con_Init (void)
        public static void Init()
        {
            _DebugLog = (Common.CheckParm("-condebug") > 0);
            if (_DebugLog)
            {
                string path = Path.Combine(Common.GameDir, LOG_FILE_NAME);
                if (File.Exists(path))
                    File.Delete(path);

                _Log = new FileStream(path, FileMode.Create, FileAccess.Write, FileShare.Read);
            }

            _LineWidth = -1;
            CheckResize();

            Con.Print("Console initialized.\n");

            //
            // register our commands
            //
            if (_NotifyTime == null)
            {
                _NotifyTime = new Cvar("con_notifytime", "3");
            }

            Cmd.Add("toggleconsole", ToggleConsole_f);
            Cmd.Add("messagemode", MessageMode_f);
            Cmd.Add("messagemode2", MessageMode2_f);
            Cmd.Add("clear", Clear_f);

            _IsInitialized = true;
        }
Esempio n. 30
0
        /// <summary>
        /// SV_SpawnServer
        /// </summary>
        public static void SpawnServer(string server)
        {
            // let's not have any servers with no name
            if (String.IsNullOrEmpty(Net.HostName))
            {
                Cvar.Set("hostname", "UNNAMED");
            }

            Scr.CenterTimeOff = 0;

            Con.DPrint("SpawnServer: {0}\n", server);
            svs.changelevel_issued = false;             // now safe to issue another

            //
            // tell all connected clients that we are going to a new level
            //
            if (sv.active)
            {
                SendReconnect();
            }

            //
            // make cvars consistant
            //
            if (Host.IsCoop)
            {
                Cvar.Set("deathmatch", 0);
            }

            Host.CurrentSkill = (int)(Host.Skill + 0.5);
            if (Host.CurrentSkill < 0)
            {
                Host.CurrentSkill = 0;
            }

            if (Host.CurrentSkill > 3)
            {
                Host.CurrentSkill = 3;
            }

            Cvar.Set("skill", (float)Host.CurrentSkill);

            //
            // set up the new server
            //
            Host.ClearMemory();

            sv.Clear();

            sv.name = server;

            // load progs to get entity field count
            Progs.LoadProgs();

            // allocate server memory
            sv.max_edicts = QDef.MAX_EDICTS;

            sv.edicts = new edict_t[sv.max_edicts];
            for (int i = 0; i < sv.edicts.Length; i++)
            {
                sv.edicts[i] = new edict_t();
            }

            // leave slots at start for clients only
            sv.num_edicts = svs.maxclients + 1;
            edict_t ent;

            for (int i = 0; i < svs.maxclients; i++)
            {
                ent = EdictNum(i + 1);
                svs.clients[i].edict = ent;
            }

            sv.state      = server_state_t.Loading;
            sv.paused     = false;
            sv.time       = 1.0;
            sv.modelname  = String.Format("maps/{0}.bsp", server);
            sv.worldmodel = Mod.ForName(sv.modelname, false);
            if (sv.worldmodel == null)
            {
                Con.Print("Couldn't spawn server {0}\n", sv.modelname);
                sv.active = false;
                return;
            }
            sv.models[1] = sv.worldmodel;

            //
            // clear world interaction links
            //
            ClearWorld();

            sv.sound_precache[0] = String.Empty;
            sv.model_precache[0] = String.Empty;

            sv.model_precache[1] = sv.modelname;
            for (int i = 1; i < sv.worldmodel.numsubmodels; i++)
            {
                sv.model_precache[1 + i] = _LocalModels[i];
                sv.models[i + 1]         = Mod.ForName(_LocalModels[i], false);
            }

            //
            // load the rest of the entities
            //
            ent = EdictNum(0);
            ent.Clear();
            ent.v.model = Progs.StringOffset(sv.worldmodel.name);
            if (ent.v.model == -1)
            {
                ent.v.model = Progs.NewString(sv.worldmodel.name);
            }
            ent.v.modelindex = 1;               // world model
            ent.v.solid      = Solids.SOLID_BSP;
            ent.v.movetype   = Movetypes.MOVETYPE_PUSH;

            if (Host.IsCoop)
            {
                Progs.GlobalStruct.coop = 1; //coop.value;
            }
            else
            {
                Progs.GlobalStruct.deathmatch = Host.Deathmatch;
            }

            int offset = Progs.NewString(sv.name);

            Progs.GlobalStruct.mapname = offset;

            // serverflags are for cross level information (sigils)
            Progs.GlobalStruct.serverflags = svs.serverflags;

            Progs.LoadFromFile(sv.worldmodel.entities);

            sv.active = true;

            // all setup is completed, any further precache statements are errors
            sv.state = server_state_t.Active;

            // run two frames to allow everything to settle
            Host.FrameTime = 0.1;
            Physics();
            Physics();

            // create a baseline for more efficient communications
            CreateBaseline();

            // send serverinfo to all connected clients
            for (int i = 0; i < svs.maxclients; i++)
            {
                Host.HostClient = svs.clients[i];
                if (Host.HostClient.active)
                {
                    SendServerInfo(Host.HostClient);
                }
            }

            GC.Collect();
            Con.DPrint("Server spawned.\n");
        }