PluginInfo.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using BepInEx.Bootstrap;
  6. namespace BepInEx
  7. {
  8. public class PluginInfo : ICacheable
  9. {
  10. public BepInPlugin Metadata { get; internal set; }
  11. public IEnumerable<BepInProcess> Processes { get; internal set; }
  12. public IEnumerable<BepInDependency> Dependencies { get; internal set; }
  13. public IEnumerable<BepInIncompatibility> Incompatibilities { get; internal set; }
  14. public string Location { get; internal set; }
  15. public object Instance { get; internal set; }
  16. public string TypeName { get; internal set; }
  17. internal Version TargettedBepInExVersion { get; set; }
  18. void ICacheable.Save(BinaryWriter bw)
  19. {
  20. bw.Write(TypeName);
  21. bw.Write(Metadata.GUID);
  22. bw.Write(Metadata.Name);
  23. bw.Write(Metadata.Version.ToString());
  24. var processList = Processes.ToList();
  25. bw.Write(processList.Count);
  26. foreach (var bepInProcess in processList)
  27. bw.Write(bepInProcess.ProcessName);
  28. var depList = Dependencies.ToList();
  29. bw.Write(depList.Count);
  30. foreach (var bepInDependency in depList)
  31. ((ICacheable)bepInDependency).Save(bw);
  32. var incList = Incompatibilities.ToList();
  33. bw.Write(incList.Count);
  34. foreach (var bepInIncompatibility in incList)
  35. ((ICacheable)bepInIncompatibility).Save(bw);
  36. bw.Write(TargettedBepInExVersion.ToString(4));
  37. }
  38. void ICacheable.Load(BinaryReader br)
  39. {
  40. TypeName = br.ReadString();
  41. Metadata = new BepInPlugin(br.ReadString(), br.ReadString(), br.ReadString());
  42. var processListCount = br.ReadInt32();
  43. var processList = new List<BepInProcess>(processListCount);
  44. for (int i = 0; i < processListCount; i++)
  45. processList.Add(new BepInProcess(br.ReadString()));
  46. Processes = processList;
  47. var depCount = br.ReadInt32();
  48. var depList = new List<BepInDependency>(depCount);
  49. for (int i = 0; i < depCount; i++)
  50. {
  51. var dep = new BepInDependency("");
  52. ((ICacheable)dep).Load(br);
  53. depList.Add(dep);
  54. }
  55. Dependencies = depList;
  56. var incCount = br.ReadInt32();
  57. var incList = new List<BepInIncompatibility>(incCount);
  58. for (int i = 0; i < incCount; i++)
  59. {
  60. var inc = new BepInIncompatibility("");
  61. ((ICacheable)inc).Load(br);
  62. incList.Add(inc);
  63. }
  64. Incompatibilities = incList;
  65. TargettedBepInExVersion = new Version(br.ReadString());
  66. }
  67. }
  68. }