public static int Main(string[] args) { bool interactive = args.Length > 0; gendiffs = args.Any(arg => arg == "--generatediffs" || arg == "-gd"); string logfile = (from arg in args where arg.StartsWith("--logFile:", StringComparison.Ordinal) || arg.StartsWith("-l:", StringComparison.Ordinal) select arg.Split(':').Last()).FirstOrDefault(); LogFile = !String.IsNullOrEmpty(logfile) ? logfile : LogFile; LogToFile = !String.IsNullOrEmpty(logfile); if (gendiffs) MethodDB.GetInstance(); newAssCS = true; Log($"[( Pluton Patcher v{Version} )]"); rustAssembly = AssemblyPatcher.GetPatcher("Assembly-CSharp.dll"); if (rustAssembly.GetType("PlutonPatched") != null) { LogError("Assembly-CSharp.dll is already patched!"); if (interactive) System.Threading.Thread.Sleep(250); return (int)ExitCode.ACDLL_ALREADY_PATCHED; } foreach (var json in Directory.GetFiles("./", "*.json")) { JSON.Array jsonArr = JSON.Array.Parse(File.ReadAllText(json)); foreach (JSON.Value jsonElmnt in jsonArr) { JSON.Object jsonObj = jsonElmnt.Obj; var assemblyPatch = AssemblyPatch.ParseFromJSON(jsonObj); if (!assemblyPatch.Patch()) { LogError("Failed to patch!"); if (interactive) System.Threading.Thread.Sleep(250); return (int)ExitCode.ACDLL_GENERIC_PATCH_ERR; } } } if (gendiffs) { MethodDB.GetInstance().Save(); string diffs = MethodDB.GetDifferences(); if (!String.IsNullOrEmpty(diffs)) File.WriteAllText($"diffs-{DateTime.Now.ToShortDateString()}{DateTime.Now.ToShortTimeString()}.html".Replace('\\', '_').Replace('/', '_'), "<html><head><style>del,ins{text-decoration:none}ins{background-color:#0F0}del{color:#999;background-color:#F00}</style></head><body>" + diffs + "</body></html>"); } Log("Completed!"); if (interactive) System.Threading.Thread.Sleep(250); return (int)ExitCode.SUCCESS; }
private static void BootstrapAttachPatch() { var initConfig = rustAssembly.GetType("Bootstrap").GetMethod("Init_Config"); var attachBootstrap = plutonAssembly.GetType("Pluton.Bootstrap").GetMethod("AttachBootstrap"); initConfig.InsertCallBefore(0, attachBootstrap); if (gendiffs && newAssCS) { File.WriteAllText("diffs" + Path.DirectorySeparatorChar + initConfig.FriendlyName + ".html", initConfig.PrintAndLink(attachBootstrap)); } }
public static int Main(string[] args) { bool interactive = true; if (args.Length > 0) { interactive = false; } foreach (string arg in args) { if (arg.Contains("--generatediffs")) { gendiffs = true; } } newAssCS = true; Console.WriteLine(string.Format("[( Pluton Patcher v{0} )]", Version)); try { plutonAssembly = AssemblyPatcher.FromFile("Pluton.dll"); rustAssembly = AssemblyPatcher.FromFile("Assembly-CSharp.dll"); } catch (FileNotFoundException ex) { Console.WriteLine("You are missing " + ex.FileName + " did you move the patcher to the managed folder ?"); if (interactive) { Console.WriteLine("Press any key to continue..."); } return((int)ExitCode.DLL_MISSING); } catch (Exception ex) { Console.WriteLine("An error occured while reading the assemblies :"); Console.WriteLine(ex.ToString()); if (interactive) { Console.WriteLine("Press any key to continue..."); } return((int)ExitCode.DLL_READ_ERROR); } bNPC = rustAssembly.GetType("BaseNPC"); bPlayer = rustAssembly.GetType("BasePlayer"); codeLock = rustAssembly.GetType("CodeLock"); hooksClass = plutonAssembly.GetType("Pluton.Hooks"); itemCrafter = rustAssembly.GetType("ItemCrafter"); pLoot = rustAssembly.GetType("PlayerLoot"); //Check if patching is required TypePatcher plutonClass = rustAssembly.GetType("PlutonPatched"); if (plutonClass == null) { try { if (gendiffs) { string hash = string.Empty; using (var sha512 = new System.Security.Cryptography.SHA512Managed()) hash = BitConverter.ToString(sha512.ComputeHash(File.ReadAllBytes("Assembly-CSharp.dll"))).Replace("-", "").ToLower(); Directory.CreateDirectory("diffs"); string hashpath = "diffs" + Path.DirectorySeparatorChar + "lastHash"; if (File.Exists(hashpath)) { newAssCS = hash != File.ReadAllText(hashpath); } if (newAssCS) { foreach (var difffile in Directory.GetFiles("diffs")) { if (difffile.Contains(".htm")) { string filename = Path.GetFileName(difffile); string dirname = Path.GetDirectoryName(difffile); Directory.CreateDirectory(Path.Combine(dirname, "old")); File.Move(difffile, difffile.Replace(Path.Combine(dirname, filename), Path.Combine(dirname, "old", filename))); } } } if (gendiffs && newAssCS) { File.WriteAllText(hashpath, hash); } } PatchASMCSharp(); Console.WriteLine("Patched Assembly-CSharp !"); } catch (Exception ex) { interactive = true; Console.WriteLine("An error occured while patching Assembly-CSharp :"); Console.WriteLine(); Console.WriteLine(ex.Message.ToString()); //Normal handle for the others Console.WriteLine(); Console.WriteLine(ex.StackTrace.ToString()); Console.WriteLine(); if (interactive) { Console.WriteLine("Press any key to continue..."); } return((int)ExitCode.ACDLL_GENERIC_PATCH_ERR); } } else { Console.WriteLine("Assembly-CSharp.dll is already patched!"); return((int)ExitCode.ACDLL_ALREADY_PATCHED); } try { rustAssembly.Write("Assembly-CSharp.dll"); } catch (Exception ex) { Console.WriteLine("An error occured while writing the assembly :"); Console.WriteLine("Error at: " + ex.TargetSite.Name); Console.WriteLine("Error msg: " + ex.Message); if (interactive) { Console.WriteLine("Press any key to continue..."); } return((int)ExitCode.DLL_WRITE_ERROR); } //Successfully patched the server Console.WriteLine("Completed !"); if (interactive) { System.Threading.Thread.Sleep(250); } return((int)ExitCode.SUCCESS); }