0 of 0

File information

Last updated

Original upload

Created by

aiTookMyJob

Uploaded by

aiTookMyJob

Virus scan

Safe to use

About this mod

Pause the game when you open your inventory.

Permissions and credits
Changelogs
Donations
Pause the game when you open your inventory.

using BepInEx;
using HarmonyLib;
using UnityEngine;
using System.Collections;

namespace InventoryPause
{
    [BepInPlugin("innocreator.inventorypause", "InventoryPause", "3.0")]
    [BepInProcess("valheim.exe")]
    public class InventoryPause : BaseUnityPlugin
    {
        private readonly Harmony harmony = new Harmony("innocreator.inventorypause");

        void Awake()
        {
            harmony.PatchAll();
        }

        [HarmonyPatch(typeof(InventoryGui), nameof(InventoryGui.Show))]
        public static class InventoryPause_Show
        {
            static void Prefix()
            {
                if (Game.IsPaused())
                    return;

                GameObject.FindObjectOfType<MonoBehaviour>().StartCoroutine(PauseAfterHalfSecond());
            }

            static IEnumerator PauseAfterHalfSecond()
            {
                if (!Game.IsPaused())
                {
                    yield return new WaitForSecondsRealtime(0.4f);
                    Game.Pause();
                }
            }
        }

        [HarmonyPatch(typeof(InventoryGui), nameof(InventoryGui.Hide))]
        public static class InventoryPause_Hide
        {
            static void Prefix()
            {
                if (!Game.IsPaused())
                    return;

                Game.Unpause();
            }
        }

        [HarmonyPatch(typeof(InventoryGui), "OnCraftPressed")]
        public static class InventoryPause_OnCraftPressed
        {
            static void Prefix()
            {
                if (!Game.IsPaused())
                    return;

                Game.Unpause();
            }
        }

        [HarmonyPatch(typeof(Player), "QueueEquipAction")]
        public static class InventoryPause_QueueEquipAction
        {
            static void Prefix()
            {
                if (!Game.IsPaused())
                    return;

                Game.Unpause();
            }
        }
    }
}