Decompiled source of Keep Running v0.1.0

plugins/KeepRunning.dll

Decompiled a week ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyVersion("0.0.0.0")]
namespace KeepRunning;

[BepInProcess("EtG.exe")]
[BepInPlugin("keeprunning.etg", "Keep Running", "0.1.0")]
public class Plugin : BaseUnityPlugin
{
	public const string Guid = "keeprunning.etg";

	public const string Name = "Keep Running";

	public const string ModVersion = "0.1.0";

	public static ConfigEntry<bool> PauseWhenUnfocused;

	public static ConfigEntry<bool> MuteWhenUnfocused;

	private bool originalRunInBackground;

	private void Awake()
	{
		//IL_0050: Unknown result type (might be due to invalid IL or missing references)
		PauseWhenUnfocused = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "PauseWhenUnfocused", false, "Pause the game when you tab out (the game's normal behaviour).");
		MuteWhenUnfocused = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "MuteWhenUnfocused", true, "Silence the game's audio when you tab out (the game's normal behaviour).");
		originalRunInBackground = Application.runInBackground;
		new Harmony("keeprunning.etg").PatchAll(typeof(Patches));
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Keep Running 0.1.0 loaded. Pause when unfocused: " + PauseWhenUnfocused.Value + ", mute when unfocused: " + MuteWhenUnfocused.Value));
	}

	private void Update()
	{
		bool flag = !PauseWhenUnfocused.Value || originalRunInBackground;
		if (Application.runInBackground != flag)
		{
			Application.runInBackground = flag;
		}
	}
}
public static class Patches
{
	private static readonly FieldInfo hasFocus = AccessTools.Field(typeof(GameManager), "m_applicationHasFocus");

	[HarmonyPatch(typeof(GameManager), "OnApplicationFocus")]
	[HarmonyPrefix]
	private static bool BeforeGameFocus(GameManager __instance, bool __0)
	{
		if (Plugin.PauseWhenUnfocused.Value)
		{
			return true;
		}
		hasFocus.SetValue(__instance, __0);
		return false;
	}

	[HarmonyPrefix]
	[HarmonyPatch(typeof(AkSoundEngineController), "ActivateAudio")]
	private static bool BeforeActivateAudio(bool __0)
	{
		if (!__0)
		{
			return Plugin.MuteWhenUnfocused.Value;
		}
		return true;
	}
}