Exemplo n.º 1
0
        static bool OnToggle(UnityModManager.ModEntry modEntry, bool value)
        {
            Main.modEntry = modEntry;
            if (enabled == value)
            {
                return(true);
            }
            enabled = value;

            if (enabled)
            {
                // disable if xlshredmenu is detected
                var mod = UnityModManager.FindMod("blendermf.XLShredMenu");
                if (mod != null)
                {
                    modEntry.CustomRequirements = $"Mod {mod.Info.DisplayName} incompatible";
                    enabled = false;
                    return(false);
                }
                harmony = new Harmony(modEntry.Info.Id);
                harmony.PatchAll(Assembly.GetExecutingAssembly());

                if (XLGraphicsMenu.Instance == null)
                {
                    if (uiBundle == null)
                    {
                        uiBundle = AssetBundle.LoadFromFile(modEntry.Path + "graphicsmenuassetbundle");
                    }

                    GameObject newMenuObject = GameObject.Instantiate(uiBundle.LoadAsset <GameObject>("Assets/Prefabs/Menu.prefab"));
                    GameObject.DontDestroyOnLoad(newMenuObject);

                    menu = XLGraphicsMenu.Instance;

                    xlGraphics = new GameObject().AddComponent <XLGraphics>();
                    GameObject.DontDestroyOnLoad(xlGraphics.gameObject);

                    Cursor.visible   = true;
                    Cursor.lockState = CursorLockMode.None;
                }
            }
            else
            {
                harmony.UnpatchAll(harmony.Id);
                GameObject.Destroy(xlGraphics.gameObject);
                xlGraphics = null;
            }
            return(true);
        }
Exemplo n.º 2
0
        static bool OnToggle(UnityModManager.ModEntry modEntry, bool value)
        {
            Main.Logger.Log("OnToggle " + value.ToString());
            if (enabled == value)
            {
                return(true);
            }

            enabled = value;

            if (value)
            {
                // disable if xlshredmenu is detected
                var mod = UnityModManager.FindMod("blendermf.XLShredMenu");
                if (mod != null)
                {
                    modEntry.CustomRequirements = $"Mod {mod.Info.DisplayName} incompatible";
                    enabled = false;
                    return(false);
                }

                // create harmony instance
                harmony = new Harmony(modEntry.Info.Id);

                // patch
                harmony.PatchAll(Assembly.GetExecutingAssembly());

                // instantiate menu and XLGraphics monobehaviour
                GameObject menuGO = GameObject.Instantiate(menuObjectAsset);
                menu       = XLGraphicsMenu.Instance;
                xlGraphics = new GameObject().AddComponent <XLGraphics>();
                GameObject.DontDestroyOnLoad(menuGO);
                GameObject.DontDestroyOnLoad(xlGraphics.gameObject);
            }
            else
            {
                // unpatch
                harmony.UnpatchAll(harmony.Id);

                // destroy menu and XLGraphics monobehaviour
                GameObject.DestroyImmediate(menu.gameObject);
                GameObject.DestroyImmediate(xlGraphics.gameObject);
            }
            Main.Logger.Log("Loaded");
            return(true);
        }