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 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.7")]
[assembly: AssemblyInformationalVersion("1.0.7")]
[assembly: AssemblyProduct("ClearView")]
[assembly: AssemblyTitle("ClearView")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.7.0")]
[module: UnverifiableCode]
namespace ClearView
{
[BepInPlugin("Mhz.clearview", "ClearView", "1.0.7")]
public class Plugin : BaseUnityPlugin
{
private static ConfigEntry<bool> _fixResolution;
private static ConfigEntry<float> _resScale;
private static ConfigEntry<bool> _disableStyleEffects;
private static ConfigEntry<bool> _disableButo;
private void Awake()
{
//IL_004f: Unknown result type (might be due to invalid IL or missing references)
//IL_0059: Expected O, but got Unknown
_fixResolution = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "FixResolution", true, "Enable Resolution Enhancement / 启用分辨率增强开关\nIf disabled, the game will use vanilla pixelated rendering. / 如果禁用,游戏将使用原版像素化渲染。");
_resScale = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ResolutionScale", 0.625f, new ConfigDescription("Resolution Scale (0.35 to 1.0): Balance between visual quality and GPU performance. Active only when 'FixResolution' is true.\n1.0 = Maximum Clarity (Highest GPU load)\n0.6 = High Quality (Good balance)\n0.35 = Performance Mode (Lower load, more pixelated)\n\n分辨率缩放 (0.35 - 1.0): 在画质与 GPU 性能之间取得平衡。仅在 'FixResolution' 为 true 时生效。\n1.0 = 极致清晰 (显卡负载最高)\n0.6 = 高画质 (清晰与性能平衡)\n0.35 = 性能模式 (低负载,较强像素感)", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.35f, 1f), Array.Empty<object>()));
_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.5 (Advanced) 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_013b: Unknown result type (might be due to invalid IL or missing references)
//IL_0197: Unknown result type (might be due to invalid IL or missing references)
//IL_01c4: Unknown result type (might be due to invalid IL or missing references)
//IL_01c6: Unknown result type (might be due to invalid IL or missing references)
//IL_01c9: Unknown result type (might be due to invalid IL or missing references)
//IL_01cb: Unknown result type (might be due to invalid IL or missing references)
//IL_01d0: Unknown result type (might be due to invalid IL or missing references)
//IL_016e: Unknown result type (might be due to invalid IL or missing references)
//IL_0173: Unknown result type (might be due to invalid IL or missing references)
//IL_0326: Unknown result type (might be due to invalid IL or missing references)
//IL_0333: Unknown result type (might be due to invalid IL or missing references)
//IL_0340: Unknown result type (might be due to invalid IL or missing references)
//IL_034d: Unknown result type (might be due to invalid IL or missing references)
//IL_035a: Unknown result type (might be due to invalid IL or missing references)
//IL_01ec: Unknown result type (might be due to invalid IL or missing references)
//IL_01f8: Unknown result type (might be due to invalid IL or missing references)
//IL_0205: Expected O, but got Unknown
//IL_02f4: Unknown result type (might be due to invalid IL or missing references)
//IL_02fa: Invalid comparison between Unknown and I4
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;
}
int num3 = Mathf.Max(1, Mathf.RoundToInt(num * _resScale.Value));
int num4 = Mathf.Max(1, Mathf.RoundToInt(num2 * _resScale.Value));
bool flag = !_disableStyleEffects.Value || !_disableButo.Value;
RenderTextureFormat val = (RenderTextureFormat)(flag ? 9 : 0);
if ((Object)(object)__instance.managedRenderTexture == (Object)null || ((Texture)__instance.managedRenderTexture).width != num3 || ((Texture)__instance.managedRenderTexture).height != num4 || __instance.managedRenderTexture.format != val)
{
__instance.ReleaseAndDestroyRenderTexture();
RenderTextureDescriptor val2 = default(RenderTextureDescriptor);
((RenderTextureDescriptor)(ref val2))..ctor(num3, num4, val, 24);
((RenderTextureDescriptor)(ref val2)).msaaSamples = 1;
((RenderTextureDescriptor)(ref val2)).useMipMap = false;
((RenderTextureDescriptor)(ref val2)).autoGenerateMips = false;
((RenderTextureDescriptor)(ref val2)).useDynamicScale = false;
RenderTextureDescriptor val3 = val2;
__instance.managedRenderTexture = new RenderTexture(val3)
{
filterMode = (FilterMode)(!(_resScale.Value >= 0.99f)),
name = "ClearView_DynamicRT",
anisoLevel = 0
};
__instance.managedRenderTexture.Create();
}
__instance._lastCanvasWidth = ((Rect)(ref rect)).width;
__instance._lastCanvasHeight = ((Rect)(ref rect)).height;
if ((Object)(object)__instance.sourceCamera != (Object)null)
{
if ((Object)(object)__instance.sourceCamera.targetTexture != (Object)(object)__instance.managedRenderTexture)
{
__instance.sourceCamera.targetTexture = __instance.managedRenderTexture;
}
if (__instance.sourceCamera.allowHDR != flag)
{
__instance.sourceCamera.allowHDR = flag;
}
if (__instance.sourceCamera.allowMSAA)
{
__instance.sourceCamera.allowMSAA = false;
}
UniversalAdditionalCameraData component = ((Component)__instance.sourceCamera).GetComponent<UniversalAdditionalCameraData>();
if ((Object)(object)component != (Object)null)
{
bool flag2 = flag;
if (component.renderPostProcessing != flag2)
{
component.renderPostProcessing = flag2;
}
if ((int)component.antialiasing > 0)
{
component.antialiasing = (AntialiasingMode)0;
}
}
}
RectTransform rectTransform = __instance._rectTransform;
if ((Object)(object)rectTransform != (Object)null)
{
rectTransform.anchorMin = Vector2.zero;
rectTransform.anchorMax = Vector2.one;
rectTransform.offsetMin = Vector2.zero;
rectTransform.offsetMax = Vector2.zero;
rectTransform.anchoredPosition = Vector2.zero;
}
if ((Object)(object)__instance._rawImage.texture != (Object)(object)__instance.managedRenderTexture)
{
__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)
{
}
}
}