static void Main(string[] args) { //enforces a nice cleanup //just hitting X or Ctrl+C normally won't actually dispose the using() below /* * ExitHandler.Init(ctrlType => * { * Console.WriteLine("\nCleaning up and exiting..."); * return true; //cancel event * }); */ /////////////////////////////////////////////////////////////////// /* * Console.WriteLine("Current OSD entries:"); * var osdEntries = OSD.GetOSDEntries(); * foreach (var osd in osdEntries) * { * Console.ForegroundColor = ConsoleColor.Cyan; * Console.WriteLine(osd.Owner); * Console.ResetColor(); * Console.WriteLine("{0}\n", osd.Text); * } */ /////////////////////////////////////////////////////////////////// /* * Console.WriteLine("Current app entries with GPU contexts:"); * var appEntries = OSD.GetAppEntries().Where(x => (x.Flags & AppFlags.MASK) != AppFlags.None).ToArray(); * foreach (var app in appEntries) * { * Console.ForegroundColor = ConsoleColor.Magenta; * Console.WriteLine("{0}:{1}", app.ProcessId, app.Name); * Console.ResetColor(); * Console.WriteLine("{0}, {1}FPS", app.Flags, app.InstantaneousFrames); * } * Console.WriteLine(); */ /////////////////////////////////////////////////////////////////// while (true) { try { Process[] processes = Process.GetProcessesByName("ASN_App_PcDx9_Final"); processHandle = NativeMethods.OpenProcess(16, false, processes[0].Id); Console.WriteLine("Connected to ASRT!"); osd = new OSD("ASRT_Speedo"); { Console.WriteLine("Connected to Rivatuner!"); Console.WriteLine("The speed stats will now be displayed."); UpdateOverlay(osd); while (true) { System.Threading.Thread.Sleep(10); oldSpeed = speed; speed = NewSpeed(0); if (!validHandle) { speedGraph.dataPoints = new float[speedGraph.dataPoints.Length]; accelGraph.dataPoints = new float[accelGraph.dataPoints.Length]; throw new System.IO.IOException("Invalid process handle."); } else if (!speedAvailable) { osd.Update(""); speedGraph.dataPoints = new float[speedGraph.dataPoints.Length]; accelGraph.dataPoints = new float[accelGraph.dataPoints.Length]; } else if (speed != oldSpeed) { UpdateOverlay(osd); } } } } catch (Exception e) { if (e is IndexOutOfRangeException) { Console.WriteLine("Failed to connect to ASRT. Waiting 5 seconds before trying again..."); } else if (e is System.IO.FileNotFoundException) { Console.WriteLine("Failed to connect to Rivatuner. Waiting 5 seconds before trying again..."); } else if (e is System.IO.InvalidDataException) { Console.WriteLine("Lost connection to Rivatuner. Waiting 5 seconds before trying again..."); osd = null; } else if (e is System.IO.IOException) { Console.WriteLine("Lost connection to ASRT. Waiting 5 seconds before trying again..."); osd.Dispose(); } else { Console.WriteLine(e.ToString()); } } System.Threading.Thread.Sleep(5000); } }