BepInComponent.cs 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Linq;
  5. using System.Text;
  6. using System.Text.RegularExpressions;
  7. using TMPro;
  8. using UnityEngine;
  9. using UnityEngine.SceneManagement;
  10. namespace BepInEx
  11. {
  12. //Adapted from https://github.com/Eusth/IPA/blob/0df8b1ecb87fdfc9e169365cb4a8fd5a909a2ad6/IllusionInjector/PluginComponent.cs
  13. public class BepInComponent : MonoBehaviour
  14. {
  15. List<BaseUnityPlugin> Plugins;
  16. private bool quitting = false;
  17. public static GameObject Create()
  18. {
  19. var obj = new GameObject("BepInEx_Manager");
  20. var manager = obj.AddComponent<BepInComponent>();
  21. manager.Plugins = new List<BaseUnityPlugin>();
  22. foreach (Type t in Chainloader.Plugins)
  23. manager.Plugins.Add((BaseUnityPlugin)obj.AddComponent(t));
  24. return obj;
  25. }
  26. void Awake()
  27. {
  28. DontDestroyOnLoad(gameObject);
  29. }
  30. void Start()
  31. {
  32. Console.WriteLine("Component ready");
  33. }
  34. void OnDestroy()
  35. {
  36. if (!quitting)
  37. {
  38. Create();
  39. }
  40. }
  41. void OnApplicationQuit()
  42. {
  43. quitting = true;
  44. }
  45. }
  46. }