PluginInfo.cs 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. using System.Collections.Generic;
  2. using System.IO;
  3. using System.Linq;
  4. using BepInEx.Bootstrap;
  5. namespace BepInEx.Contract
  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 string Location { get; internal set; }
  13. public BaseUnityPlugin Instance { get; internal set; }
  14. internal string TypeName { get; set; }
  15. void ICacheable.Save(BinaryWriter bw)
  16. {
  17. bw.Write(TypeName);
  18. bw.Write(Metadata.GUID);
  19. bw.Write(Metadata.Name);
  20. bw.Write(Metadata.Version.ToString());
  21. var processList = Processes.ToList();
  22. bw.Write(processList.Count);
  23. foreach (var bepInProcess in processList)
  24. bw.Write(bepInProcess.ProcessName);
  25. var depList = Dependencies.ToList();
  26. bw.Write(depList.Count);
  27. foreach (var bepInDependency in depList)
  28. ((ICacheable)bepInDependency).Save(bw);
  29. }
  30. void ICacheable.Load(BinaryReader br)
  31. {
  32. TypeName = br.ReadString();
  33. Metadata = new BepInPlugin(br.ReadString(), br.ReadString(), br.ReadString());
  34. var processListCount = br.ReadInt32();
  35. var processList = new List<BepInProcess>(processListCount);
  36. for (int i = 0; i < processListCount; i++)
  37. processList.Add(new BepInProcess(br.ReadString()));
  38. Processes = processList;
  39. var depCount = br.ReadInt32();
  40. var depList = new List<BepInDependency>(depCount);
  41. for (int i = 0; i < depCount; i++)
  42. {
  43. var dep = new BepInDependency("");
  44. ((ICacheable)dep).Load(br);
  45. depList.Add(dep);
  46. }
  47. Dependencies = depList;
  48. }
  49. }
  50. }