PluginInfo.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 string Location { get; internal set; }
  13. public BaseUnityPlugin Instance { get; internal set; }
  14. internal string TypeName { get; set; }
  15. public void 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. {
  29. bw.Write(bepInDependency.DependencyGUID);
  30. bw.Write((int)bepInDependency.Flags);
  31. }
  32. }
  33. public void Load(BinaryReader br)
  34. {
  35. TypeName = br.ReadString();
  36. Metadata = new BepInPlugin(br.ReadString(), br.ReadString(), br.ReadString());
  37. var processListCount = br.ReadInt32();
  38. var processList = new List<BepInProcess>(processListCount);
  39. for (int i = 0; i < processListCount; i++)
  40. processList.Add(new BepInProcess(br.ReadString()));
  41. Processes = processList;
  42. var depCount = br.ReadInt32();
  43. var depList = new List<BepInDependency>(depCount);
  44. for (int i = 0; i < depCount; i++)
  45. depList.Add(new BepInDependency(br.ReadString(), (BepInDependency.DependencyFlags) br.ReadInt32()));
  46. Dependencies = depList;
  47. }
  48. }
  49. }