Cardlife mod patcher
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

Program.cs 3.5KB

8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
8 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text.RegularExpressions;
  7. using System.Windows.Forms;
  8. namespace Launcher
  9. {
  10. static class Program
  11. {
  12. private static string[] TABOO_NAMES = {
  13. //"Start",
  14. //"Update",
  15. //"Awake",
  16. //"OnDestroy"
  17. };
  18. private static string[] ENTRY_TYPES = { "Display" };
  19. /// <summary>
  20. /// The main entry point for the application.
  21. /// </summary>
  22. [STAThread]
  23. static void Main()
  24. {
  25. try {
  26. var execPath = Application.ExecutablePath;
  27. var fileName = Path.GetFileNameWithoutExtension(execPath);
  28. if (fileName.IndexOf("VR") == -1 && fileName.IndexOf("_") == -1)
  29. {
  30. Fail("File not named correctly!");
  31. }
  32. bool vrMode = fileName.IndexOf("VR") > 0;
  33. string baseName = execPath.Substring(0, vrMode
  34. ? execPath.LastIndexOf("VR")
  35. : execPath.LastIndexOf("_"));
  36. string executable = baseName + ".exe";
  37. var file = new FileInfo(executable);
  38. if (file.Exists)
  39. {
  40. var args = Environment.GetCommandLineArgs().ToList();
  41. if (vrMode) args.Add("--vr");
  42. EnsureIPA(executable);
  43. StartGame(executable, args.ToArray());
  44. }
  45. else
  46. {
  47. MessageBox.Show("Could not find: " + file.FullName, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  48. }
  49. } catch(Exception globalException) {
  50. MessageBox.Show(globalException.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
  51. }
  52. }
  53. private static void EnsureIPA(string executable)
  54. {
  55. var processStart = new ProcessStartInfo("IPA.exe", EncodeParameterArgument(executable) + " --nowait");
  56. processStart.UseShellExecute = false;
  57. processStart.CreateNoWindow = true;
  58. processStart.RedirectStandardError = true;
  59. var process = Process.Start(processStart);
  60. process.WaitForExit();
  61. if(process.ExitCode != 0)
  62. {
  63. Fail(process.StandardError.ReadToEnd());
  64. }
  65. }
  66. private static void StartGame(string executable, string[] args)
  67. {
  68. var arguments = string.Join(" ", args.ToArray());
  69. Process.Start(executable, arguments);
  70. }
  71. private static void Fail(string reason) {
  72. throw new Exception(reason);
  73. }
  74. /// <summary>
  75. /// Encodes an argument for passing into a program
  76. /// </summary>
  77. /// <param name="original">The value that should be received by the program</param>
  78. /// <returns>The value which needs to be passed to the program for the original value
  79. /// to come through</returns>
  80. private static string EncodeParameterArgument(string original)
  81. {
  82. if (string.IsNullOrEmpty(original))
  83. return original;
  84. string value = Regex.Replace(original, @"(\\*)" + "\"", @"$1\$0");
  85. value = Regex.Replace(value, @"^(.*\s.*?)(\\*)$", "\"$1$2$2\"");
  86. return value;
  87. }
  88. }
  89. }