A fork of Eusth's IPA
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.

113 lines
4.1KB

  1. using IPA.Patcher;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Linq;
  6. using System.Text;
  7. namespace IPA
  8. {
  9. class Program
  10. {
  11. static void Main(string[] args)
  12. {
  13. if(args.Length < 1 || !args[0].EndsWith(".exe"))
  14. {
  15. Fail("Drag an (executable) file on the exe!");
  16. }
  17. string launcherSrc = Path.Combine("IPA", "Launcher.exe");
  18. string dataSrcPath = Path.Combine("IPA", "Data");
  19. string pluginsFolder = "Plugins";
  20. string projectName = Path.GetFileNameWithoutExtension(args[0]);
  21. string dataDstPath = Path.Combine(Path.GetDirectoryName(args[0]), projectName + "_Data");
  22. string managedPath = Path.Combine(dataDstPath, "Managed");
  23. string engineFile = Path.Combine(managedPath, "UnityEngine.dll");
  24. string assemblyFile = Path.Combine(managedPath, "Assembly-Csharp.dll");
  25. // Sanitizing
  26. if (!File.Exists(launcherSrc)) Fail("Couldn't find DLLs! Make sure you extracted all contents of the release archive.");
  27. if(!Directory.Exists(dataDstPath) || !File.Exists(engineFile) || !File.Exists(assemblyFile))
  28. {
  29. Fail("Game does not seem to be a Unity project. Could not find the libraries to patch. ");
  30. }
  31. try
  32. {
  33. // Copying
  34. Console.Write("Updating files... ");
  35. CopyAll(new DirectoryInfo(dataSrcPath), new DirectoryInfo(dataDstPath));
  36. Console.WriteLine("Successfully updated files!");
  37. if (!Directory.Exists(pluginsFolder))
  38. {
  39. Console.WriteLine("Creating plugins folder... ");
  40. Directory.CreateDirectory(pluginsFolder);
  41. }
  42. // Patching
  43. var patchedModule = PatchedModule.Load(engineFile);
  44. if(!patchedModule.IsPatched)
  45. {
  46. Console.Write("Patching UnityEngine.dll... ");
  47. BackupManager.MakeBackup(engineFile);
  48. patchedModule.Patch();
  49. Console.WriteLine("Done!");
  50. }
  51. // Virtualizing
  52. var virtualizedModule = VirtualizedModule.Load(assemblyFile);
  53. if(!virtualizedModule.IsVirtualized)
  54. {
  55. Console.Write("Virtualizing Assembly-Csharp.dll... ");
  56. BackupManager.MakeBackup(assemblyFile);
  57. virtualizedModule.Virtualize();
  58. Console.WriteLine("Done!");
  59. }
  60. } catch(Exception e)
  61. {
  62. Fail("Oops! This should not have happened.\n\n" + e);
  63. }
  64. Console.WriteLine("Finished!");
  65. }
  66. public static void CopyAll(DirectoryInfo source, DirectoryInfo target)
  67. {
  68. Directory.CreateDirectory(target.FullName);
  69. // Copy each file into the new directory.
  70. foreach (FileInfo fi in source.GetFiles())
  71. {
  72. string targetFile = Path.Combine(target.FullName, fi.Name);
  73. if (!File.Exists(targetFile) || File.GetLastWriteTimeUtc(targetFile) < fi.LastWriteTimeUtc)
  74. {
  75. Console.WriteLine(@"Copying {0}\{1}", target.FullName, fi.Name);
  76. fi.CopyTo(Path.Combine(target.FullName, fi.Name), true);
  77. }
  78. }
  79. // Copy each subdirectory using recursion.
  80. foreach (DirectoryInfo diSourceSubDir in source.GetDirectories())
  81. {
  82. DirectoryInfo nextTargetSubDir =
  83. target.CreateSubdirectory(diSourceSubDir.Name);
  84. CopyAll(diSourceSubDir, nextTargetSubDir);
  85. }
  86. }
  87. static void Fail(string message)
  88. {
  89. Console.Error.Write("ERROR: " + message);
  90. if (!Environment.CommandLine.Contains("--nowait"))
  91. {
  92. Console.WriteLine("\n\n[Press any key to quit]");
  93. Console.ReadKey();
  94. }
  95. Environment.Exit(1);
  96. }
  97. }
  98. }