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 HarmonyLib;
using UnityEngine;
using UnityEngine.Rendering;
using UnityEngine.Rendering.Universal;
[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp-firstpass")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: IgnoresAccessChecksTo("Unity.RenderPipelines.Universal.Runtime")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("MHZ")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCopyright("Copyright © 2026 Masaicker")]
[assembly: AssemblyFileVersion("1.0.4")]
[assembly: AssemblyInformationalVersion("1.0.4")]
[assembly: AssemblyProduct("ClearView")]
[assembly: AssemblyTitle("ClearView")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.4.0")]
[module: UnverifiableCode]
namespace ClearView
{
[BepInPlugin("Mhz.clearview", "ClearView", "1.0.4")]
public class Plugin : BaseUnityPlugin
{
private static ConfigEntry<bool> _fixResolution;
private static ConfigEntry<bool> _disableStyleEffects;
private static ConfigEntry<bool> _disableButo;
private void Awake()
{
_fixResolution = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "FixResolution", true, "Native Resolution Mode (Fixes pixelation and blur) / 原生分辨率高清化 (修复像素感与模糊)");
_disableStyleEffects = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DisableStyleEffects", true, "Atmospheric Clarity (Removes distortion and noise) / 画面通透增强 (移除扭曲与噪点)");
_disableButo = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "DisableButo", true, "Disable Volumetric Fog / 禁用体积雾");
Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
((BaseUnityPlugin)this).Logger.LogInfo((object)"ClearView 1.0.4 (Optimized) Loaded.");
}
private void Start()
{
if (_disableStyleEffects.Value || _disableButo.Value)
{
DisableGarbageFeatures();
}
}
[HarmonyPrefix]
[HarmonyPatch(typeof(PixelPerfectScaler), "ApplyScaling")]
private static bool Prefix(PixelPerfectScaler __instance)
{
//IL_005b: Unknown result type (might be due to invalid IL or missing references)
//IL_0060: Unknown result type (might be due to invalid IL or missing references)
//IL_0077: Unknown result type (might be due to invalid IL or missing references)
//IL_007d: Invalid comparison between Unknown and I4
//IL_014e: Unknown result type (might be due to invalid IL or missing references)
//IL_0150: Unknown result type (might be due to invalid IL or missing references)
//IL_0155: Unknown result type (might be due to invalid IL or missing references)
//IL_015d: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Expected O, but got Unknown
if (!_fixResolution.Value)
{
return true;
}
if ((Object)(object)__instance._rawImage == (Object)null || (Object)(object)__instance._canvas == (Object)null || (Object)(object)__instance._canvasRectTransform == (Object)null)
{
return false;
}
Rect rect = __instance._canvasRectTransform.rect;
float num = ((Rect)(ref rect)).width;
float num2 = ((Rect)(ref rect)).height;
if ((int)__instance._canvas.renderMode == 1 && (Object)(object)__instance._canvas.worldCamera != (Object)null)
{
num = __instance._canvas.worldCamera.pixelWidth;
num2 = __instance._canvas.worldCamera.pixelHeight;
}
if (num <= 0f || num2 <= 0f)
{
return false;
}
__instance._lastCanvasWidth = num;
__instance._lastCanvasHeight = num2;
int num3 = Mathf.RoundToInt(num);
int num4 = Mathf.RoundToInt(num2);
if ((Object)(object)__instance.managedRenderTexture == (Object)null || ((Texture)__instance.managedRenderTexture).width != num3 || ((Texture)__instance.managedRenderTexture).height != num4)
{
__instance.ReleaseAndDestroyRenderTexture();
RenderTextureDescriptor val = default(RenderTextureDescriptor);
((RenderTextureDescriptor)(ref val))..ctor(num3, num4, (RenderTextureFormat)9, 24);
__instance.managedRenderTexture = new RenderTexture(val)
{
filterMode = (FilterMode)1,
name = "ClearView_PerfectRT"
};
__instance.managedRenderTexture.Create();
}
if ((Object)(object)__instance.sourceCamera != (Object)null)
{
__instance.sourceCamera.targetTexture = __instance.managedRenderTexture;
UniversalAdditionalCameraData component = ((Component)__instance.sourceCamera).GetComponent<UniversalAdditionalCameraData>();
if ((Object)(object)component != (Object)null)
{
component.renderPostProcessing = !_disableStyleEffects.Value || !_disableButo.Value;
}
}
__instance._rawImage.texture = (Texture)(object)__instance.managedRenderTexture;
return false;
}
private void DisableGarbageFeatures()
{
RenderPipelineAsset currentRenderPipeline = GraphicsSettings.currentRenderPipeline;
UniversalRenderPipelineAsset val = (UniversalRenderPipelineAsset)(object)((currentRenderPipeline is UniversalRenderPipelineAsset) ? currentRenderPipeline : null);
if ((Object)(object)val == (Object)null)
{
return;
}
ScriptableRendererData[] rendererDataList = val.m_RendererDataList;
if (rendererDataList == null)
{
return;
}
ScriptableRendererData[] array = rendererDataList;
foreach (ScriptableRendererData val2 in array)
{
if ((Object)(object)val2 == (Object)null)
{
continue;
}
foreach (ScriptableRendererFeature rendererFeature in val2.rendererFeatures)
{
if ((Object)(object)rendererFeature == (Object)null)
{
continue;
}
string name = ((Object)rendererFeature).name;
if (1 == 0)
{
}
bool flag;
if (name == "ButoRenderFeature")
{
flag = _disableButo.Value;
}
else
{
string text = ((Object)rendererFeature).name.ToLowerInvariant();
if (1 == 0)
{
}
bool flag2;
if (text.Contains("vhs"))
{
flag2 = true;
}
else
{
string text2 = text;
if (text2.Contains("lowres"))
{
flag2 = true;
}
else
{
string text3 = text;
if (text3.Contains("beautify"))
{
flag2 = true;
}
else
{
string text4 = text;
if (text4.Contains("haze"))
{
flag2 = true;
}
else
{
string text5 = text;
flag2 = (text5.Contains("scattering") ? true : false);
}
}
}
}
if (1 == 0)
{
}
flag = flag2;
}
if (1 == 0)
{
}
if (flag)
{
rendererFeature.SetActive(false);
}
}
}
}
}
}
namespace System.Runtime.CompilerServices
{
[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
internal sealed class IgnoresAccessChecksToAttribute : Attribute
{
public IgnoresAccessChecksToAttribute(string assemblyName)
{
}
}
}