protected void CheckMapVersion() { // FIXME: // not really needed, just don't call this // remove me when source map checksum stuff is figured out if (Demo.Engine == Demo.Engines.Source) { return; } // see if the game has a config file // FIXME: engine name - assuming goldsrc for now (see above) Game game = GameManager.Find(Demo); if (game == null || game.HasConfig == false) { // can't determine what maps are built-in for the game - can't handle map versions return; } // see if the map is built-in if (game.BuiltInMapExists(Demo.MapChecksum, Demo.MapName)) { // ok, suitable map found return; } // see if the map already exists in the game's "maps" folder String mapDestinationPath = gameFullPath + "\\maps"; String mapDestinationFileName = mapDestinationPath + "\\" + Demo.MapName + ".bsp"; if (File.Exists(mapDestinationFileName)) { if (HalfLifeMapChecksum.Calculate(mapDestinationFileName) == Demo.MapChecksum) { // ok, suitable map found return; } } // see if we have a map in the map pool matching the checksum String mapSourcePath = Config.ProgramDataPath + "\\maps\\goldsrc\\" + String.Format("{0}\\{1}", Demo.GameFolderName, Demo.MapChecksum); String mapSourceFileName = mapSourcePath + "\\" + Demo.MapName + ".bsp"; if (!File.Exists(mapSourceFileName)) { DownloadMapWindow downloadMapWindow = new DownloadMapWindow(Demo.MapName, Config.MapsUrl + "goldsrc/" + String.Format("{0}/{1}_{2}.zip", Demo.GameFolderName, Demo.MapChecksum, Demo.MapName), mapSourcePath + "\\" + Demo.MapName + ".zip"); downloadMapWindow.Owner = Owner; if (downloadMapWindow.ShowDialog() == false) { // can't find a suitable map if (Common.Message(Owner, String.Format("Can't find a version of \"{0}\" with a matching checksum \"{1}\" for this demo. Continue with playback anyway?", Demo.MapName, Demo.MapChecksum), null, MessageWindow.Flags.ContinueAbort) != MessageWindow.Result.Continue) { throw new AbortLaunchException(); } return; } } // first make sure the desination "maps" folder exists (create it if it doesn't) if (!Directory.Exists(mapDestinationPath)) { Directory.CreateDirectory(mapDestinationPath); } // if original map exists, rename to *.bak (if that exists, just delete it) String backupDestinationFileName = Path.ChangeExtension(mapDestinationFileName, ".bak"); if (File.Exists(mapDestinationFileName)) { if (File.Exists(backupDestinationFileName)) { File.Delete(backupDestinationFileName); } File.Move(mapDestinationFileName, backupDestinationFileName); FileOperationList.Add(new FileMoveOperation(backupDestinationFileName, mapDestinationFileName)); } // copy old version of map File.Copy(mapSourceFileName, mapDestinationFileName); FileOperationList.Add(new FileDeleteOperation(mapDestinationFileName)); // copy any wad files (if they don't already exist) DirectoryInfo directoryInfo = new DirectoryInfo(mapSourcePath); foreach (FileInfo fi in directoryInfo.GetFiles("*.wad", SearchOption.TopDirectoryOnly)) { // wad destination = demo destination String wadDestinationFileName = gameFullPath + "\\" + fi.Name; if (!File.Exists(wadDestinationFileName)) { File.Copy(fi.FullName, wadDestinationFileName); } } }
private void uiPlayButton_Click(object sender, RoutedEventArgs e) { Demo demo = uiDemoListView.GetSelectedDemo(); if (demo == null) { // shouldn't happen since the button should be disabled, but anyway... return; } // verify paths etc. launcher = LauncherFactory.CreateLauncher(demo); launcher.Owner = this; launcher.UseHlae = UseHlae(demo); launcher.Interface = (ILauncher)this; try { launcher.Verify(); } catch (Launcher.AbortLaunchException) { return; } catch (ApplicationException ex) { Common.Message(this, null, ex); return; } catch (Exception ex) { Common.Message(this, null, ex, MessageWindow.Flags.Error); return; } // make sure source and destination filenames don't match (dickhead insurance) if (String.Equals(demo.FileFullPath, launcher.GameFullPath + "\\" + Config.LaunchDemoFileName, StringComparison.CurrentCultureIgnoreCase)) { Common.Message(this, "Source and destination filenames are the same. Rename or move the source file and try again."); return; } // add the demo file path to the file operation manager FileOperationList.Add(new FileDeleteOperation(launcher.GameFullPath + "\\" + Config.LaunchDemoFileName)); // stop the user from being able to open a new demo now canOpenDemo = false; // write the demo ProgressWindow writeDemoProgressWindow = new ProgressWindow() { Owner = this }; writeDemoProgressWindow.Thread = demo.Write((IProgressWindow)writeDemoProgressWindow); writeDemoProgressWindow.ThreadParameter = launcher.GameFullPath + "\\" + Config.LaunchDemoFileName; if (writeDemoProgressWindow.ShowDialog() == false) { // user aborted writing FileOperationList.Execute(); canOpenDemo = true; return; } // go to tray MinimiseToTray(); // launch the game try { launcher.Run(); } catch (Exception ex) { RestoreFromTray(); FileOperationList.Execute(); canOpenDemo = true; Common.Message(this, "Error launching game.", ex, MessageWindow.Flags.Error); return; } SystemTrayIcon.Text = "Looking for " + (launcher.UseHlae ? "HLAE" : "game") + " process..."; // enable the tray context menu TrayContextMenuEnable(true); }
private void WriteConfig() { String configFileFullPath = gameFullPath; if (Demo.Engine == Demo.Engines.Source) { configFileFullPath += "\\cfg"; } configFileFullPath += "\\" + Config.LaunchConfigFileName; StreamWriter stream = File.CreateText(configFileFullPath); try { if (Demo.Engine == Demo.Engines.Source) { stream.WriteLine("alias +col_ff_slow \"demo_timescale 2\""); stream.WriteLine("alias -col_ff_slow \"demo_timescale 1\""); stream.WriteLine("alias +col_ff_fast \"demo_timescale 4\""); stream.WriteLine("alias -col_ff_fast \"demo_timescale 1\""); stream.WriteLine("alias +col_slowmo \"demo_timescale 0.25\""); stream.WriteLine("alias -col_slowmo \"demo_timescale 1\""); stream.WriteLine("alias col_pause demo_togglepause "); } else { stream.WriteLine("alias +col_ff_slow \"host_framerate 0.01; alias col_pause col_pause1\""); stream.WriteLine("alias -col_ff_slow \"host_framerate 0\""); stream.WriteLine("alias +col_ff_fast \"host_framerate 0.1; alias col_pause col_pause1\""); stream.WriteLine("alias -col_ff_fast \"host_framerate 0\""); stream.WriteLine("alias +col_slowmo \"host_framerate 0.001; alias col_pause col_pause1\""); stream.WriteLine("alias -col_slowmo \"host_framerate 0\""); stream.WriteLine("alias col_pause1 \"host_framerate 0.000000001; alias col_pause col_pause2\""); stream.WriteLine("alias col_pause2 \"host_framerate 0; alias col_pause col_pause1\""); stream.WriteLine("alias col_pause col_pause1\n"); stream.WriteLine("alias wait10 \"wait; wait; wait; wait; wait; wait; wait; wait; wait; wait\"\n"); stream.WriteLine("brightness 2"); stream.WriteLine("gamma 3"); stream.WriteLine("wait10"); if (Demo.Engine == Demo.Engines.HalfLifeSteam || ((HalfLifeDemo)Demo).ConvertNetworkProtocol()) { stream.WriteLine("sv_voicecodec voice_speex"); stream.WriteLine("sv_voicequality 5"); } stream.WriteLine("wait10"); stream.WriteLine("wait10"); stream.WriteLine("wait10"); stream.WriteLine("wait10"); stream.WriteLine("wait10"); } String playbackType; if (Demo.Engine != Demo.Engines.Source) { playbackType = (Config.Settings.PlaybackType == ProgramSettings.Playback.Playdemo ? "playdemo" : "viewdemo"); } else { playbackType = "playdemo"; } stream.WriteLine("{0} {1}", playbackType, Config.LaunchDemoFileName); if (Demo.Engine != Demo.Engines.Source) { stream.WriteLine("wait10"); stream.WriteLine("slot1"); // TODO: remove this, figure out why the spec menu it's initalised correctly with old converted HLTV demos. if (Demo.Perspective == Demo.Perspectives.Hltv) { stream.WriteLine("wait10"); stream.WriteLine("spec_menu 0"); stream.WriteLine("wait10"); stream.WriteLine("spec_mode 4"); stream.WriteLine("wait10"); stream.WriteLine("wait10"); stream.WriteLine("wait10"); stream.WriteLine("spec_menu 1"); stream.WriteLine("wait10"); stream.WriteLine("+attack"); } } stream.WriteLine("echo \"\""); stream.WriteLine("echo \"==========================\""); stream.WriteLine("echo \"{0}\"", Config.ProgramName); stream.WriteLine("echo \"==========================\""); stream.WriteLine("echo \"Aliases:\""); stream.WriteLine("echo \" +col_ff_slow (Fast Forward)\""); stream.WriteLine("echo \" +col_ff_fast (Faster Fast Forward)\""); stream.WriteLine("echo \" +col_slowmo (Slow Motion)\""); stream.WriteLine("echo \" col_pause (Toggle Pause)\""); stream.WriteLine("echo \"\""); stream.WriteLine("echo \"Playing \'{0}\'...\"", Demo.Name); stream.WriteLine("echo \" Duration: {0}\"", Common.DurationString(Demo.DurationInSeconds)); stream.WriteLine("echo \" Recorded by: {0}\"", Demo.RecorderName); stream.WriteLine("echo \"\""); } finally { stream.Close(); FileOperationList.Add(new FileDeleteOperation(configFileFullPath)); } }