Пример #1
0
        internal static void Main(string[] args)
        {
            WriteStartupHeader();

            if (!IsValidSyntax(args))
            {
                ColoredOutput.WriteInformation($"Usage: {GetExecutingFileName()} <-t (--target) Assembly-CSharp.dll> [options]");
                ColoredOutput.WriteInformation("  Options:");
                ColoredOutput.WriteInformation("    -t [--target]+: Specify the target Distance DLL you want to patch.");
                ColoredOutput.WriteInformation("    -s [--source]+: Specify the source DLL you want to cross-reference.");
                ColoredOutput.WriteInformation("    -p [--patch]+:  Run only patch with the specified name.");
                ErrorHandler.TerminateWithError("Invalid syntax provided.");
            }

            ParseArguments(args);

            if (string.IsNullOrEmpty(_distanceAssemblyFilename))
            {
                ErrorHandler.TerminateWithError("Target DLL name not specified.");
            }
            if ((args.Contains("-p") || args.Contains("--patch")) && string.IsNullOrEmpty(_requestedPatchName))
            {
                ErrorHandler.TerminateWithError("Patch name not specified.");
            }
            if ((args.Contains("-s") || args.Contains("--source")) && string.IsNullOrEmpty(_bootstrapAssemblyFilename))
            {
                ErrorHandler.TerminateWithError("Source DLL name not specified.");
            }

            if (!DistanceFileExists())
            {
                ErrorHandler.TerminateWithError("Specified TARGET DLL not found.");
            }

            if (!BootstrapFileExists() && (args.Contains("-s") || args.Contains("--source")))
            {
                ErrorHandler.TerminateWithError("Specified SOURCE DLL not found.");
            }

            CreateBackup();
            PreparePatches();
            RunPatches();
            ModuleWriter.SavePatchedFile(_distanceAssemblyDefinition, _distanceAssemblyFilename);

            // Run decapsulation after all other configured patches.
            _patcher.AddPatch(new DecapsulationPatch());
            _patcher.RunSpecific("Decapsulation");

            var devDllFileName = $"{Path.GetFileNameWithoutExtension(_distanceAssemblyFilename)}.dev.dll";

            ModuleWriter.SavePatchedFile(_distanceAssemblyDefinition, devDllFileName);
            ColoredOutput.WriteSuccess($"Saved decapsulated development DLL to {devDllFileName}");

            ColoredOutput.WriteSuccess("Patch process completed.");
        }
Пример #2
0
        internal static void Main(string[] args)
        {
            WriteStartupHeader();

            if (!IsValidSyntax(args))
            {
                ColoredOutput.WriteInformation($"Usage: {GetExecutingFileName()} <(-t | --target) target_assembly.dll> [options]");
                ColoredOutput.WriteInformation("  Options:");
                ColoredOutput.WriteInformation("    -t [--target]+: Specify the target assembly you want to patch.");
                ColoredOutput.WriteInformation("    -s [--source]+: Specify the source DLL you want to source the init code from.");
                ColoredOutput.WriteInformation("    -p [--patch]+:  Run only the patch with the specified name.");
                ColoredOutput.WriteInformation("    -h [--hash]: Generate a .md5 file of the patched assembly.");
                ColoredOutput.WriteInformation("    -d [--decap-only]: Only decapsulate the target DLL. Invalidates -s -p and -h.");

                ErrorHandler.TerminateWithError("Invalid syntax provided.", TerminationReason.InvalidSyntax);
            }

            ParseArguments(args);

            if (string.IsNullOrEmpty(_gameAssemblyFilename))
            {
                ErrorHandler.TerminateWithError("Target DLL name not specified.", TerminationReason.TargetDllNotProvided);
            }
            if ((args.Contains("-p") || args.Contains("--patch")) && string.IsNullOrEmpty(_requestedPatchName))
            {
                ErrorHandler.TerminateWithError("Patch name not specified.", TerminationReason.PatchNameNotProvided);
            }
            if ((args.Contains("-s") || args.Contains("--source")) && string.IsNullOrEmpty(_bootstrapAssemblyFilename))
            {
                ErrorHandler.TerminateWithError("Source DLL name not specified.", TerminationReason.SourceDllNotProvided);
            }

            if (!BootstrapFileExists() && (args.Contains("-s") || args.Contains("--source")))
            {
                ErrorHandler.TerminateWithError("Specified SOURCE DLL not found.", TerminationReason.SourceDllNonexistant);
            }

            if (!GameFileExists())
            {
                ErrorHandler.TerminateWithError("Specified TARGET DLL not found.", TerminationReason.TargetDllNonexistant);
            }

            PreparePatches();

            if (!_decapOnly)
            {
                CreateBackup();
                RunPatches();

                ModuleWriter.SavePatchedFile(_gameAssemblyDefinition, _gameAssemblyFilename, false);

                if (_generateHashFile)
                {
                    GenerateHashFile();
                }
            }
            else
            {
                ColoredOutput.WriteInformation("Attention! Decap-only run requested.");
            }

            _patcher.AddPatch(new DecapsulationPatch());
            _patcher.RunSpecific("Decapsulation");

            var devDllFileName = $"{Path.GetFileNameWithoutExtension(_gameAssemblyFilename)}.dev.dll";

            ModuleWriter.SavePatchedFile(_gameAssemblyDefinition, devDllFileName, true);
            ColoredOutput.WriteSuccess($"Saved decapsulated development DLL to {devDllFileName}");

            ColoredOutput.WriteSuccess("Patch process completed.");
        }