PatcherPlugin.cs 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using BepInEx.Bootstrap;
  5. namespace BepInEx.Preloader.Patching
  6. {
  7. /// <summary>
  8. /// A single assembly patcher.
  9. /// </summary>
  10. internal class PatcherPlugin : ICacheable
  11. {
  12. /// <summary>
  13. /// Target assemblies to patch.
  14. /// </summary>
  15. public Func<IEnumerable<string>> TargetDLLs { get; set; } = null;
  16. /// <summary>
  17. /// Initializer method that is run before any patching occurs.
  18. /// </summary>
  19. public Action Initializer { get; set; } = null;
  20. /// <summary>
  21. /// Finalizer method that is run after all patching is done.
  22. /// </summary>
  23. public Action Finalizer { get; set; } = null;
  24. /// <summary>
  25. /// The main patcher method that is called on every DLL defined in <see cref="TargetDLLs" />.
  26. /// </summary>
  27. public AssemblyPatcherDelegate Patcher { get; set; } = null;
  28. /// <summary>
  29. /// Type name of the patcher.
  30. /// </summary>
  31. public string TypeName { get; set; } = string.Empty;
  32. public void Save(BinaryWriter bw)
  33. {
  34. bw.Write(TypeName);
  35. }
  36. public void Load(BinaryReader br)
  37. {
  38. TypeName = br.ReadString();
  39. }
  40. }
  41. }