Ejemplo n.º 1
0
        public static void SV_CopySaveGame(String src, String dst)
        {
            Com.DPrintf("SV_CopySaveGame(" + src + "," + dst + ")\\n");
            SV_WipeSavegame(dst);
            var name  = FS.Gamedir() + "/save/" + src + "/server.ssv";
            var name2 = FS.Gamedir() + "/save/" + dst + "/server.ssv";

            FS.CreatePath(name2);
            CopyFile(name, name2);
            name  = FS.Gamedir() + "/save/" + src + "/game.ssv";
            name2 = FS.Gamedir() + "/save/" + dst + "/game.ssv";
            CopyFile(name, name2);
            var name1 = FS.Gamedir() + "/save/" + src + "/";

            name = FS.Gamedir() + "/save/" + src + "/*.sav";
            var found = CoreSys.FindFirst(name);

            while (found != null)
            {
                name  = name1 + found;
                name2 = FS.Gamedir() + "/save/" + dst + "/" + found;
                CopyFile(name, name2);
                name  = name.Substring(0, name.Length - 3) + "sv2";
                name2 = name2.Substring(0, name2.Length - 3) + "sv2";
                CopyFile(name, name2);
                found = CoreSys.FindNext();
            }

            CoreSys.FindClose();
        }
Ejemplo n.º 2
0
        /*
         * ================
         * SV_CopySaveGame
         * ================
         */
        public static void SV_CopySaveGame(string src, string dst)
        {
            Com.DPrintf("SV_CopySaveGame(" + src + "," + dst + ")\n");

            SV_CCMDS.SV_WipeSavegame(dst);

            // copy the savegame over
            var name  = FS.Gamedir() + "/save/" + src + "/server.ssv";
            var name2 = FS.Gamedir() + "/save/" + dst + "/server.ssv";

            FS.CreatePath(name2);
            SV_CCMDS.CopyFile(name, name2);

            name  = FS.Gamedir() + "/save/" + src + "/game.ssv";
            name2 = FS.Gamedir() + "/save/" + dst + "/game.ssv";
            SV_CCMDS.CopyFile(name, name2);

            var name1 = FS.Gamedir() + "/save/" + src + "/";

            name = FS.Gamedir() + "/save/" + src + "/*.sav";

            var found = Sys.FindFirst(name, 0, 0);

            while (found != null)
            {
                name  = name1 + Path.GetFileName(found);
                name2 = FS.Gamedir() + "/save/" + dst + "/" + Path.GetFileName(found);

                SV_CCMDS.CopyFile(name, name2);

                // change sav to sv2
                name  = name[..^ 3] + "sv2";
Ejemplo n.º 3
0
        public static void SV_GameMap_f( )
        {
            if (Cmd.Argc() != 2)
            {
                Com.Printf("USAGE: gamemap <map>\\n");
                return;
            }

            Com.DPrintf("SV_GameMap(" + Cmd.Argv(1) + ")\\n");
            FS.CreatePath(FS.Gamedir() + "/save/current/");
            var map = Cmd.Argv(1);

            if (map[0] == '*')
            {
                SV_WipeSavegame("current");
            }
            else
            {
                if (SV_INIT.sv.state == Defines.ss_game)
                {
                    client_t  cl;
                    Boolean[] savedInuse = new Boolean[( Int32 )SV_MAIN.maxclients.value];
                    for (var i = 0; i < SV_MAIN.maxclients.value; i++)
                    {
                        cl             = SV_INIT.svs.clients[i];
                        savedInuse[i]  = cl.edict.inuse;
                        cl.edict.inuse = false;
                    }

                    SV_WriteLevelFile();
                    for (var i = 0; i < SV_MAIN.maxclients.value; i++)
                    {
                        cl             = SV_INIT.svs.clients[i];
                        cl.edict.inuse = savedInuse[i];
                    }

                    savedInuse = null;
                }
            }

            SV_INIT.SV_Map(false, Cmd.Argv(1), false);
            SV_INIT.svs.mapcmd = Cmd.Argv(1);
            if (0 == Globals.dedicated.value)
            {
                SV_WriteServerFile(true);
                SV_CopySaveGame("current", "save0");
            }
        }
Ejemplo n.º 4
0
        //	/*
        //	==============================================================================
        //
        //							SCREEN SHOTS
        //
        //	==============================================================================
        //	*/
        //
        //	typedef struct _TargaHeader {
        //		unsigned char   id_length, colormap_type, image_type;
        //		unsigned short	colormap_index, colormap_length;
        //		unsigned char	colormap_size;
        //		unsigned short	x_origin, y_origin, width, height;
        //		unsigned char	pixel_size, attributes;
        //	} TargaHeader;

        /**
         * GL_ScreenShot_f
         */
        public override void GL_ScreenShot_f()
        {
            StringBuilder sb = new(FS.Gamedir() + "/scrshot/screenshot00.tga");

            FS.CreatePath(sb.ToString());
            var file = sb.ToString();

            // find a valid file name
            var i      = 0;
            var offset = sb.Length - 6;

            while (File.Exists(file) && i++ < 100)
            {
                sb[offset]     = (char)(i / 10 + '0');
                sb[offset + 1] = (char)(i % 10 + '0');
                file           = sb.ToString();
            }

            if (i == 100)
            {
                VID.Printf(Defines.PRINT_ALL, "Clean up your screenshots\n");

                return;
            }

            try
            {
                Stream       @out  = File.OpenWrite(file);
                BinaryWriter image = new(@out);

                // write the TGA header
                image.Write((byte)0);
                image.Write((byte)0);
                image.Write((byte)2);                     // uncompressed type
                image.Write(new byte[9]);
                image.Write((short)Base.vid.getWidth());  // vid.getWidth()
                image.Write((short)Base.vid.getHeight()); // vid.getHeight()
                image.Write((byte)24);                    // pixel size
                image.Write(new byte[1]);

                var rgb = new byte[Base.vid.getWidth() * Base.vid.getHeight() * 3];

                // change pixel alignment for reading
                if (Base.vid.getWidth() % 4 != 0)
                {
                    this.gl.glPixelStorei(OpenGL.GL_PACK_ALIGNMENT, 1);
                }

                // OpenGL 1.2+ supports the GL_BGR color format
                // check the GL_VERSION to use the TARGA BGR order if possible
                // e.g.: 1.5.2 NVIDIA 66.29
                if (this.gl_config.getOpenGLVersion() >= 1.2f)
                {
                    // read the BGR values into the image buffer
                    this.gl.glReadPixels(0, 0, Base.vid.getWidth(), Base.vid.getHeight(), OpenGL.GL_BGR, OpenGL.GL_UNSIGNED_BYTE, rgb);
                }
                else
                {
                    // read the RGB values into the image buffer
                    this.gl.glReadPixels(0, 0, Base.vid.getWidth(), Base.vid.getHeight(), OpenGL.GL_RGB, OpenGL.GL_UNSIGNED_BYTE, rgb);

                    // flip RGB to BGR
                    for (i = 0; i < rgb.Length; i += 3)
                    {
                        image.Write(rgb[i + 2]);
                        image.Write(rgb[i + 1]);
                        image.Write(rgb[i + 0]);
                    }
                }

                // reset to default alignment
                this.gl.glPixelStorei(OpenGL.GL_PACK_ALIGNMENT, 4);

                // close the file channel
                @out.Close();
            }
            catch (Exception e)
            {
                VID.Printf(Defines.PRINT_ALL, e.Message + '\n');
            }

            VID.Printf(Defines.PRINT_ALL, "Wrote " + file + '\n');
        }
Ejemplo n.º 5
0
        public static void SV_ServerRecord_f( )
        {
            String name;

            Byte[]    buf_data = new Byte[32768];
            sizebuf_t buf      = new sizebuf_t();
            Int32     len;
            Int32     i;

            if (Cmd.Argc() != 2)
            {
                Com.Printf("serverrecord <demoname>\\n");
                return;
            }

            if (SV_INIT.svs.demofile != null)
            {
                Com.Printf("Already recording.\\n");
                return;
            }

            if (SV_INIT.sv.state != Defines.ss_game)
            {
                Com.Printf("You must be in a level to record.\\n");
                return;
            }

            name = FS.Gamedir() + "/demos/" + Cmd.Argv(1) + ".dm2";
            Com.Printf("recording to " + name + ".\\n");
            FS.CreatePath(name);
            try
            {
                SV_INIT.svs.demofile = new QuakeFile(name, FileAccess.ReadWrite);
            }
            catch (Exception e)
            {
                Com.Printf("ERROR: couldn't open.\\n");
                return;
            }

            SZ.Init(SV_INIT.svs.demo_multicast, SV_INIT.svs.demo_multicast_buf, SV_INIT.svs.demo_multicast_buf.Length);
            SZ.Init(buf, buf_data, buf_data.Length);
            MSG.WriteByte(buf, Defines.svc_serverdata);
            MSG.WriteLong(buf, Defines.PROTOCOL_VERSION);
            MSG.WriteLong(buf, SV_INIT.svs.spawncount);
            MSG.WriteByte(buf, 2);
            MSG.WriteString(buf, Cvar.VariableString("gamedir"));
            MSG.WriteShort(buf, -1);
            MSG.WriteString(buf, SV_INIT.sv.configstrings[Defines.CS_NAME]);
            for (i = 0; i < Defines.MAX_CONFIGSTRINGS; i++)
            {
                if (SV_INIT.sv.configstrings[i].Length == 0)
                {
                    MSG.WriteByte(buf, Defines.svc_configstring);
                    MSG.WriteShort(buf, i);
                    MSG.WriteString(buf, SV_INIT.sv.configstrings[i]);
                }
            }

            Com.DPrintf("signon message length: " + buf.cursize + "\\n");
            len = EndianHandler.SwapInt(buf.cursize);
            try
            {
                SV_INIT.svs.demofile.Write(len);
                SV_INIT.svs.demofile.Write(buf.data, 0, buf.cursize);
            }
            catch (IOException e1)
            {
                e1.PrintStackTrace();
            }
        }
Ejemplo n.º 6
0
        public static void ParseDownload( )
        {
            Int32 size    = MSG.ReadShort(Globals.net_message);
            var   percent = MSG.ReadByte(Globals.net_message);

            if (size == -1)
            {
                Com.Printf("Server does not have this file.\\n");
                if (Globals.cls.download != null)
                {
                    try
                    {
                        Globals.cls.download.Close();
                    }
                    catch (IOException e)
                    {
                    }

                    Globals.cls.download = null;
                }

                CL.RequestNextDownload();
                return;
            }

            if (Globals.cls.download == null)
            {
                var name = DownloadFileName(Globals.cls.downloadtempname).ToLower();
                FS.CreatePath(name);
                Globals.cls.download = new QuakeFile(name, FileAccess.ReadWrite);
                if (Globals.cls.download == null)
                {
                    Globals.net_message.readcount += size;
                    Com.Printf("Failed to open " + Globals.cls.downloadtempname + "\\n");
                    CL.RequestNextDownload();
                    return;
                }
            }

            try
            {
                Globals.cls.download.Write(Globals.net_message.data, Globals.net_message.readcount, size);
            }
            catch (Exception e)
            {
            }

            Globals.net_message.readcount += size;
            if (percent != 100)
            {
                Globals.cls.downloadpercent = percent;
                MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd);
                SZ.Print(Globals.cls.netchan.message, "nextdl");
            }
            else
            {
                try
                {
                    Globals.cls.download.Close();
                }
                catch (IOException e)
                {
                }

                var oldn = DownloadFileName(Globals.cls.downloadtempname);
                var newn = DownloadFileName(Globals.cls.downloadname);
                var r    = Lib.Rename(oldn, newn);
                if (r != 0)
                {
                    Com.Printf("failed to rename.\\n");
                }
                Globals.cls.download        = null;
                Globals.cls.downloadpercent = 0;
                CL.RequestNextDownload();
            }
        }
Ejemplo n.º 7
0
        /*
         * ===================== CL_ParseDownload
         *
         * A download message has been received from the server
         * =====================
         */
        public static void ParseDownload()
        {
            // read the data
            int size    = MSG.ReadShort(Globals.net_message);
            var percent = MSG.ReadByte(Globals.net_message);

            if (size == -1)
            {
                Com.Printf("Server does not have this file.\n");

                if (Globals.cls.download != null)
                {
                    // if here, we tried to resume a file but the server said no
                    try
                    {
                        Globals.cls.download.Close();
                    }
                    catch (IOException)
                    {
                    }

                    Globals.cls.download = null;
                }

                Cl.RequestNextDownload();

                return;
            }

            // open the file if not opened yet
            if (Globals.cls.download == null)
            {
                var name = CL_parse.DownloadFileName(Globals.cls.downloadtempname).ToLower();
                FS.CreatePath(name);
                Globals.cls.download = File.OpenWrite(name);

                if (Globals.cls.download == null)
                {
                    Globals.net_message.readcount += size;
                    Com.Printf("Failed to open " + Globals.cls.downloadtempname + "\n");
                    Cl.RequestNextDownload();

                    return;
                }
            }

            try
            {
                Globals.cls.download.Write(Globals.net_message.data, Globals.net_message.readcount, size);
            }
            catch (Exception)
            {
            }

            Globals.net_message.readcount += size;

            if (percent != 100)
            {
                // request next block
                //	   change display routines by zoid
                Globals.cls.downloadpercent = percent;
                MSG.WriteByte(Globals.cls.netchan.message, Defines.clc_stringcmd);
                SZ.Print(Globals.cls.netchan.message, "nextdl");
            }
            else
            {
                try
                {
                    Globals.cls.download.Close();
                }
                catch (IOException)
                {
                }

                // rename the temp file to it's final name
                var oldn = CL_parse.DownloadFileName(Globals.cls.downloadtempname);
                var newn = CL_parse.DownloadFileName(Globals.cls.downloadname);
                File.Move(oldn, newn);
                Globals.cls.download        = null;
                Globals.cls.downloadpercent = 0;

                // get another file if needed
                Cl.RequestNextDownload();
            }
        }
Ejemplo n.º 8
0
        public override void GL_ScreenShot_f()
        {
            StringBuffer sb = new StringBuffer(FS.Gamedir() + "/scrshot/jake00.tga");

            FS.CreatePath(sb.ToString());
            FileInfo file   = new FileInfo(sb.ToString());
            int      i      = 0;
            int      offset = sb.Length - 6;

            while (file.Exists && i++ < 100)
            {
                sb[offset]     = (char)((i / 10) + '0');
                sb[offset + 1] = (char)((i % 10) + '0');
                file           = new FileInfo(sb.ToString());
            }

            if (i == 100)
            {
                VID.Printf(Defines.PRINT_ALL, "Clean up your screenshots\\n");
                return;
            }

            try
            {
                FileStream out_renamed = File.OpenWrite(file.FullName);
                int        fileLength  = TGA_HEADER_SIZE + vid.GetWidth() * vid.GetHeight() * 3;
                out_renamed.SetLength(fileLength);
                ByteBuffer image = ByteBuffer.Allocate((int)file.Length);
                image.Put(0, (byte)0).Put(1, (byte)0);
                image.Put(2, (byte)2);
                image.Put(12, (byte)(vid.GetWidth() & 0xFF));
                image.Put(13, (byte)(vid.GetWidth() >> 8));
                image.Put(14, (byte)(vid.GetHeight() & 0xFF));
                image.Put(15, (byte)(vid.GetHeight() >> 8));
                image.Put(16, (byte)24);
                image.Position = TGA_HEADER_SIZE;
                ByteBuffer rgb = image.Slice();
                if (vid.GetWidth() % 4 != 0)
                {
                    GL.PixelStore(PixelStoreParameter.PackAlignment, 1);
                }

                if (gl_config.GetOpenGLVersion() >= 1.2F)
                {
                    Byte[] pixels = new Byte[vid.GetWidth() * vid.GetHeight() * 3];
                    GL.ReadPixels(0, 0, vid.GetWidth(), vid.GetHeight(), PixelFormat.Bgr, PixelType.UnsignedByte, pixels);
                    rgb = ByteBuffer.Allocate(pixels.Length);
                    rgb.Put(pixels);
                }
                else
                {
                    Byte[] pixels = new Byte[vid.GetWidth() * vid.GetHeight() * 3];
                    GL.ReadPixels(0, 0, vid.GetWidth(), vid.GetHeight(), PixelFormat.Rgb, PixelType.UnsignedByte, pixels);
                    rgb = ByteBuffer.Allocate(pixels.Length);
                    rgb.Put(pixels);
                    byte tmp;
                    for (i = TGA_HEADER_SIZE; i < fileLength; i += 3)
                    {
                        tmp = image.Get(i);
                        image.Put(i, image.Get(i + 2));
                        image.Put(i + 2, tmp);
                    }
                }

                GL.PixelStore(PixelStoreParameter.PackAlignment, 4);
                out_renamed.Write(image.Array, 0, image.Array.Length);
                out_renamed.Dispose();
            }
            catch (IOException e)
            {
                VID.Printf(Defines.PRINT_ALL, e.ToString() + '\\');
            }

            VID.Printf(Defines.PRINT_ALL, "Wrote " + file + '\\');
        }
Ejemplo n.º 9
0
            public override void Execute( )
            {
                Int32      l, x;
                Int32      line;
                FileStream f;

                Byte[] buffer = new Byte[1024];
                String name;

                if (Cmd.Argc() != 2)
                {
                    Com.Printf("usage: condump <filename>\\n");
                    return;
                }

                name = FS.Gamedir() + "/" + Cmd.Argv(1) + ".txt";
                Com.Printf("Dumped console text to " + name + ".\\n");
                FS.CreatePath(name);
                f = Lib.Fopen(name, FileMode.OpenOrCreate, FileAccess.ReadWrite);
                if (f == null)
                {
                    Com.Printf("ERROR: couldn't open.\\n");
                    return;
                }

                for (l = con.current - con.totallines + 1; l <= con.current; l++)
                {
                    line = (l % con.totallines) * con.linewidth;
                    for (x = 0; x < con.linewidth; x++)
                    {
                        if (con.text[line + x] != ' ')
                        {
                            break;
                        }
                    }
                    if (x != con.linewidth)
                    {
                        break;
                    }
                }

                buffer[con.linewidth] = 0;
                for ( ; l <= con.current; l++)
                {
                    line = (l % con.totallines) * con.linewidth;
                    System.Array.Copy(con.text, line, buffer, 0, con.linewidth);
                    for (x = con.linewidth - 1; x >= 0; x--)
                    {
                        if (buffer[x] == ' ')
                        {
                            buffer[x] = 0;
                        }
                        else
                        {
                            break;
                        }
                    }

                    for (x = 0; buffer[x] != 0; x++)
                    {
                        buffer[x] &= 0x7f;
                    }
                    buffer[x] = ( Byte )'\\';
                    try
                    {
                        f.Write(buffer, 0, x + 1);
                    }
                    catch (IOException e)
                    {
                    }
                }

                Lib.Fclose(f);
            }