private static void Main(string[] args) { if (args.Length < 1 || !args[0].EndsWith(".exe")) { Fail("Drag an (executable) file on the exe!"); } try { var context = PatchContext.Create(args); bool isRevert = args.Contains("--revert") || Keyboard.IsKeyDown(Keys.LMenu); // Sanitizing Validate(context); if (isRevert) { Revert(context); } else { Install(context); StartIfNeedBe(context); } } catch (Exception e) { Fail(e.Message); } }
static void Main(string[] args) { Arguments.CmdLine.Flags(ArgHelp, ArgWaitFor, ArgForce, ArgRevert, ArgNoWait, ArgStart, ArgLaunch).Process(); if (ArgHelp) { Arguments.CmdLine.PrintHelp(); return; } try { if (ArgWaitFor.HasValue) { // wait for process if necessary int pid = int.Parse(ArgWaitFor.Value); try { // wait for beat saber to exit (ensures we can modify the file) var parent = Process.GetProcessById(pid); Console.WriteLine($"Waiting for parent ({pid}) process to die..."); parent.WaitForExit(); } catch (Exception) { } } PatchContext context; var argExeName = Arguments.CmdLine.PositionalArgs.FirstOrDefault(s => s.EndsWith(".exe")); if (argExeName == null) { context = PatchContext.Create(new DirectoryInfo(Directory.GetCurrentDirectory()).GetFiles() .First(o => o.Extension == ".exe" && o.FullName != Assembly.GetCallingAssembly().Location) .FullName); } else { context = PatchContext.Create(argExeName); } // Sanitizing Validate(context); if (ArgRevert || Keyboard.IsKeyDown(Keys.LMenu)) { Revert(context); } else { Install(context); StartIfNeedBe(context); } } catch (Exception e) { Fail(e.Message); } WaitForEnd(); }
static void Main(string[] args) { PatchContext context; if (args.Length < 1 || !args[0].EndsWith(".exe")) { //Fail("Drag an (executable) file on the exe!"); context = PatchContext.Create(new[] { new DirectoryInfo(Directory.GetCurrentDirectory()).GetFiles() .First(o => o.FullName.EndsWith(".exe")) .FullName }); } else { context = PatchContext.Create(args); } try { bool isRevert = args.Contains("--revert") || Keyboard.IsKeyDown(Keys.LMenu); // Sanitizing Validate(context); if (isRevert) { Revert(context); } else { Install(context); StartIfNeedBe(context); } } catch (Exception e) { Fail(e.Message); } }
public static void Main(string[] args) { Arguments.CmdLine.Flags(ArgHelp, ArgWaitFor, ArgForce, ArgRevert, ArgNoWait, ArgStart, ArgLaunch /*, ArgDestructive*/).Process(); if (ArgHelp) { Arguments.CmdLine.PrintHelp(); return; } try { if (ArgWaitFor.HasValue) { // wait for process if necessary var pid = int.Parse(ArgWaitFor.Value); try { // wait for beat saber to exit (ensures we can modify the file) var parent = Process.GetProcessById(pid); Console.WriteLine($"Waiting for parent ({pid}) process to die..."); parent.WaitForExit(); } catch (Exception) { // ignored } } PatchContext context = null; Assembly AssemblyLibLoader(object source, ResolveEventArgs e) { // ReSharper disable AccessToModifiedClosure if (context == null) { return(null); } var libsDir = context.LibsPathSrc; // ReSharper enable AccessToModifiedClosure var asmName = new AssemblyName(e.Name); var testFile = Path.Combine(libsDir, $"{asmName.Name}.{asmName.Version}.dll"); if (File.Exists(testFile)) { return(Assembly.LoadFile(testFile)); } Console.WriteLine($"Could not load library {asmName}"); return(null); } AppDomain.CurrentDomain.AssemblyResolve += AssemblyLibLoader; var argExeName = Arguments.CmdLine.PositionalArgs.FirstOrDefault(s => s.EndsWith(".exe")); if (argExeName == null) { context = PatchContext.Create(new DirectoryInfo(Directory.GetCurrentDirectory()).GetFiles() .First(o => o.Extension == ".exe" && o.FullName != Assembly.GetCallingAssembly().Location) .FullName); } else { context = PatchContext.Create(argExeName); } // Sanitizing Validate(context); if (ArgRevert || Keyboard.IsKeyDown(Keys.LMenu)) { Revert(context); } else { Install(context); StartIfNeedBe(context); } } catch (Exception e) { Fail(e.Message); } WaitForEnd(); }