PluginInfo.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  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(Location);
  22. bw.Write(Metadata.GUID);
  23. bw.Write(Metadata.Name);
  24. bw.Write(Metadata.Version.ToString());
  25. var processList = Processes.ToList();
  26. bw.Write(processList.Count);
  27. foreach (var bepInProcess in processList)
  28. bw.Write(bepInProcess.ProcessName);
  29. var depList = Dependencies.ToList();
  30. bw.Write(depList.Count);
  31. foreach (var bepInDependency in depList)
  32. ((ICacheable)bepInDependency).Save(bw);
  33. var incList = Incompatibilities.ToList();
  34. bw.Write(incList.Count);
  35. foreach (var bepInIncompatibility in incList)
  36. ((ICacheable)bepInIncompatibility).Save(bw);
  37. bw.Write(TargettedBepInExVersion.ToString(4));
  38. }
  39. void ICacheable.Load(BinaryReader br)
  40. {
  41. TypeName = br.ReadString();
  42. Location = br.ReadString();
  43. Metadata = new BepInPlugin(br.ReadString(), br.ReadString(), br.ReadString());
  44. var processListCount = br.ReadInt32();
  45. var processList = new List<BepInProcess>(processListCount);
  46. for (int i = 0; i < processListCount; i++)
  47. processList.Add(new BepInProcess(br.ReadString()));
  48. Processes = processList;
  49. var depCount = br.ReadInt32();
  50. var depList = new List<BepInDependency>(depCount);
  51. for (int i = 0; i < depCount; i++)
  52. {
  53. var dep = new BepInDependency("");
  54. ((ICacheable)dep).Load(br);
  55. depList.Add(dep);
  56. }
  57. Dependencies = depList;
  58. var incCount = br.ReadInt32();
  59. var incList = new List<BepInIncompatibility>(incCount);
  60. for (int i = 0; i < incCount; i++)
  61. {
  62. var inc = new BepInIncompatibility("");
  63. ((ICacheable)inc).Load(br);
  64. incList.Add(inc);
  65. }
  66. Incompatibilities = incList;
  67. TargettedBepInExVersion = new Version(br.ReadString());
  68. }
  69. }
  70. }