Exemplo n.º 1
0
        private static void Revert(PatchContext context)
        {
            Console.Write("Restoring backup... ");
            if (BackupManager.Restore(context))
            {
                Console.WriteLine("Done!");
            }
            else
            {
                Console.WriteLine("Already vanilla!");
            }

            if (File.Exists(context.ShortcutPath))
            {
                Console.WriteLine("Deleting shortcut...");
                File.Delete(context.ShortcutPath);
            }

            Console.WriteLine("");
            Console.WriteLine("--- Done reverting ---");

            if (!Environment.CommandLine.Contains("--nowait"))
            {
                Console.WriteLine("\n\n[Press any key to quit]");
                Console.ReadKey();
            }
        }
Exemplo n.º 2
0
        private static void Revert(PatchContext context, string[] args = null)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;
            bool isNewVersion = (args != null && args.Contains("newVersion"));

            Console.Write("Restoring backup... ");
            if (BackupManager.Restore(context))
            {
                Console.WriteLine("Done!");
            }
            else
            {
                Console.WriteLine("Already vanilla or you removed your backups!");
            }


            if (File.Exists(context.ShortcutPath))
            {
                Console.WriteLine("Deleting shortcut...");
                File.Delete(context.ShortcutPath);
            }

            Console.WriteLine("");
            Console.WriteLine("--- Done reverting ---");

            if (!Environment.CommandLine.Contains("--nowait") && !isNewVersion)
            {
                Console.WriteLine("\n\n[Press any key to quit]");
                Console.ReadKey();
            }

            Console.ResetColor();
        }
Exemplo n.º 3
0
 private static void Validate(PatchContext c)
 {
     if (!Directory.Exists(c.DataPathDst) || !File.Exists(c.EngineFile))
     {
         Fail("Game does not seem to be a Unity project. Could not find the libraries to patch.");
     }
 }
Exemplo n.º 4
0
#pragma warning restore CS8618 // Non-nullable field must contain a non-null value when exiting constructor. Consider declaring as nullable.

        public static PatchContext Create(string exe)
        {
            var context = new PatchContext
            {
                Executable = exe
            };

            context.ProjectRoot   = new FileInfo(context.Executable).Directory?.FullName ?? throw new Exception();
            context.IPARoot       = Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly() !.Location) ?? throw new InvalidOperationException(), "IPA");
            context.IPA           = Assembly.GetExecutingAssembly().Location;
            context.DataPathSrc   = Path.Combine(context.IPARoot, "Data");
            context.LibsPathSrc   = Path.Combine(context.IPARoot, "Libs");
            context.PluginsFolder = Path.Combine(context.ProjectRoot ?? throw new InvalidOperationException(), "Plugins");
            context.ProjectName   = Path.GetFileNameWithoutExtension(context.Executable);
            context.DataPathDst   = Path.Combine(context.ProjectRoot, context.ProjectName + "_Data");
            context.LibsPathDst   = Path.Combine(context.ProjectRoot, "Libs");
            context.ManagedPath   = Path.Combine(context.DataPathDst, "Managed");
            context.EngineFile    = Path.Combine(context.ManagedPath, "UnityEngine.CoreModule.dll");
            context.AssemblyFile  = Path.Combine(context.ManagedPath, "Assembly-CSharp.dll");
            context.BackupPath    = Path.Combine(context.IPARoot, "Backups", context.ProjectName);
            string shortcutName = $"{context.ProjectName} (Patch & Launch)";

            context.ShortcutPath = Path.Combine(context.ProjectRoot, shortcutName) + ".lnk";

            _ = Directory.CreateDirectory(context.BackupPath);

            return(context);
        }
Exemplo n.º 5
0
        public static PatchContext Create(String[] args)
        {
            var context = new PatchContext();

            context.Args          = args;
            context.Executable    = args[0];
            context.ProjectRoot   = new FileInfo(context.Executable).Directory.FullName;
            context.IPARoot       = Path.Combine(context.ProjectRoot, "IPA");
            context.IPA           = Assembly.GetExecutingAssembly().Location ?? Path.Combine(context.ProjectRoot, "IPA.exe");
            context.DataPathSrc   = Path.Combine(context.IPARoot, "Data");
            context.PluginsFolder = Path.Combine(context.ProjectRoot, "Plugins");
            context.ProjectName   = Path.GetFileNameWithoutExtension(context.Executable);
            context.DataPathDst   = Path.Combine(context.ProjectRoot, context.ProjectName + "_Data");
            context.ManagedPath   = Path.Combine(context.DataPathDst, "Managed");
            context.EngineFile    = Path.Combine(context.ManagedPath, "UnityEngine.CoreModule.dll");
            context.AssemblyFile  = Path.Combine(context.ManagedPath, "Assembly-CSharp.dll");
            context.BackupPath    = Path.Combine(Path.Combine(context.IPARoot, "Backups"), context.ProjectName);
            string shortcutName = $"{context.ProjectName} (Patch & Launch)";

            context.ShortcutPath = Path.Combine(context.ProjectRoot, shortcutName) + ".lnk";

            Directory.CreateDirectory(context.BackupPath);

            return(context);
        }
Exemplo n.º 6
0
        private static void Revert(PatchContext context)
        {
            Console.ForegroundColor = ConsoleColor.Cyan;

            Console.Write("Restoring backup... ");
            if (BackupManager.Restore(context))
            {
                Console.WriteLine("Done!");
            }
            else
            {
                Console.WriteLine("Already vanilla or you removed your backups!");
            }


            if (File.Exists(context.ShortcutPath))
            {
                Console.WriteLine("Deleting shortcut...");
                File.Delete(context.ShortcutPath);
            }

            Console.WriteLine("");
            Console.WriteLine("--- Done reverting ---");

            Console.ResetColor();
        }
Exemplo n.º 7
0
        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);
            }
        }
Exemplo n.º 8
0
        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();
        }
Exemplo n.º 9
0
        private static void Install(PatchContext context)
        {
            try
            {
                var backup = new BackupUnit(context);

                Console.ForegroundColor = ConsoleColor.Cyan;
                Console.WriteLine("Restoring old version... ");
                if (BackupManager.HasBackup(context))
                {
                    BackupManager.Restore(context);
                }

                var  nativePluginFolder = Path.Combine(context.DataPathDst, "Plugins");
                bool isFlat             = Directory.Exists(nativePluginFolder) &&
                                          Directory.GetFiles(nativePluginFolder).Any(f => f.EndsWith(".dll"));
                bool force        = !BackupManager.HasBackup(context) || ArgForce;
                var  architecture = DetectArchitecture(context.Executable);

                Console.ForegroundColor = ConsoleColor.DarkCyan;
                Console.WriteLine("Installing files... ");

                CopyAll(new DirectoryInfo(context.DataPathSrc), new DirectoryInfo(context.DataPathDst), force,
                        backup,
                        (from, to) => NativePluginInterceptor(from, to, new DirectoryInfo(nativePluginFolder), isFlat,
                                                              architecture));
                CopyAll(new DirectoryInfo(context.LibsPathSrc), new DirectoryInfo(context.LibsPathDst), force,
                        backup,
                        (from, to) => NativePluginInterceptor(from, to, new DirectoryInfo(nativePluginFolder), isFlat,
                                                              architecture));
                CopyAll(new DirectoryInfo(context.IPARoot), new DirectoryInfo(context.ProjectRoot), force,
                        backup,
                        null, false);

                //backup.Add(context.AssemblyFile);
                //backup.Add(context.EngineFile);

                #region Create Plugin Folder

                if (!Directory.Exists(context.PluginsFolder))
                {
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine("Creating plugins folder... ");
                    Directory.CreateDirectory(context.PluginsFolder);
                    Console.ResetColor();
                }

                #endregion
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Fail("Oops! This should not have happened.\n\n" + e);
            }
            Console.ResetColor();
        }
Exemplo n.º 10
0
 private static void Validate(PatchContext c)
 {
     if (!File.Exists(c.LauncherPathSrc))
     {
         Fail("Couldn't find DLLs! Make sure you extracted all contents of the release archive.");
     }
     if (!Directory.Exists(c.DataPathDst) || !File.Exists(c.EngineFile))
     {
         Fail("Game does not seem to be a Unity project. Could not find the libraries to patch.");
     }
 }
Exemplo n.º 11
0
        private static void StartIfNeedBe(PatchContext context)
        {
            var  argList = context.Args.ToList();
            bool launch  = argList.Remove("--launch");

            argList.RemoveAt(0);

            if (launch)
            {
                Process.Start(context.Executable, Args(argList.ToArray()));
            }
        }
Exemplo n.º 12
0
        private static Version GetInstalledVersion(PatchContext context)
        {
            // first, check currently installed version, if any
            if (File.Exists(Path.Combine(context.ProjectRoot, "winhttp.dll")))
            { // installed, so check version of installed assembly
                string injectorPath = Path.Combine(context.ManagedPath, "IPA.Injector.dll");
                if (File.Exists(injectorPath))
                {
                    var verInfo     = FileVersionInfo.GetVersionInfo(injectorPath);
                    var fileVersion = new Version(verInfo.FileVersion);

                    return(fileVersion);
                }
            }

            return(null);
        }
Exemplo n.º 13
0
        private static void StartIfNeedBe(PatchContext context)
        {
            if (ArgStart.HasValue)
            {
                Process.Start(context.Executable, ArgStart.Value);
            }
            else
            {
                var argList = Arguments.CmdLine.PositionalArgs.ToList();

                argList.Remove(context.Executable);

                if (ArgLaunch)
                {
                    Process.Start(context.Executable, Args(argList.ToArray()));
                }
            }
        }
Exemplo n.º 14
0
        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);
            }
        }
Exemplo n.º 15
0
        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();
        }
Exemplo n.º 16
0
        private static void Install(PatchContext context)
        {
            try
            {
                bool installFiles = true;
                // first, check currently installed version, if any
                if (File.Exists(Path.Combine(context.ProjectRoot, "winhttp.dll")))
                { // installed, so check version of installed assembly
                    string injectorPath = Path.Combine(context.ManagedPath, "IPA.Injector.dll");
                    if (File.Exists(injectorPath))
                    {
                        var verInfo     = FileVersionInfo.GetVersionInfo(injectorPath);
                        var fileVersion = new Version(verInfo.FileVersion);

                        if (fileVersion > Version)
                        {
                            installFiles = false;
                        }
                    }
                }

                if (installFiles || ArgForce)
                {
                    var backup = new BackupUnit(context);

                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("Restoring old version... ");
                    if (BackupManager.HasBackup(context))
                    {
                        BackupManager.Restore(context);
                    }

                    var  nativePluginFolder = Path.Combine(context.DataPathDst, "Plugins");
                    bool isFlat             = Directory.Exists(nativePluginFolder) &&
                                              Directory.GetFiles(nativePluginFolder).Any(f => f.EndsWith(".dll"));
                    bool force        = !BackupManager.HasBackup(context) || ArgForce;
                    var  architecture = DetectArchitecture(context.Executable);

                    Console.ForegroundColor = ConsoleColor.DarkCyan;
                    Console.WriteLine("Installing files... ");

                    CopyAll(new DirectoryInfo(context.DataPathSrc), new DirectoryInfo(context.DataPathDst), force,
                            backup,
                            (from, to) => NativePluginInterceptor(from, to, new DirectoryInfo(nativePluginFolder), isFlat,
                                                                  architecture));
                    CopyAll(new DirectoryInfo(context.LibsPathSrc), new DirectoryInfo(context.LibsPathDst), force,
                            backup,
                            (from, to) => NativePluginInterceptor(from, to, new DirectoryInfo(nativePluginFolder), isFlat,
                                                                  architecture));
                    CopyAll(new DirectoryInfo(context.IPARoot), new DirectoryInfo(context.ProjectRoot), force,
                            backup,
                            null, false);
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Not copying files because newer version already installed");
                }

                #region Create Plugin Folder

                if (!Directory.Exists(context.PluginsFolder))
                {
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine("Creating plugins folder... ");
                    Directory.CreateDirectory(context.PluginsFolder);
                    Console.ResetColor();
                }

                #endregion
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Fail("Oops! This should not have happened.\n\n" + e);
            }
            Console.ResetColor();
        }
Exemplo n.º 17
0
        private static void Install(PatchContext context)
        {
            try
            {
                bool installFiles = true;

                var fileVersion = GetInstalledVersion(context);

                if (fileVersion != null && fileVersion > Version)
                {
                    installFiles = false;
                }

                if (installFiles || ArgForce)
                {
                    var backup = new BackupUnit(context);

                    if (!ArgNoRevert)
                    {
                        Console.ForegroundColor = ConsoleColor.Cyan;
                        Console.WriteLine("Restoring old version... ");
                        if (BackupManager.HasBackup(context))
                        {
                            BackupManager.Restore(context);
                        }
                    }

                    var  nativePluginFolder = Path.Combine(context.DataPathDst, "Plugins");
                    bool isFlat             = Directory.Exists(nativePluginFolder) &&
                                              Directory.GetFiles(nativePluginFolder).Any(f => f.EndsWith(".dll"));
                    bool force        = !BackupManager.HasBackup(context) || ArgForce;
                    var  architecture = DetectArchitecture(context.Executable);

                    Console.ForegroundColor = ConsoleColor.DarkCyan;
                    Console.WriteLine("Installing files... ");

                    CopyAll(new DirectoryInfo(context.DataPathSrc), new DirectoryInfo(context.DataPathDst), force,
                            backup);
                    CopyAll(new DirectoryInfo(context.LibsPathSrc), new DirectoryInfo(context.LibsPathDst), force,
                            backup);
                    CopyAll(new DirectoryInfo(context.IPARoot), new DirectoryInfo(context.ProjectRoot), force,
                            backup,
                            null, false);
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Yellow;
                    Console.WriteLine("Not copying files because newer version already installed");
                }

                #region Create Plugin Folder

                if (!Directory.Exists(context.PluginsFolder))
                {
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine("Creating plugins folder... ");
                    Directory.CreateDirectory(context.PluginsFolder);
                    Console.ResetColor();
                }

                #endregion
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Fail("Oops! This should not have happened.\n\n" + e);
            }
            Console.ResetColor();
        }
Exemplo n.º 18
0
        private static void Install(PatchContext context)
        {
            try
            {
                var backup = new BackupUnit(context);

                if (ArgDestructive)
                {
                    #region Patch Version Check

                    var patchedModule = PatchedModule.Load(context.EngineFile);
#if DEBUG
                    var isCurrentNewer = Version.CompareTo(patchedModule.Data.Version) >= 0;
#else
                    var isCurrentNewer = Version.CompareTo(patchedModule.Data.Version) > 0;
#endif
                    Console.WriteLine($"Current: {Version} Patched: {patchedModule.Data.Version}");
                    if (isCurrentNewer)
                    {
                        Console.ForegroundColor = ConsoleColor.White;
                        Console.WriteLine(
                            $"Preparing for update, {(patchedModule.Data.Version == null ? "UnPatched" : patchedModule.Data.Version.ToString())} => {Version}");
                        Console.WriteLine("--- Starting ---");
                        Revert(context);
                        Console.ResetColor();

                        #region File Copying

                        Console.ForegroundColor = ConsoleColor.Magenta;
                        Console.WriteLine("Updating files... ");
                        var  nativePluginFolder = Path.Combine(context.DataPathDst, "Plugins");
                        bool isFlat             = Directory.Exists(nativePluginFolder) &&
                                                  Directory.GetFiles(nativePluginFolder).Any(f => f.EndsWith(".dll"));
                        bool force        = !BackupManager.HasBackup(context) || ArgForce;
                        var  architecture = DetectArchitecture(context.Executable);

                        Console.WriteLine("Architecture: {0}", architecture);

                        CopyAll(new DirectoryInfo(context.DataPathSrc), new DirectoryInfo(context.DataPathDst), force,
                                backup,
                                (from, to) => NativePluginInterceptor(from, to, new DirectoryInfo(nativePluginFolder), isFlat,
                                                                      architecture));
                        CopyAll(new DirectoryInfo(context.LibsPathSrc), new DirectoryInfo(context.LibsPathDst), force,
                                backup,
                                (from, to) => NativePluginInterceptor(from, to, new DirectoryInfo(nativePluginFolder), isFlat,
                                                                      architecture));

                        Console.WriteLine("Successfully updated files!");

                        #endregion
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine($"Files up to date @ Version {Version}!");
                        Console.ResetColor();
                    }

                    #endregion

                    #region Patching

                    if (!patchedModule.Data.IsPatched || isCurrentNewer)
                    {
                        Console.ForegroundColor = ConsoleColor.Yellow;
                        Console.WriteLine($"Patching UnityEngine.dll with Version {Application.ProductVersion}... ");
                        backup.Add(context.EngineFile);
                        patchedModule.Patch(Version);
                        Console.WriteLine("Done!");
                        Console.ResetColor();
                    }

                    #endregion

                    #region Creating shortcut
                    if (!File.Exists(context.ShortcutPath))
                    {
                        Console.ForegroundColor = ConsoleColor.DarkGreen;
                        Console.WriteLine("Creating shortcut to IPA ({0})... ", context.IPA);
                        try
                        {
                            Shortcut.Create(
                                fileName: context.ShortcutPath,
                                targetPath: context.IPA,
                                arguments: Args(context.Executable, "-ln"),
                                workingDirectory: context.ProjectRoot,
                                description: "Launches the game and makes sure it's in a patched state",
                                hotkey: "",
                                iconPath: context.Executable
                                );
                        }
                        catch (Exception)
                        {
                            Console.ForegroundColor = ConsoleColor.Red;
                            Console.Error.WriteLine("Failed to create shortcut, but game was patched!");
                        }
                        Console.ResetColor();
                    }
                    #endregion
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Cyan;
                    Console.WriteLine("Restoring old version... ");
                    if (BackupManager.HasBackup(context))
                    {
                        BackupManager.Restore(context);
                    }

                    var  nativePluginFolder = Path.Combine(context.DataPathDst, "Plugins");
                    bool isFlat             = Directory.Exists(nativePluginFolder) &&
                                              Directory.GetFiles(nativePluginFolder).Any(f => f.EndsWith(".dll"));
                    bool force        = !BackupManager.HasBackup(context) || ArgForce;
                    var  architecture = DetectArchitecture(context.Executable);

                    Console.ForegroundColor = ConsoleColor.DarkCyan;
                    Console.WriteLine("Installing files... ");

                    CopyAll(new DirectoryInfo(context.DataPathSrc), new DirectoryInfo(context.DataPathDst), force,
                            backup,
                            (from, to) => NativePluginInterceptor(from, to, new DirectoryInfo(nativePluginFolder), isFlat,
                                                                  architecture));
                    CopyAll(new DirectoryInfo(context.LibsPathSrc), new DirectoryInfo(context.LibsPathDst), force,
                            backup,
                            (from, to) => NativePluginInterceptor(from, to, new DirectoryInfo(nativePluginFolder), isFlat,
                                                                  architecture));
                    CopyAll(new DirectoryInfo(context.IPARoot), new DirectoryInfo(context.ProjectRoot), force,
                            backup,
                            null, false);

                    //backup.Add(context.AssemblyFile);
                    //backup.Add(context.EngineFile);
                }

                #region Create Plugin Folder

                if (!Directory.Exists(context.PluginsFolder))
                {
                    Console.ForegroundColor = ConsoleColor.DarkYellow;
                    Console.WriteLine("Creating plugins folder... ");
                    Directory.CreateDirectory(context.PluginsFolder);
                    Console.ResetColor();
                }

                #endregion

                #region Virtualizing

                if (ArgDestructive && File.Exists(context.AssemblyFile))
                {
                    var virtualizedModule = VirtualizedModule.Load(context.AssemblyFile);
                    if (!virtualizedModule.IsVirtualized)
                    {
                        Console.ForegroundColor = ConsoleColor.Green;
                        Console.WriteLine("Virtualizing Assembly-Csharp.dll... ");
                        backup.Add(context.AssemblyFile);
                        virtualizedModule.Virtualize();
                        Console.WriteLine("Done!");
                        Console.ResetColor();
                    }
                }

                #endregion
            }
            catch (Exception e)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Fail("Oops! This should not have happened.\n\n" + e);
            }
            Console.ResetColor();
        }
Exemplo n.º 19
0
        private static void Install(PatchContext context)
        {
            try
            {
                var backup = new BackupUnit(context);

                // Copying
                Console.WriteLine("Updating files... ");
                var  nativePluginFolder = Path.Combine(context.DataPathDst, "Plugins");
                bool isFlat             = Directory.Exists(nativePluginFolder) && Directory.GetFiles(nativePluginFolder).Any(f => f.EndsWith(".dll"));
                bool force        = !BackupManager.HasBackup(context) || context.Args.Contains("-f") || context.Args.Contains("--force");
                var  architecture = DetectArchitecture(context.Executable);

                Console.WriteLine("Architecture: {0}", architecture);

                CopyAll(new DirectoryInfo(context.DataPathSrc), new DirectoryInfo(context.DataPathDst), force, backup,
                        (from, to) => NativePluginInterceptor(from, to, new DirectoryInfo(nativePluginFolder), isFlat, architecture));

                Console.WriteLine("Successfully updated files!");

                if (!Directory.Exists(context.PluginsFolder))
                {
                    Console.WriteLine("Creating plugins folder... ");
                    Directory.CreateDirectory(context.PluginsFolder);
                }

                if (!Directory.Exists(context.LogsFolder))
                {
                    Console.WriteLine("Creating logs folder... ");
                    Directory.CreateDirectory(context.LogsFolder);
                }

                // Patching
                var patchedModule = PatchedModule.Load(context.EngineFile);
                if (!patchedModule.IsPatched)
                {
                    Console.Write("Patching UnityEngine.dll... ");
                    backup.Add(context.EngineFile);
                    patchedModule.Patch();
                    Console.WriteLine("Done!");
                }

                // Virtualizing
                if (File.Exists(context.AssemblyFile))
                {
                    var virtualizedModule = VirtualizedModule.Load(context.AssemblyFile);
                    if (!virtualizedModule.IsVirtualized)
                    {
                        Console.Write("Virtualizing Assembly-Csharp.dll... ");
                        backup.Add(context.AssemblyFile);
                        virtualizedModule.Virtualize();
                        Console.WriteLine("Done!");
                    }
                }
            }
            catch (Exception e)
            {
                Fail("Oops! This should not have happened.\n\n" + e);
            }


            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Finished!");
            Console.ResetColor();
        }
Exemplo n.º 20
0
        private static void Install(PatchContext context)
        {
            try
            {
                var backup = new BackupUnit(context);

                // Copying
                Console.WriteLine("Updating files... ");
                var  nativePluginFolder = Path.Combine(context.DataPathDst, "Plugins");
                bool isFlat             = Directory.Exists(nativePluginFolder) && Directory.GetFiles(nativePluginFolder).Any(f => f.EndsWith(".dll"));
                bool force        = !BackupManager.HasBackup(context) || context.Args.Contains("-f") || context.Args.Contains("--force");
                var  architecture = DetectArchitecture(context.Executable);

                Console.WriteLine("Architecture: {0}", architecture);

                CopyAll(new DirectoryInfo(context.DataPathSrc), new DirectoryInfo(context.DataPathDst), force, backup,
                        (from, to) => NativePluginInterceptor(from, to, new DirectoryInfo(nativePluginFolder), isFlat, architecture));

                Console.WriteLine("Successfully updated files!");

                if (!Directory.Exists(context.PluginsFolder))
                {
                    Console.WriteLine("Creating plugins folder... ");
                    Directory.CreateDirectory(context.PluginsFolder);
                }

                // Deobfuscating

                /*var options = new Deobfuscator.Options();
                 * options.OneFileAtATime = false;
                 * var searchDir = new Deobfuscator.SearchDir() { InputDirectory = context.ManagedPath, OutputDirectory = Path.Combine(context.ManagedPath, "decompiled/"), SkipUnknownObfuscators = false };
                 * options.SearchDirs = new List<Deobfuscator.SearchDir>() { searchDir };
                 *              new Deobfuscator(options).DoIt();*/

                // Patching
                var patchedModule = PatchedModule.Load(context.EngineFile);
                if (!patchedModule.IsPatched)
                {
                    Console.Write("Patching UnityEngine.dll... ");
                    backup.Add(context.EngineFile);
                    patchedModule.Patch();
                    Console.WriteLine("Done!");
                }

                // Virtualizing
                if (File.Exists(context.AssemblyFile))
                {
                    var virtualizedModule = VirtualizedModule.Load(context.AssemblyFile);
                    if (!virtualizedModule.IsVirtualized)
                    {
                        Console.Write("Virtualizing Assembly-Csharp.dll... ");
                        backup.Add(context.AssemblyFile);
                        virtualizedModule.Virtualize();
                        Console.WriteLine("Done!");
                    }
                }

                // Creating shortcut
                if (!File.Exists(context.ShortcutPath))
                {
                    Console.Write("Creating shortcut to IPA ({0})... ", context.IPA);
                    try
                    {
                        Shortcut.Create(
                            fileName: context.ShortcutPath,
                            targetPath: context.IPA,
                            arguments: Args(context.Executable, "--launch"),
                            workingDirectory: context.ProjectRoot,
                            description: "Launches the game and makes sure it's in a patched state",
                            hotkey: "",
                            iconPath: context.Executable
                            );
                        Console.WriteLine("Created");
                    }
                    catch (Exception e)
                    {
                        Console.Error.WriteLine("Failed to create shortcut, but game was patched!");
                    }
                }
            }
            catch (Exception e)
            {
                Fail("Oops! This should not have happened.\n\n" + e);
            }

            Console.ForegroundColor = ConsoleColor.Green;
            Console.WriteLine("Finished!");
            Console.ResetColor();
        }