PluginInfo.cs 2.1 KB

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