private void Form2_Shown(object sender, EventArgs e) { lblUrl.Text = "Downloading " + this.demoUrl; NFKHelper.GetOrCreateConfigFile(); try { // local file if (File.Exists(demoUrl)) { NFKHelper.DemoFile = demoUrl; waitGameLoading(); } // web link else { downloadFile(demoUrl, NFKHelper.GetOrCreateDemoDownloadDir()); } } catch (Exception ex) { Common.ShowError("Error", ex.Message + "\n" + demoUrl); userMode = false; this.Close(); } }
static void Main(string[] args) { // set allowed protocol to download from ServicePointManager.SecurityProtocol = SecurityProtocolType.Ssl3 | SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); if (args.Length == 0) { Application.Run(new Form1()); } else { var np = new NFKProcess(); // connect to server if (args[0].StartsWith("nfk://")) { var serverAddress = getServerAddress(args[0]); var spectator = !args[0].Contains("play"); if (!NFKHelper.SendPing(serverAddress)) { Common.ShowError("Connection timeout", "Could not connect to NFK server " + serverAddress); return; } if (!spectator) { // if play mode then just run a game and exit np.RunGame(serverAddress); return; } // run nfk np.Run(serverAddress, false); np.WatchForExit(); } // play demo else { var demoUrl = getDemoPath(args[0]); Application.Run(new Form2(demoUrl, np)); if (!String.IsNullOrEmpty(NFKHelper.DemoFile)) { // show video intro after the download form if (np.Intro != null && !np.Intro.CloseFlag && np.GameRunning) { Application.Run(np.Intro); } } } // this form is used to keep program running if (np.StubForm != null && !np.StubForm.CloseFlag && np.GameRunning) { Application.Run(np.StubForm); } } }
public void RunGame(string serverAddress) { var process = new Process(); process.StartInfo = new ProcessStartInfo() { FileName = NFKHelper.GameExePath, Arguments = NFKHelper.GetGameStartArgs(serverAddress), WorkingDirectory = NFKHelper.GetGameWorkingDir() }; process.Start(); }
private bool disposedValue = false; // To detect redundant calls protected virtual void Dispose(bool disposing) { if (!disposedValue) { if (disposing) { // dispose managed state (managed objects). } // TODO: free unmanaged resources (unmanaged objects) and override a finalizer below. // TODO: set large fields to null. try { if (kbh != null) { kbh.UnHookKeyboard(); } if (p != null) { p.Kill(); p.Close(); p = null; } if (Intro != null) { // close intro Intro.CloseFlag = true; } StubForm.CloseFlag = true; StubForm = null; // delete temp exe // FIXME: it may be not deleted if there are two instances of the program are running File.Delete(Path.Combine(NFKHelper.GetGameWorkingDir(), NFKHelper.GAME_EXE_TEMP)); } catch (Exception e) { } disposedValue = true; } }
public void Run(string fileName, bool isDemo = true) { if (isDemo && String.IsNullOrEmpty(NFKHelper.DemoFile)) { return; } p = new Process(); p.StartInfo = new ProcessStartInfo() { FileName = NFKHelper.GameExePathTemp, Arguments = isDemo ? NFKHelper.GetDemoStartArgs(fileName) : NFKHelper.GetSpectatorStartArgs(fileName), WorkingDirectory = NFKHelper.GetGameWorkingDir() }; p.Start(); sw.Start(); GameRunning = true; }
/// <summary> /// Wait for game loading and adjust progress bar /// </summary> private void waitGameLoading() { lblUrl.Text = "Loading demo file ..."; if (!NFKHelper.IsValidDemoFile(NFKHelper.DemoFile)) { NFKHelper.DemoFile = null; Common.ShowError("Error", "Invalid NFK demo file\n" + NFKHelper.DemoFile); userMode = false; this.Close(); } // run nfk np.Run(NFKHelper.DemoFile); np.WatchForExit(); var gameLoadTime = Properties.Settings.Default.GameLoadTime > 0 ? Properties.Settings.Default.GameLoadTime : NFKHelper.GAME_LOAD_TIME_DEFAULT; int interval = (int)(gameLoadTime - NFKHelper.INTRO_TIME) / (progressBar1.Maximum - progressBar1.Value); if (interval >= 0) { // run until prograss bar is filled for 100% for (; progressBar1.Value < progressBar1.Maximum; progressBar1.Value++) { // if abort button clicked if (String.IsNullOrEmpty(NFKHelper.DemoFile)) { break; } Thread.Sleep(interval); Application.DoEvents(); } } userMode = false; this.Close(); }
public FormIntro() { //#if !DEBUG this.TopMost = true; //#endif this.Location = new Point(0, 0); this.StartPosition = FormStartPosition.Manual; this.BackColor = Color.Black; this.ShowInTaskbar = false; // read options from the game config var lines = File.ReadAllLines(NFKHelper.GetOrCreateConfigFile()); foreach (var l in lines) { // extract window size if (l.Trim().StartsWith("r_mode")) { var parts = l.Trim().Split(' '); if (parts.Length == 3) { int.TryParse(parts[1], out w); int.TryParse(parts[2], out h); } } // switch to full screen if game is zoomwindowed if (l.Trim().StartsWith("zoomwindow")) { this.WindowState = FormWindowState.Maximized; } } InitializeComponent(); this.Width = w; this.Height = h + WINDOW_HEADER_HEIGHT; }
private void Form1_Load(object sender, EventArgs e) { wr = new Regedit(); // set version lvlVersion.Text = string.Format("v{0}", Common.ProgramVersion); // check new version in separate thread Task.Factory.StartNew(Common.CheckNewVersion); chkLinkHandler.Enabled = chkFileHandler.Enabled = false; linkConfig.Visible = false; // load settings if (File.Exists(Properties.Settings.Default.GameExePath) && Directory.Exists(NFKHelper.GetBasenfkPath())) { txtGamePath.Text = Properties.Settings.Default.GameExePath; chkLinkHandler.Enabled = chkFileHandler.Enabled = true; linkConfig.Visible = true; } else { // auto show file dialog if NFK.exe not exists TxtGamePath_MouseClick(null, null); } userMode = false; chkLinkHandler.Checked = wr.HasNfkLinkHandler() && wr.HasNfkdemoLinkHandler(); chkFileHandler.Checked = wr.HasFileHandler(); userMode = true; }
private void LinkConfig_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { var fileName = NFKHelper.GetOrCreateConfigFile(); var p = Process.Start("explorer.exe", "/select, \"" + fileName + "\""); }