// SCR_ScreenShot_f static void ScreenShot_f() { // // find a file name to save it to // string path = null; int i; for (i = 0; i <= 999; i++) { path = Path.Combine(Common.GameDir, String.Format("quake{0:D3}.tga", i)); if (Sys.GetFileTime(path) == DateTime.MinValue) { break; // file doesn't exist } } if (i == 100) { Con.Print("SCR_ScreenShot_f: Couldn't create a file\n"); return; } FileStream fs = Sys.FileOpenWrite(path, true); if (fs == null) { Con.Print("SCR_ScreenShot_f: Couldn't create a file\n"); return; } using (BinaryWriter writer = new BinaryWriter(fs)) { // Write tga header (18 bytes) writer.Write((ushort)0); writer.Write((byte)2); //buffer[2] = 2; uncompressed type writer.Write((byte)0); writer.Write((uint)0); writer.Write((uint)0); writer.Write((byte)(glWidth & 0xff)); writer.Write((byte)(glWidth >> 8)); writer.Write((byte)(glHeight & 0xff)); writer.Write((byte)(glHeight >> 8)); writer.Write((byte)24); // pixel size writer.Write((ushort)0); byte[] buffer = new byte[glWidth * glHeight * 3]; GL.ReadPixels(glX, glY, glWidth, glHeight, PixelFormat.Rgb, PixelType.UnsignedByte, buffer); // swap 012 to 102 int c = glWidth * glHeight * 3; for (i = 0; i < c; i += 3) { byte temp = buffer[i + 0]; buffer[i + 0] = buffer[i + 1]; buffer[i + 1] = temp; } writer.Write(buffer, 0, buffer.Length); } Con.Print("Wrote {0}\n", Path.GetFileName(path)); }
static void InitVCR(quakeparms_t parms) { if (Common.HasParam("-playback")) { if (Common.Argc != 2) { Sys.Error("No other parameters allowed with -playback\n"); } Stream file = Sys.FileOpenRead("quake.vcr"); if (file == null) { Sys.Error("playback file not found\n"); } _VcrReader = new BinaryReader(file, Encoding.ASCII); int signature = _VcrReader.ReadInt32(); //Sys_FileRead(vcrFile, &i, sizeof(int)); if (signature != Host.VCR_SIGNATURE) { Sys.Error("Invalid signature in vcr file\n"); } int argc = _VcrReader.ReadInt32(); // Sys_FileRead(vcrFile, &com_argc, sizeof(int)); string[] argv = new string[argc + 1]; argv[0] = parms.argv[0]; for (int i = 1; i < argv.Length; i++) { argv[i] = Sys.ReadString(_VcrReader); } Common.Args = argv; parms.argv = argv; } int n = Common.CheckParm("-record"); if (n != 0) { Stream file = Sys.FileOpenWrite("quake.vcr"); // vcrFile = Sys_FileOpenWrite("quake.vcr"); _VcrWriter = new BinaryWriter(file, Encoding.ASCII); _VcrWriter.Write(VCR_SIGNATURE); // Sys_FileWrite(vcrFile, &i, sizeof(int)); _VcrWriter.Write(Common.Argc - 1); for (int i = 1; i < Common.Argc; i++) { if (i == n) { Sys.WriteString(_VcrWriter, "-playback"); continue; } Sys.WriteString(_VcrWriter, Common.Argv(i)); } } }
/// <summary> /// Host_WriteConfiguration /// Writes key bindings and archived cvars to config.cfg /// </summary> static void WriteConfiguration() { // dedicated servers initialize the host but don't parse and set the // config.cfg cvars if (_IsInitialized & !Host.IsDedicated) { string path = Path.Combine(Common.GameDir, "config.cfg"); using (FileStream fs = Sys.FileOpenWrite(path, true)) { if (fs != null) { Key.WriteBindings(fs); Cvar.WriteVariables(fs); } } } }
/// <summary> /// CL_Record_f /// record <demoname> <map> [cd track] /// </summary> static void Record_f() { if (Cmd.Source != cmd_source_t.src_command) { return; } int c = Cmd.Argc; if (c != 2 && c != 3 && c != 4) { Con.Print("record <demoname> [<map> [cd track]]\n"); return; } if (Cmd.Argv(1).Contains("..")) { Con.Print("Relative pathnames are not allowed.\n"); return; } if (c == 2 && cls.state == cactive_t.ca_connected) { Con.Print("Can not record - already connected to server\nClient demo recording must be started before connecting\n"); return; } // write the forced cd track number, or -1 int track; if (c == 4) { track = Common.atoi(Cmd.Argv(3)); Con.Print("Forcing CD track to {0}\n", track); } else { track = -1; } string name = Path.Combine(Common.GameDir, Cmd.Argv(1)); // // start the map up // if (c > 2) { Cmd.ExecuteString(String.Format("map {0}", Cmd.Argv(2)), cmd_source_t.src_command); } // // open the demo file // name = Path.ChangeExtension(name, ".dem"); Con.Print("recording to {0}.\n", name); FileStream fs = Sys.FileOpenWrite(name, true); if (fs == null) { Con.Print("ERROR: couldn't open.\n"); return; } BinaryWriter writer = new BinaryWriter(fs, Encoding.ASCII); cls.demofile = new DisposableWrapper <BinaryWriter>(writer, true); cls.forcetrack = track; byte[] tmp = Encoding.ASCII.GetBytes(cls.forcetrack.ToString()); writer.Write(tmp); writer.Write('\n'); cls.demorecording = true; }
static int _StripCount; // stripcount /// <summary> /// GL_MakeAliasModelDisplayLists /// </summary> public static void MakeAliasModelDisplayLists(model_t m, aliashdr_t hdr) { _AliasModel = m; _AliasHdr = hdr; // // look for a cached version // string path = Path.ChangeExtension("glquake/" + Path.GetFileNameWithoutExtension(m.name), ".ms2"); DisposableWrapper <BinaryReader> file; Common.FOpenFile(path, out file); if (file != null) { using (file) { BinaryReader reader = file.Object; _NumCommands = reader.ReadInt32(); _NumOrder = reader.ReadInt32(); for (int i = 0; i < _NumCommands; i++) { _Commands[i] = reader.ReadInt32(); } for (int i = 0; i < _NumOrder; i++) { _VertexOrder[i] = reader.ReadInt32(); } } } else { // // build it from scratch // Con.Print("meshing {0}...\n", m.name); BuildTris(); // trifans or lists // // save out the cached version // string fullpath = Path.Combine(Common.GameDir, path); Stream fs = Sys.FileOpenWrite(fullpath, true); if (fs != null) { using (BinaryWriter writer = new BinaryWriter(fs, Encoding.ASCII)) { writer.Write(_NumCommands); writer.Write(_NumOrder); for (int i = 0; i < _NumCommands; i++) { writer.Write(_Commands[i]); } for (int i = 0; i < _NumOrder; i++) { writer.Write(_VertexOrder[i]); } } } } // // save the data out // _AliasHdr.poseverts = _NumOrder; int[] cmds = new int[_NumCommands]; //Hunk_Alloc (numcommands * 4); _AliasHdr.commands = cmds; // in bytes??? // (byte*)cmds - (byte*)paliashdr; Buffer.BlockCopy(_Commands, 0, cmds, 0, _NumCommands * 4); //memcpy (cmds, commands, numcommands * 4); trivertx_t[][] poseverts = Mod.PoseVerts; trivertx_t[] verts = new trivertx_t[_AliasHdr.numposes * _AliasHdr.poseverts]; // Hunk_Alloc (paliashdr->numposes * paliashdr->poseverts * sizeof(trivertx_t) ); _AliasHdr.posedata = verts; // (byte*)verts - (byte*)paliashdr; int offset = 0; for (int i = 0; i < _AliasHdr.numposes; i++) { for (int j = 0; j < _NumOrder; j++) { verts[offset++] = poseverts[i][_VertexOrder[j]]; // *verts++ = poseverts[i][vertexorder[j]]; } } }
/// <summary> /// Host_Savegame_f /// </summary> static void Savegame_f() { if (Cmd.Source != cmd_source_t.src_command) { return; } if (!Server.sv.active) { Con.Print("Not playing a local game.\n"); return; } if (Client.cl.intermission != 0) { Con.Print("Can't save in intermission.\n"); return; } if (Server.svs.maxclients != 1) { Con.Print("Can't save multiplayer games.\n"); return; } if (Cmd.Argc != 2) { Con.Print("save <savename> : save a game\n"); return; } if (Cmd.Argv(1).Contains("..")) { Con.Print("Relative pathnames are not allowed.\n"); return; } for (int i = 0; i < Server.svs.maxclients; i++) { if (Server.svs.clients[i].active && (Server.svs.clients[i].edict.v.health <= 0)) { Con.Print("Can't savegame with a dead player\n"); return; } } string name = Path.ChangeExtension(Path.Combine(Common.GameDir, Cmd.Argv(1)), ".sav"); Con.Print("Saving game to {0}...\n", name); FileStream fs = Sys.FileOpenWrite(name, true); if (fs == null) { Con.Print("ERROR: couldn't open.\n"); return; } using (StreamWriter writer = new StreamWriter(fs, Encoding.ASCII)) { writer.WriteLine(SAVEGAME_VERSION); writer.WriteLine(SavegameComment()); for (int i = 0; i < Server.NUM_SPAWN_PARMS; i++) { writer.WriteLine(Server.svs.clients[0].spawn_parms[i].ToString("F6", CultureInfo.InvariantCulture.NumberFormat)); } writer.WriteLine(Host.CurrentSkill); writer.WriteLine(Server.sv.name); writer.WriteLine(Server.sv.time.ToString("F6", CultureInfo.InvariantCulture.NumberFormat)); // write the light styles for (int i = 0; i < QDef.MAX_LIGHTSTYLES; i++) { if (!String.IsNullOrEmpty(Server.sv.lightstyles[i])) { writer.WriteLine(Server.sv.lightstyles[i]); } else { writer.WriteLine("m"); } } Progs.WriteGlobals(writer); for (int i = 0; i < Server.sv.num_edicts; i++) { Progs.WriteEdict(writer, Server.EdictNum(i)); writer.Flush(); } } Con.Print("done.\n"); }