PatcherPlugin.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using BepInEx.Bootstrap;
  5. namespace BepInEx.Preloader.Core
  6. {
  7. /// <summary>
  8. /// A single assembly patcher.
  9. /// </summary>
  10. public 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. /// <inheritdoc />
  33. public void Save(BinaryWriter bw)
  34. {
  35. bw.Write(TypeName);
  36. }
  37. /// <inheritdoc />
  38. public void Load(BinaryReader br)
  39. {
  40. TypeName = br.ReadString();
  41. }
  42. }
  43. }