Exemple #1
0
        private static void WriteStartupHeader()
        {
            var version = Assembly.GetExecutingAssembly().GetName().Version;

            ColoredOutput.WriteInformation($"Centrifuge Spindle for Unity Engine. Version {version.Major}.{version.Minor}.{version.Build}.{version.Revision}");
            ColoredOutput.WriteInformation("------------------------------------------");
        }
Exemple #2
0
 private static void CreateBackup()
 {
     if (!File.Exists($"{_distanceAssemblyFilename}.backup"))
     {
         ColoredOutput.WriteInformation("Performing a backup...");
         File.Copy($"{_distanceAssemblyFilename}", $"{_distanceAssemblyFilename}.backup");
     }
 }
Exemple #3
0
        public override void Run(ModuleDefinition moduleDefinition)
        {
            ColoredOutput.WriteInformation("Decapsulating non-public types and their members...");
            ColoredOutput.WriteInformation("WARNING: You will need to compile your plug-ins with\n           unsafe code allowed if you're going to publish them.");

            var assemblyTypes = ScanTypes(moduleDefinition);

            DecapsulateMembers(assemblyTypes);
        }
Exemple #4
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.");
        }
Exemple #5
0
        private static void PreparePatches()
        {
            ColoredOutput.WriteInformation("Preparing patches...");
            _gameAssemblyDefinition = ModuleLoader.LoadGameModule(_gameAssemblyFilename);

            if (!string.IsNullOrEmpty(_bootstrapAssemblyFilename))
            {
                _bootstrapAssemblyDefinition = ModuleLoader.LoadBootstrapModule(_bootstrapAssemblyFilename);
            }
            _patcher = new Patcher(_bootstrapAssemblyDefinition, _gameAssemblyDefinition);
            _patcher.AddPatch(new CentrifugeInitPatch());
        }
Exemple #6
0
 public void RunAll()
 {
     foreach (var patch in Patches)
     {
         if (SourceModule == null && patch.NeedsSource)
         {
             ColoredOutput.WriteInformation($"Skipping '{patch.Name}' because no source module was provided.");
             continue;
         }
         RunPatch(patch);
     }
 }
Exemple #7
0
 private static void RunPatches()
 {
     if (string.IsNullOrEmpty(_requestedPatchName))
     {
         ColoredOutput.WriteInformation("Running all patches...");
         _patcher.RunAll();
     }
     else
     {
         ColoredOutput.WriteInformation($"Running the requested patch: '{_requestedPatchName}'");
         _patcher.RunSpecific(_requestedPatchName);
     }
 }
Exemple #8
0
        private static void PreparePatches()
        {
            ColoredOutput.WriteInformation("Preparing patches...");

            _distanceAssemblyDefinition = ModuleLoader.LoadDistanceModule(_distanceAssemblyFilename);

            if (!string.IsNullOrEmpty(_bootstrapAssemblyFilename))
            {
                _bootstrapAssemblyDefinition = ModuleLoader.LoadBootstrapModule(_bootstrapAssemblyFilename);
            }
            _patcher = new Patcher(_bootstrapAssemblyDefinition, _distanceAssemblyDefinition);

            _patcher.AddPatch(new SpectrumInitCodePatch());
            _patcher.AddPatch(new SpectrumUpdateCodePatch());
        }
Exemple #9
0
        public void AddPatch(IPatch patch)
        {
            if (patch == null)
            {
                return;
            }

            patch.PatchFailed += (sender, args) =>
            {
                ErrorHandler.TerminateWithError($"Patch '{args.Name}' failed. Reason: {args.Exception.Message}", TerminationReason.PatchFailure);
            };

            patch.PatchSucceeded += (sender, args) =>
            {
                ColoredOutput.WriteSuccess($"Patch '{args.Name}' succeeded.");
            };

            Patches.Add(patch);
        }
Exemple #10
0
 public static void TerminateWithError(string message, TerminationReason reason = 0)
 {
     ColoredOutput.WriteError(message);
     Environment.Exit((int)reason);
 }
Exemple #11
0
 public static void TerminateWithError(string message)
 {
     ColoredOutput.WriteError(message);
     Environment.Exit(0);
 }
Exemple #12
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.");
        }
Exemple #13
0
        public void SetConsoleColor(int color)
        {
            ColoredOutput coloredOutput = new ColoredOutput(color);

            Console.SetOut(coloredOutput);
        }