Decompiled source of NoPixelFilter v1.0.0

NoPixelFilter.dll

Decompiled 2 days ago
using System;
using System.Collections;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using UnityEngine;
using UnityEngine.Rendering;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("ClassLibrary1")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ClassLibrary1")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("a99960a9-cd3c-4edc-9972-d3c46ab9de4f")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("sekond.yapyap.nopixel", "YAPYAP No Pixel Filter", "1.0.0")]
public class NoPixelFilter : BaseUnityPlugin
{
	private float nextApply;

	private const bool DISABLE_LOWRES_RENDERER_FEATURE = true;

	private void Start()
	{
		((BaseUnityPlugin)this).Logger.LogInfo((object)"NoPixelFilter 0.7.0 loaded (resize low-res RT to fullscreen to keep UI working)");
		nextApply = Time.unscaledTime + 1f;
	}

	private void Update()
	{
		if (Time.unscaledTime < nextApply)
		{
			return;
		}
		nextApply = Time.unscaledTime + ((Time.unscaledTime < 10f) ? 1f : 3f);
		try
		{
			bool flag = true;
			DisableLowResRendererFeatureOnly();
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("DisableLowResRendererFeatureOnly failed: " + ex));
		}
		try
		{
			UpscaleCameraTargetTexturesToScreen();
		}
		catch (Exception ex2)
		{
			((BaseUnityPlugin)this).Logger.LogWarning((object)("UpscaleCameraTargetTexturesToScreen failed: " + ex2));
		}
	}

	private static bool ContainsIgnoreCase(string hay, string needle)
	{
		if (hay == null || needle == null)
		{
			return false;
		}
		return hay.IndexOf(needle, StringComparison.OrdinalIgnoreCase) >= 0;
	}

	private static object GetField(object obj, string fieldName)
	{
		if (obj == null)
		{
			return null;
		}
		Type type = obj.GetType();
		FieldInfo field = type.GetField(fieldName, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
		return (field != null) ? field.GetValue(obj) : null;
	}

	private void UpscaleCameraTargetTexturesToScreen()
	{
		Camera[] allCameras = Camera.allCameras;
		if (allCameras == null || allCameras.Length == 0)
		{
			return;
		}
		int width = Screen.width;
		int height = Screen.height;
		Camera[] array = allCameras;
		foreach (Camera val in array)
		{
			if (!((Object)(object)val == (Object)null))
			{
				RenderTexture targetTexture = val.targetTexture;
				if (!((Object)(object)targetTexture == (Object)null) && ((float)((Texture)targetTexture).width < (float)width * 0.9f || (float)((Texture)targetTexture).height < (float)height * 0.9f) && (((Texture)targetTexture).width != width || ((Texture)targetTexture).height != height))
				{
					((BaseUnityPlugin)this).Logger.LogInfo((object)$"Camera '{((Object)val).name}': upscaling targetTexture {((Texture)targetTexture).width}x{((Texture)targetTexture).height} -> {width}x{height}");
					targetTexture.Release();
					((Texture)targetTexture).width = width;
					((Texture)targetTexture).height = height;
					((Texture)targetTexture).filterMode = (FilterMode)1;
					targetTexture.Create();
				}
			}
		}
	}

	private void DisableLowResRendererFeatureOnly()
	{
		RenderPipelineAsset currentRenderPipeline = GraphicsSettings.currentRenderPipeline;
		if ((Object)(object)currentRenderPipeline == (Object)null)
		{
			return;
		}
		Type type = ((object)currentRenderPipeline).GetType();
		string hay = type.FullName ?? type.Name;
		if (!ContainsIgnoreCase(hay, "Universal"))
		{
			return;
		}
		object obj = GetField(currentRenderPipeline, "m_RendererDataList") ?? GetField(currentRenderPipeline, "m_RendererData") ?? GetField(currentRenderPipeline, "rendererDataList");
		if (obj == null)
		{
			return;
		}
		if (obj is IEnumerable enumerable && !(obj is string))
		{
			foreach (object item in enumerable)
			{
				DisableLowResOnRendererData(item);
			}
			return;
		}
		DisableLowResOnRendererData(obj);
	}

	private void DisableLowResOnRendererData(object rendererData)
	{
		if (rendererData == null)
		{
			return;
		}
		object obj = GetField(rendererData, "m_RendererFeatures") ?? GetField(rendererData, "rendererFeatures");
		if (!(obj is IEnumerable enumerable))
		{
			return;
		}
		foreach (object item in enumerable)
		{
			if (item == null)
			{
				continue;
			}
			Type type = item.GetType();
			string text = type.FullName ?? type.Name;
			string text2 = GetField(item, "m_Name") as string;
			if (string.IsNullOrEmpty(text2))
			{
				text2 = type.Name;
			}
			if (string.Equals(text2, "LowResRendererFeature", StringComparison.Ordinal) || string.Equals(type.Name, "LowResRendererFeature", StringComparison.Ordinal) || text.EndsWith(".LowResRendererFeature", StringComparison.Ordinal))
			{
				MethodInfo method = type.GetMethod("SetActive", BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
				if (method != null)
				{
					method.Invoke(item, new object[1] { false });
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Disabled LowResRendererFeature via SetActive(false): '" + text2 + "' (" + text + ")"));
					break;
				}
				FieldInfo fieldInfo = type.GetField("m_Active", BindingFlags.Instance | BindingFlags.NonPublic) ?? type.GetField("m_IsActive", BindingFlags.Instance | BindingFlags.NonPublic);
				if (fieldInfo != null && fieldInfo.FieldType == typeof(bool))
				{
					fieldInfo.SetValue(item, false);
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Disabled LowResRendererFeature via field: '" + text2 + "' (" + text + ")"));
					break;
				}
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Matched LowResRendererFeature but couldn't disable it: " + text));
			}
		}
	}
}