using System; using System.Diagnostics; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Security; using System.Security.Permissions; using BepInEx; using BepInEx.Configuration; using BepInEx.Logging; using HarmonyLib; using Microsoft.CodeAnalysis; using Silksong.ModMenu.Plugin; using UnityEngine; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")] [assembly: AssemblyCompany("BackgroundBlurImproved")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("0.8.1.0")] [assembly: AssemblyInformationalVersion("0.8.1+3ea918683b3f7e359b8b7c9f73fb6b61de4356c4")] [assembly: AssemblyProduct("BackgroundBlurImproved")] [assembly: AssemblyTitle("BackgroundBlurImproved")] [assembly: AssemblyMetadata("RepositoryUrl", "https://github.com/alexkiri/BackgroundBlurImprovedPlugin")] [assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)] [assembly: AssemblyVersion("0.8.1.0")] [module: UnverifiableCode] [module: RefSafetyRules(11)] namespace System.Runtime.CompilerServices { [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [Microsoft.CodeAnalysis.Embedded] [AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)] internal sealed class RefSafetyRulesAttribute : Attribute { public readonly int Version; public RefSafetyRulesAttribute(int P_0) { Version = P_0; } } } internal sealed class ConfigurationManagerAttributes { public delegate void CustomHotkeyDrawerFunc(ConfigEntryBase setting, ref bool isCurrentlyAcceptingInput); public bool? ShowRangeAsPercent; public Action CustomDrawer; public CustomHotkeyDrawerFunc CustomHotkeyDrawer; public bool? Browsable; public string Category; public object DefaultValue; public bool? HideDefaultButton; public bool? HideSettingName; public string Description; public string DispName; public int? Order; public bool? ReadOnly; public bool? IsAdvanced; public Func ObjToStr; public Func StrToObj; } namespace BepInEx { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] [Microsoft.CodeAnalysis.Embedded] internal sealed class BepInAutoPluginAttribute : Attribute { public BepInAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace BepInEx.Preloader.Core.Patching { [AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)] [Conditional("CodeGeneration")] [Microsoft.CodeAnalysis.Embedded] internal sealed class PatcherAutoPluginAttribute : Attribute { public PatcherAutoPluginAttribute(string? id = null, string? name = null, string? version = null) { } } } namespace Microsoft.CodeAnalysis { [Microsoft.CodeAnalysis.Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace BackgroundBlurImproved { [BepInDependency("org.silksong-modding.modmenu", "0.7.4")] [BepInPlugin("io.github.alexkiri.backgroundblurimproved", "BackgroundBlurImproved", "0.8.1")] public class BackgroundBlurImprovedPlugin : BaseUnityPlugin { internal static ManualLogSource Log; private readonly Harmony harmony = new Harmony("io.github.alexkiri.backgroundblurimproved"); private bool isApplyingPreset; public static ConfigEntry blurRenderTextureHeightConfigEntry; public static ConfigEntry blurPassGroupCountConfigEntry; public static ConfigEntry blurEnableConfigEntry; public static ConfigEntry presetConfigEntry; public static ConfigEntry bloomOptimizedResolutionConfig; public static ConfigEntry bloomOptimizedBlurIterationsConfig; public static LightBlurredBackground? lightBlurredBackground; public static BloomOptimized? bloomOptimized; public const string Id = "io.github.alexkiri.backgroundblurimproved"; public static string Name => "BackgroundBlurImproved"; public static string Version => "0.8.1"; public static void ApplyBlurredBackgroundSettings() { int value = (int)blurRenderTextureHeightConfigEntry.Value; int value2 = blurPassGroupCountConfigEntry.Value; bool value3 = blurEnableConfigEntry.Value; if ((Object)(object)lightBlurredBackground != (Object)null) { Log.LogInfo((object)$"will apply settings for {lightBlurredBackground} RenderTextureHeight: {lightBlurredBackground.renderTextureHeight}->{value} PassGroupCount: {lightBlurredBackground.passGroupCount}->{value2}"); ((Behaviour)lightBlurredBackground.lightBlur).enabled = true; lightBlurredBackground.RenderTextureHeight = value; lightBlurredBackground.PassGroupCount = value2; ((Behaviour)lightBlurredBackground).enabled = false; ((Behaviour)lightBlurredBackground).enabled = true; ((Behaviour)lightBlurredBackground.lightBlur).enabled = value3; } } public static void ApplyBloomOptimizedSettings() { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0080: Unknown result type (might be due to invalid IL or missing references) //IL_0081: Unknown result type (might be due to invalid IL or missing references) Resolution value = bloomOptimizedResolutionConfig.Value; int value2 = bloomOptimizedBlurIterationsConfig.Value; if ((Object)(object)bloomOptimized != (Object)null) { Log.LogInfo((object)$"will apply settings for {bloomOptimized} resolution: {bloomOptimized.resolution}->{value} blurIterations: {bloomOptimized.blurIterations}->{value2}"); bloomOptimized.resolution = value; bloomOptimized.blurIterations = value2; } } private void Awake() { //IL_004b: Unknown result type (might be due to invalid IL or missing references) //IL_0055: Expected O, but got Unknown //IL_00b0: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Expected O, but got Unknown //IL_0106: Unknown result type (might be due to invalid IL or missing references) //IL_0110: Expected O, but got Unknown //IL_017a: Unknown result type (might be due to invalid IL or missing references) //IL_0184: Expected O, but got Unknown //IL_0214: Unknown result type (might be due to invalid IL or missing references) //IL_021e: Expected O, but got Unknown Log = ((BaseUnityPlugin)this).Logger; harmony.PatchAll(); blurRenderTextureHeightConfigEntry = ((BaseUnityPlugin)this).Config.Bind("BlurredBackground", "BlurTextureHeight", BlurHeight.Medium720, new ConfigDescription("Height of the BlurredBackground layer. Improves quality, lowers effect intensity.", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = 3 } })); blurRenderTextureHeightConfigEntry.SettingChanged += delegate { if (!isApplyingPreset) { presetConfigEntry.Value = BlurPreset.Custom; } ApplyBlurredBackgroundSettings(); }; blurPassGroupCountConfigEntry = ((BaseUnityPlugin)this).Config.Bind("BlurredBackground", "BlurPassCount", 4, new ConfigDescription("Number of blur effect passes. Medium / heavy performance impact.", (AcceptableValueBase)(object)new AcceptableValueRange(1, 16), new object[2] { new ConfigurationManagerAttributes { Order = 2 }, MenuElementGenerators.CreateIntSliderGenerator() })); blurPassGroupCountConfigEntry.SettingChanged += delegate { if (!isApplyingPreset) { presetConfigEntry.Value = BlurPreset.Custom; } ApplyBlurredBackgroundSettings(); }; blurEnableConfigEntry = ((BaseUnityPlugin)this).Config.Bind("BlurredBackground", "BlurEffectEnabled", true, new ConfigDescription("Uncheck to completely disable the blur effect.", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { Order = 1 } })); blurEnableConfigEntry.SettingChanged += delegate { bool value = blurEnableConfigEntry.Value; Log.LogInfo((object)$"blurEnableConfigEntry.SettingChanged -> {value}"); if (!isApplyingPreset) { presetConfigEntry.Value = BlurPreset.Custom; } if ((Object)(object)lightBlurredBackground != (Object)null) { ((Behaviour)lightBlurredBackground.lightBlur).enabled = value; } }; presetConfigEntry = ((BaseUnityPlugin)this).Config.Bind("BlurredBackground", "ApplyBlurPreset", BlurPreset.Medium, new ConfigDescription("Pick any predefined preset.", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { HideDefaultButton = true, CustomDrawer = PresetsCustomDrawer, Order = 4 } })); presetConfigEntry.SettingChanged += delegate { ApplyPreset(presetConfigEntry.Value); }; bloomOptimizedResolutionConfig = ((BaseUnityPlugin)this).Config.Bind("Bloom", "BloomResolution", (Resolution)0, "Resolution of the Bloom effect."); bloomOptimizedResolutionConfig.SettingChanged += delegate { ApplyBloomOptimizedSettings(); }; bloomOptimizedBlurIterationsConfig = ((BaseUnityPlugin)this).Config.Bind("Bloom", "BloomBlurIterations", 1, new ConfigDescription("Number of iterations for the Bloom effect.", (AcceptableValueBase)(object)new AcceptableValueRange(1, 16), new object[1] { MenuElementGenerators.CreateIntSliderGenerator() })); bloomOptimizedBlurIterationsConfig.SettingChanged += delegate { ApplyBloomOptimizedSettings(); }; GameCameras instance = GameCameras.instance; if ((Object)(object)instance != (Object)null) { Log.LogInfo((object)$"Existing GameCameras object found {instance}"); LightBlurredBackground component = ((Component)instance).GetComponent(); if ((Object)(object)component != (Object)null) { Log.LogInfo((object)$"Existing LightBlurredBackground object found {component}"); lightBlurredBackground = component; ApplyBlurredBackgroundSettings(); } BloomOptimized component2 = ((Component)instance.tk2dCam).GetComponent(); if ((Object)(object)component2 != (Object)null) { Log.LogInfo((object)$"Existing BloomOptimized object found {component2}"); bloomOptimized = component2; ApplyBloomOptimizedSettings(); } } UIManager instance2 = UIManager.instance; if ((Object)(object)instance2 != (Object)null) { Log.LogInfo((object)$"Existing UIManager object found {instance2}"); CustomizeMenu(instance2); } Log.LogInfo((object)("Plugin " + Name + " (io.github.alexkiri.backgroundblurimproved) has loaded!")); } private void OnDestroy() { harmony.UnpatchSelf(); lightBlurredBackground = null; Log.LogInfo((object)("Plugin " + Name + " (io.github.alexkiri.backgroundblurimproved) has unloaded!")); } private void ApplyPreset(BlurPreset preset) { isApplyingPreset = true; try { switch (preset) { case BlurPreset.Vanilla: blurEnableConfigEntry.Value = true; blurRenderTextureHeightConfigEntry.Value = BlurHeight.Vanilla360; blurPassGroupCountConfigEntry.Value = 2; break; case BlurPreset.Medium: blurEnableConfigEntry.Value = true; blurRenderTextureHeightConfigEntry.Value = BlurHeight.Medium720; blurPassGroupCountConfigEntry.Value = 4; break; case BlurPreset.High: blurEnableConfigEntry.Value = true; blurRenderTextureHeightConfigEntry.Value = BlurHeight.High1080; blurPassGroupCountConfigEntry.Value = 6; break; case BlurPreset.VeryHigh: blurEnableConfigEntry.Value = true; blurRenderTextureHeightConfigEntry.Value = BlurHeight.Veryhigh1440; blurPassGroupCountConfigEntry.Value = 8; break; } } finally { isApplyingPreset = false; } } private void PresetsCustomDrawer(ConfigEntryBase configEntry) { if (GUILayout.Button(BlurPreset.Vanilla.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) })) { presetConfigEntry.Value = BlurPreset.Vanilla; } if (GUILayout.Button(BlurPreset.Medium.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) })) { presetConfigEntry.Value = BlurPreset.Medium; } if (GUILayout.Button(BlurPreset.High.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) })) { presetConfigEntry.Value = BlurPreset.High; } if (GUILayout.Button(BlurPreset.VeryHigh.ToString(), (GUILayoutOption[])(object)new GUILayoutOption[1] { GUILayout.ExpandWidth(true) })) { presetConfigEntry.Value = BlurPreset.VeryHigh; } } public static void CustomizeMenu(UIManager um) { Transform val = ((Component)um.advancedVideoMenuScreen).transform.Find("Content/ShaderSetting"); if (!((Object)(object)val == (Object)null)) { ((Component)val).gameObject.SetActive(false); } } } public enum BlurHeight { Verylow240 = 240, Verylow270 = 270, Vanilla360 = 360, Low480 = 480, Low540 = 540, Medium600 = 600, Medium720 = 720, High900 = 900, High1080 = 1080, Veryhigh1280 = 1280, Veryhigh1440 = 1440, Ultrahigh1800 = 1800, Ultrahigh2160 = 2160 } public enum BlurPreset { Vanilla, Medium, High, VeryHigh, Custom } [HarmonyPatch] public class Patcher { private static readonly ManualLogSource Log = BackgroundBlurImprovedPlugin.Log; [HarmonyPatch(typeof(BlurManager), "Awake")] [HarmonyPostfix] private static void BlurManager_Awake(BlurManager __instance) { int value = (int)BackgroundBlurImprovedPlugin.blurRenderTextureHeightConfigEntry.Value; Log.LogDebug((object)$"BlurManager.Awake() called on {__instance}[{((object)__instance).GetHashCode()}] baseHeight: {__instance.baseHeight} -> {value}"); __instance.baseHeight = value; BackgroundBlurImprovedPlugin.lightBlurredBackground = __instance.lightBlurredBackground; } [HarmonyPatch(typeof(BlurManager), "Update")] [HarmonyPrefix] private static void BlurManager_Update(BlurManager __instance) { //IL_0015: Unknown result type (might be due to invalid IL or missing references) //IL_001a: Unknown result type (might be due to invalid IL or missing references) //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_001d: Unknown result type (might be due to invalid IL or missing references) GameManager instance = GameManager.instance; if ((Object)(object)instance != (Object)null) { ShaderQualities shaderQuality = instance.gameSettings.shaderQuality; __instance.appliedShaderQuality = shaderQuality; } } [HarmonyPatch(typeof(LightBlurredBackground), "Awake")] [HarmonyPostfix] private static void LightBlurredBackground_Awake(LightBlurredBackground __instance) { int value = (int)BackgroundBlurImprovedPlugin.blurRenderTextureHeightConfigEntry.Value; int value2 = BackgroundBlurImprovedPlugin.blurPassGroupCountConfigEntry.Value; Log.LogDebug((object)$"LightBlurredBackground.Awake called on {__instance}[{((object)__instance).GetHashCode()}], renderTextureHeight: {__instance.renderTextureHeight} -> {value}, passGroupCount: {__instance.passGroupCount} -> {value2}"); __instance.passGroupCount = value2; __instance.renderTextureHeight = value; } [HarmonyPatch(typeof(LightBlur), "Awake")] [HarmonyPrefix] private static void LightBlur_Awake(LightBlur __instance) { bool value = BackgroundBlurImprovedPlugin.blurEnableConfigEntry.Value; Log.LogDebug((object)$"LightBlur.Awake called on {__instance}[{((object)__instance).GetHashCode()}], will enable {value}"); ((Behaviour)__instance).enabled = value; } [HarmonyPatch(typeof(BloomOptimized), "Awake")] [HarmonyPostfix] private static void BloomOptimized_Awake(BloomOptimized __instance) { Log.LogDebug((object)$"BloomOptimized.Awake called on {__instance}[{((object)__instance).GetHashCode()}]"); BackgroundBlurImprovedPlugin.bloomOptimized = __instance; BackgroundBlurImprovedPlugin.ApplyBloomOptimizedSettings(); } [HarmonyPatch(typeof(UIManager), "Awake")] [HarmonyPostfix] public static void UIManager_Awake(UIManager __instance) { Log.LogDebug((object)$"UIManager.Awake called on {__instance}[{((object)__instance).GetHashCode()}]"); BackgroundBlurImprovedPlugin.CustomizeMenu(__instance); } } }