Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of WiresUpscalers v0.1.1
WiresUpscalers.dll
Decompiled 8 hours agousing System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; using System.Runtime.Versioning; using System.Security.Cryptography; using BepInEx; using BepInEx.Configuration; using GUIFramework; using HarmonyLib; using Microsoft.CodeAnalysis; using TMPro; using UnityEngine; using UnityEngine.Events; using UnityEngine.PostProcessing; using UnityEngine.Rendering; using UnityEngine.UI; using Valheim.SettingsGui; [assembly: CompilationRelaxations(8)] [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)] [assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")] [assembly: AssemblyCompany("WiresUpscalers")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+a26eb15b080104d8986d5dd43a3d32feaeab4a61")] [assembly: AssemblyProduct("WiresUpscalers")] [assembly: AssemblyTitle("WiresUpscalers")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [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; } } } namespace WiresUpscalers { internal static class Native { internal struct Params { public int backend; public int model; public int inW; public int inH; public int outW; public int outH; public IntPtr color; public IntPtr depth; public IntPtr motion; public IntPtr output; public float jitterX; public float jitterY; public float mvScaleX; public float mvScaleY; public float sharpness; public float frameTimeMs; public float cameraNear; public float cameraFar; public float fovY; public int reset; public int hdr; public int depthInverted; } internal const string Dll = "WiresUpscalersNative"; private const int EventDetect = 1; private const int EventEvaluate = 2; private const int EventRelease = 3; internal const int AvailDLSS = 1; internal const int AvailFSR3 = 2; internal const int AvailFSR4 = 4; internal const int AvailXeSS = 8; internal const int Ready = 65536; private static bool s_loaded; private static bool s_asked; private static int s_ready; private static IntPtr s_event; private static string s_lastMessage = ""; private static readonly IntPtr[] s_params = new IntPtr[3]; private static int s_paramAt; private static readonly CommandBuffer s_cb = new CommandBuffer { name = "Wire's Upscalers" }; internal static int Available { get { if (!s_loaded) { return 0; } if (s_ready != 0) { return s_ready; } int num = WU_Available(); if ((num & 0x10000) == 0 && !s_asked) { s_asked = true; Issue(1, IntPtr.Zero); } if ((num & 0x10000) != 0) { s_ready = num; LogMessage(); } return num; } } [DllImport("WiresUpscalersNative", CharSet = CharSet.Unicode)] private static extern void WU_SetModFolder(string dir); [DllImport("WiresUpscalersNative")] private static extern int WU_Renderer(); [DllImport("WiresUpscalersNative")] private static extern int WU_Available(); [DllImport("WiresUpscalersNative")] private static extern IntPtr WU_Message(); [DllImport("WiresUpscalersNative")] private static extern IntPtr WU_EventFunc(); internal static void Start(string modDir) { try { WU_SetModFolder(modDir); if (WU_Renderer() < 0) { Plugin.Warn("Unity didn't hand the native part its graphics device; restart Valheim once."); return; } s_event = WU_EventFunc(); for (int i = 0; i < s_params.Length; i++) { s_params[i] = Marshal.AllocHGlobal(Marshal.SizeOf<Params>()); } s_loaded = true; s_asked = true; Issue(1, IntPtr.Zero); } catch (Exception ex) { Plugin.Warn("Native part unavailable: " + ex.Message); } } internal static bool Has(Upscaler u) { int available = Available; return u switch { Upscaler.DLSS => (available & 1) != 0, Upscaler.FSR3 => (available & 2) != 0, Upscaler.FSR4 => (available & 4) != 0, Upscaler.XeSS => (available & 8) != 0, _ => true, }; } internal static void Evaluate(ref Params p) { if (s_loaded) { s_paramAt = (s_paramAt + 1) % s_params.Length; Marshal.StructureToPtr(p, s_params[s_paramAt], fDeleteOld: false); Issue(2, s_params[s_paramAt]); } } internal static void Release() { if (s_loaded) { Issue(3, IntPtr.Zero); } } private static void Issue(int id, IntPtr data) { s_cb.Clear(); s_cb.IssuePluginEventAndData(s_event, id, data); Graphics.ExecuteCommandBuffer(s_cb); } internal static void LogMessage() { if (s_loaded) { string text = Marshal.PtrToStringAnsi(WU_Message()); if (!string.IsNullOrEmpty(text) && !(text == s_lastMessage)) { s_lastMessage = text; Plugin.Log(text); } } } } internal enum Upscaler { None, DLSS, FSR3, FSR4, XeSS } [BepInPlugin("wire.valheim.upscalers", "Wire's Upscalers", "0.1.0")] public sealed class Plugin : BaseUnityPlugin { [HarmonyPatch(typeof(GameCamera), "Awake")] private static class GameCam { private static void Postfix(GameCamera __instance) { Attach(((Object)(object)__instance != (Object)null) ? ((Component)__instance).GetComponent<Camera>() : null); } } [HarmonyPatch(typeof(FejdStartup), "Start")] private static class MenuCam { private static void Postfix() { Attach(Camera.main); } } internal static Plugin Instance; internal static ConfigEntry<int> UpscalerConfig; internal static ConfigEntry<int> DlssModel; internal static ConfigEntry<float> Sharpness; internal static ConfigEntry<bool> ShowAll; private Harmony _harmony; internal static Upscaler Current => (Upscaler)Mathf.Clamp(UpscalerConfig.Value, 0, 4); private void Awake() { //IL_0075: Unknown result type (might be due to invalid IL or missing references) //IL_007f: Expected O, but got Unknown //IL_00b5: Unknown result type (might be due to invalid IL or missing references) //IL_00bf: Expected O, but got Unknown //IL_00d0: Unknown result type (might be due to invalid IL or missing references) //IL_00da: Expected O, but got Unknown Instance = this; UpscalerConfig = ((BaseUnityPlugin)this).Config.Bind<int>("Upscaling", "Upscaler", 0, "Set in the game's graphics settings (the Smooth/Pixelated row). 0 none, 1 NVIDIA DLSS, 2 AMD FSR 3, 3 AMD FSR 4, 4 Intel XeSS."); DlssModel = ((BaseUnityPlugin)this).Config.Bind<int>("Upscaling", "DLSS model", 13, "Set in the game's graphics settings. NVIDIA render preset: 13 Transformer 2 (DLSS 4.5), 11 Transformer (DLSS 4), 5 CNN (DLSS 3)."); Sharpness = ((BaseUnityPlugin)this).Config.Bind<float>("Upscaling", "FSR sharpness", 0f, new ConfigDescription("Set in the game's graphics settings. AMD's own sharpening, 0 off.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>())); ShowAll = ((BaseUnityPlugin)this).Config.Bind<bool>("Advanced", "Show every upscaler", false, new ConfigDescription("Lists every upscaler and its settings even where this PC can't run them (for screenshots). One that can't run shows the game's own image.", (AcceptableValueBase)null, new object[1] { new ConfigurationManagerAttributes { IsAdvanced = true } })); InstallNative(); _harmony = new Harmony("wire.valheim.upscalers"); _harmony.PatchAll(typeof(Plugin).Assembly); } private void OnDestroy() { Harmony harmony = _harmony; if (harmony != null) { harmony.UnpatchSelf(); } } internal static void Log(string m) { Plugin instance = Instance; if (instance != null) { ((BaseUnityPlugin)instance).Logger.LogInfo((object)m); } } internal static void Warn(string m) { Plugin instance = Instance; if (instance != null) { ((BaseUnityPlugin)instance).Logger.LogWarning((object)m); } } private void InstallNative() { string directoryName = Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location); string text = Path.Combine(directoryName, "WiresUpscalersNative.dll"); string text2 = Path.Combine(Application.dataPath, "Plugins", "x86_64"); string text3 = Path.Combine(text2, "WiresUpscalersNative.dll"); try { if (File.Exists(text) && (!File.Exists(text3) || Hash(text) != Hash(text3))) { Directory.CreateDirectory(text2); string text4 = text3 + ".new"; File.Copy(text, text4, overwrite: true); if (File.Exists(text3)) { File.Delete(text3); } File.Move(text4, text3); ((BaseUnityPlugin)this).Logger.LogInfo((object)("Native part installed to " + text3)); } } catch (Exception ex) { ((BaseUnityPlugin)this).Logger.LogWarning((object)("Native part not installed (" + ex.Message + "); upscalers stay off.")); } Native.Start(directoryName); } private static string Hash(string file) { using SHA256 sHA = SHA256.Create(); using FileStream inputStream = File.OpenRead(file); return BitConverter.ToString(sHA.ComputeHash(inputStream)); } internal static void Attach(Camera cam) { if (!((Object)(object)cam == (Object)null) && !((Object)(object)((Component)cam).GetComponent<UpscaleRenderer>() != (Object)null)) { ((Component)cam).gameObject.AddComponent<UpscaleRenderer>(); } } } internal sealed class ConfigurationManagerAttributes { public bool? IsAdvanced; } [HarmonyPatch] internal static class Settings { private sealed class Ui { internal GuiDropdown upscaling; internal GuiDropdown model; internal GuiDropdown sharpness; internal GameObject modelRow; internal GameObject sharpRow; internal int gameOptions; internal readonly List<Upscaler> listed = new List<Upscaler>(4); internal RectTransform list; } private static readonly Upscaler[] Order = new Upscaler[4] { Upscaler.DLSS, Upscaler.FSR3, Upscaler.FSR4, Upscaler.XeSS }; private static readonly string[] Names = new string[4] { "NVIDIA® DLSS", "AMD FSR™ 3", "AMD FSR™ 4", "Intel® XeSS" }; private static readonly int[] Models = new int[3] { 13, 11, 5 }; private static readonly string[] ModelNames = new string[3] { "Transformer 2 (DLSS 4.5)", "Transformer (DLSS 4)", "CNN (DLSS 3)" }; private static readonly float[] Sharp = new float[5] { 0f, 0.25f, 0.5f, 0.75f, 1f }; private static readonly string[] SharpNames = new string[5] { "Off", "25%", "50%", "75%", "100%" }; private static readonly Dictionary<GraphicsSettings, Ui> Open = new Dictionary<GraphicsSettings, Ui>(); private static readonly FieldRef<GraphicsSettings, GuiDropdown> UpscalingField = AccessTools.FieldRefAccess<GraphicsSettings, GuiDropdown>("m_upscalingAlgorithmDropdown"); private static readonly FieldRef<GraphicsSettings, List<QualityDropdownData>> DropdownsField = AccessTools.FieldRefAccess<GraphicsSettings, List<QualityDropdownData>>("m_qualityDropdowns"); private static readonly FieldRef<GraphicsSettings, RectTransform> ListField = AccessTools.FieldRefAccess<GraphicsSettings, RectTransform>("m_listRoot"); private static Upscaler Selected(Ui ui) { int num = ((TMP_Dropdown)ui.upscaling).value - ui.gameOptions; if (num < 0 || num >= ui.listed.Count) { return Upscaler.None; } return ui.listed[num]; } [HarmonyPatch(typeof(GraphicsSettings), "InitializeUpscalingAlgorithmsDropdown")] [HarmonyPostfix] private static void Build(GraphicsSettings __instance) { //IL_0143: Unknown result type (might be due to invalid IL or missing references) try { GuiDropdown val = UpscalingField.Invoke(__instance); List<QualityDropdownData> list = DropdownsField.Invoke(__instance); RectTransform val2 = ListField.Invoke(__instance); if ((Object)(object)val == (Object)null || list == null || list.Count == 0 || (Object)(object)val2 == (Object)null) { return; } Ui ui = new Ui { upscaling = val, gameOptions = ((TMP_Dropdown)val).options.Count, list = val2 }; bool value = Plugin.ShowAll.Value; List<string> list2 = new List<string>(); for (int i = 0; i < Order.Length; i++) { if (value || Native.Has(Order[i])) { ui.listed.Add(Order[i]); list2.Add(Names[i]); } } ((TMP_Dropdown)val).AddOptions(list2); List<int> list3 = new List<int>(); for (int j = 0; j < ui.gameOptions; j++) { list3.Add(j); } for (int k = 0; k < ui.listed.Count; k++) { list3.Add(0); } list[list.Count - 1] = new QualityDropdownData((GraphicsSettingInt)8, val, (ScrollRectEnsureVisible)null, (IReadOnlyCollection<int>)list3); ui.modelRow = Row(val, val2, "DLSS model", ModelNames, out ui.model); ui.sharpRow = Row(val, val2, "FSR sharpness", SharpNames, out ui.sharpness); ((UnityEvent<int>)(object)((TMP_Dropdown)val).onValueChanged).AddListener((UnityAction<int>)delegate { Refresh(ui); }); Open[__instance] = ui; } catch (Exception ex) { Plugin.Warn("Upscaler settings not added: " + ex.Message); } } private static GameObject Row(GuiDropdown template, RectTransform list, string title, string[] options, out GuiDropdown dropdown) { Transform val = ((Component)template).transform; Transform val2 = ((Component)template).transform; while ((Object)(object)val.parent != (Object)null && (Object)(object)val.parent != (Object)(object)list && ((Component)val.parent).GetComponentsInChildren<GuiDropdown>(true).Length == 1) { val = val.parent; } while ((Object)(object)val2.parent != (Object)null && (Object)(object)val2.parent != (Object)(object)list) { val2 = val2.parent; } GameObject val3 = Object.Instantiate<GameObject>(((Component)val).gameObject, (Transform)(object)list, false); ((Object)val3).name = "WiresUpscalers_" + title; val3.transform.SetSiblingIndex(val2.GetSiblingIndex() + 1); dropdown = val3.GetComponentInChildren<GuiDropdown>(true); ((UnityEventBase)((TMP_Dropdown)dropdown).onValueChanged).RemoveAllListeners(); ((TMP_Dropdown)dropdown).ClearOptions(); ((TMP_Dropdown)dropdown).AddOptions(new List<string>(options)); TMP_Text[] componentsInChildren = val3.GetComponentsInChildren<TMP_Text>(true); foreach (TMP_Text val4 in componentsInChildren) { if ((Object)(object)((Component)val4).GetComponentInParent<GuiDropdown>(true) == (Object)null) { val4.text = title; break; } } val3.SetActive(false); return val3; } private static float Height(GameObject row) { //IL_001c: Unknown result type (might be due to invalid IL or missing references) //IL_0021: Unknown result type (might be due to invalid IL or missing references) RectTransform component = row.GetComponent<RectTransform>(); if (!((Object)(object)component != (Object)null)) { return 48f; } Rect rect = component.rect; return Mathf.Max(40f, ((Rect)(ref rect)).height) + 8f; } [HarmonyPatch(typeof(GraphicsSettings), "SetSettingsFromState")] [HarmonyPostfix] private static void Load(GraphicsSettings __instance) { if (!Open.TryGetValue(__instance, out var value)) { return; } int num = value.listed.IndexOf(Plugin.Current); if (Plugin.Current != Upscaler.None && num >= 0) { ((TMP_Dropdown)value.upscaling).SetValueWithoutNotify(value.gameOptions + num); } ((TMP_Dropdown)value.model).SetValueWithoutNotify(Math.Max(0, Array.IndexOf(Models, Plugin.DlssModel.Value))); int valueWithoutNotify = 0; for (int i = 0; i < Sharp.Length; i++) { if (Mathf.Abs(Sharp[i] - Plugin.Sharpness.Value) < 0.01f) { valueWithoutNotify = i; } } ((TMP_Dropdown)value.sharpness).SetValueWithoutNotify(valueWithoutNotify); Refresh(value); } private static void Refresh(Ui ui) { //IL_00bc: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) Upscaler upscaler = Selected(ui); bool value = Plugin.ShowAll.Value; bool flag = value || upscaler == Upscaler.DLSS; bool flag2 = value || upscaler == Upscaler.FSR3 || upscaler == Upscaler.FSR4; if (ui.modelRow.activeSelf != flag || ui.sharpRow.activeSelf != flag2) { float num = 0f; if (ui.modelRow.activeSelf != flag) { num += (float)(flag ? 1 : (-1)) * Height(ui.modelRow); } if (ui.sharpRow.activeSelf != flag2) { num += (float)(flag2 ? 1 : (-1)) * Height(ui.sharpRow); } ui.modelRow.SetActive(flag); ui.sharpRow.SetActive(flag2); RectTransform list = ui.list; Rect rect = ui.list.rect; list.SetSizeWithCurrentAnchors((Axis)1, ((Rect)(ref rect)).height + num); LayoutRebuilder.MarkLayoutForRebuild(ui.list); } } [HarmonyPatch(typeof(GraphicsSettings), "OnOkAsync")] [HarmonyPrefix] private static void Save(GraphicsSettings __instance) { if (Open.TryGetValue(__instance, out var value)) { Upscaler upscaler = Selected(value); int num = Models[Mathf.Clamp(((TMP_Dropdown)value.model).value, 0, Models.Length - 1)]; float num2 = Sharp[Mathf.Clamp(((TMP_Dropdown)value.sharpness).value, 0, Sharp.Length - 1)]; if (Plugin.UpscalerConfig.Value != (int)upscaler || Plugin.DlssModel.Value != num || !Mathf.Approximately(Plugin.Sharpness.Value, num2)) { Plugin.UpscalerConfig.Value = (int)upscaler; Plugin.DlssModel.Value = num; Plugin.Sharpness.Value = num2; UpscaleRenderer.SettingsChanged(); } } } [HarmonyPatch(typeof(GraphicsSettings), "Terminate")] [HarmonyPrefix] private static void Close(GraphicsSettings __instance) { Open.Remove(__instance); } } [RequireComponent(typeof(Camera))] internal sealed class UpscaleRenderer : MonoBehaviour { private static readonly List<UpscaleRenderer> All = new List<UpscaleRenderer>(2); private Camera _cam; private PostProcessingBehaviour _post; private RenderTexture _color; private RenderTexture _depth; private RenderTexture _motion; private RenderTexture _output; private IntPtr _colorPtr; private IntPtr _depthPtr; private IntPtr _motionPtr; private IntPtr _outputPtr; private int _inW; private int _inH; private int _outW; private int _outH; private bool _reset = true; private bool _jittered; private bool _oldTransparentJitter; private bool _aaOff; private bool _oldAa; private Vector2 _jitter; private int _jitterIndex; private readonly List<RawImage> _shown = new List<RawImage>(2); private Upscaler _last; private bool Active { get { if (Plugin.Current != Upscaler.None) { return Native.Has(Plugin.Current); } return false; } } private void Awake() { _cam = ((Component)this).GetComponent<Camera>(); _post = ((Component)this).GetComponent<PostProcessingBehaviour>(); All.Add(this); } private void OnDestroy() { Release(); All.Remove(this); } internal static void SettingsChanged() { foreach (UpscaleRenderer item in All) { if ((Object)(object)item != (Object)null) { item.Release(); } } Native.Release(); } private static float Halton(int i, int b) { float num = 1f; float num2 = 0f; while (i > 0) { num /= (float)b; num2 += num * (float)(i % b); i /= b; } return num2; } private void OnPreCull() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0026: Unknown result type (might be due to invalid IL or missing references) //IL_008f: Unknown result type (might be due to invalid IL or missing references) //IL_0094: Unknown result type (might be due to invalid IL or missing references) //IL_00aa: Unknown result type (might be due to invalid IL or missing references) //IL_00af: Unknown result type (might be due to invalid IL or missing references) //IL_00b6: Unknown result type (might be due to invalid IL or missing references) //IL_011b: Unknown result type (might be due to invalid IL or missing references) _jittered = false; if (Active && _inW >= 1) { Camera cam = _cam; cam.depthTextureMode = (DepthTextureMode)(cam.depthTextureMode | 5); float num = (float)_outW / (float)_inW; int num2 = Mathf.Clamp(Mathf.CeilToInt(8f * num * num), 8, 128); _jitterIndex = (_jitterIndex + 1) % num2; _jitter = new Vector2(Halton(_jitterIndex + 1, 2) - 0.5f, Halton(_jitterIndex + 1, 3) - 0.5f); _cam.ResetProjectionMatrix(); Matrix4x4 projectionMatrix = _cam.projectionMatrix; _cam.nonJitteredProjectionMatrix = projectionMatrix; projectionMatrix.m02 += 2f * _jitter.x / (float)_inW; projectionMatrix.m12 += 2f * _jitter.y / (float)_inH; _oldTransparentJitter = _cam.useJitteredProjectionMatrixForTransparentRendering; _cam.projectionMatrix = projectionMatrix; _cam.useJitteredProjectionMatrixForTransparentRendering = true; _jittered = true; } } private void OnPostRender() { //IL_0020: Unknown result type (might be due to invalid IL or missing references) if (_jittered) { _cam.ResetProjectionMatrix(); _cam.nonJitteredProjectionMatrix = _cam.projectionMatrix; _cam.useJitteredProjectionMatrixForTransparentRendering = _oldTransparentJitter; _jittered = false; } } private static RenderTexture Make(int w, int h, RenderTextureFormat f, bool uav, string name) { //IL_0003: Unknown result type (might be due to invalid IL or missing references) //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_0012: Unknown result type (might be due to invalid IL or missing references) //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0027: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Expected O, but got Unknown RenderTexture val = new RenderTexture(w, h, 0, f, (RenderTextureReadWrite)1) { name = name, enableRandomWrite = uav, antiAliasing = 1, filterMode = (FilterMode)1 }; val.Create(); return val; } private void Ensure(int inW, int inH) { int width = Screen.width; int height = Screen.height; if (!((Object)(object)_color != (Object)null) || inW != _inW || inH != _inH || width != _outW || height != _outH) { Release(); _inW = inW; _inH = inH; _outW = width; _outH = height; _color = Make(inW, inH, (RenderTextureFormat)2, uav: false, "Wire upscale color"); _depth = Make(inW, inH, (RenderTextureFormat)14, uav: false, "Wire upscale depth"); _motion = Make(inW, inH, (RenderTextureFormat)13, uav: false, "Wire upscale motion"); _output = Make(width, height, (RenderTextureFormat)2, uav: true, "Wire upscale output"); _colorPtr = ((Texture)_color).GetNativeTexturePtr(); _depthPtr = ((Texture)_depth).GetNativeTexturePtr(); _motionPtr = ((Texture)_motion).GetNativeTexturePtr(); _outputPtr = ((Texture)_output).GetNativeTexturePtr(); _reset = true; } } private void OnRenderImage(RenderTexture source, RenderTexture destination) { Upscaler current = Plugin.Current; if (current != _last) { _last = current; _reset = true; } Texture globalTexture = Shader.GetGlobalTexture("_CameraDepthTexture"); Texture globalTexture2 = Shader.GetGlobalTexture("_CameraMotionVectorsTexture"); if (!Active || (Object)(object)source == (Object)null || (Object)(object)globalTexture == (Object)null || (Object)(object)globalTexture2 == (Object)null) { Restore(); Graphics.Blit((Texture)(object)source, destination); return; } Ensure(((Texture)source).width, ((Texture)source).height); Graphics.Blit((Texture)(object)source, _color); Graphics.Blit(globalTexture, _depth); Graphics.Blit(globalTexture2, _motion); bool flag = current == Upscaler.FSR3 || current == Upscaler.FSR4; Native.Params p = new Native.Params { backend = (int)current, model = Plugin.DlssModel.Value, inW = _inW, inH = _inH, outW = _outW, outH = _outH, color = _colorPtr, depth = _depthPtr, motion = _motionPtr, output = _outputPtr, jitterX = ((current == Upscaler.DLSS) ? (0f - _jitter.x) : _jitter.x), jitterY = ((current == Upscaler.DLSS) ? (0f - _jitter.y) : _jitter.y), mvScaleX = -_inW, mvScaleY = -_inH, sharpness = (flag ? Mathf.Clamp01(Plugin.Sharpness.Value) : 0f), frameTimeMs = Time.unscaledDeltaTime * 1000f, cameraNear = _cam.nearClipPlane, cameraFar = _cam.farClipPlane, fovY = _cam.fieldOfView * ((float)Math.PI / 180f), reset = (_reset ? 1 : 0), hdr = (_cam.allowHDR ? 1 : 0), depthInverted = (SystemInfo.usesReversedZBuffer ? 1 : 0) }; Native.Evaluate(ref p); _reset = false; if (Time.frameCount % 120 == 0) { Native.LogMessage(); } if (!_aaOff && (Object)(object)_post != (Object)null && (Object)(object)_post.profile != (Object)null) { _oldAa = ((PostProcessingModel)_post.profile.antialiasing).enabled; ((PostProcessingModel)_post.profile.antialiasing).enabled = false; _aaOff = true; } if ((Object)(object)_cam.targetTexture != (Object)null) { Show(); Graphics.Blit((Texture)(object)source, destination); } else { Graphics.Blit((Texture)(object)_output, destination); } } private void Show() { bool flag = _shown.Count > 0; foreach (RawImage item in _shown) { if ((Object)(object)item == (Object)null || (Object)(object)item.texture != (Object)(object)_output) { flag = false; break; } } if (flag) { return; } FrameBufferScaler[] array = Object.FindObjectsByType<FrameBufferScaler>((FindObjectsSortMode)0); foreach (FrameBufferScaler val in array) { RawImage val2 = (((Object)(object)val != (Object)null) ? ((Component)val).GetComponent<RawImage>() : null); if (!((Object)(object)val2 == (Object)null) && (!((Object)(object)val2.texture != (Object)(object)_cam.targetTexture) || !((Object)(object)val2.texture != (Object)(object)_output))) { val2.texture = (Texture)(object)_output; if (!_shown.Contains(val2)) { _shown.Add(val2); } } } } private void Restore() { foreach (RawImage item in _shown) { if ((Object)(object)item != (Object)null && (Object)(object)item.texture == (Object)(object)_output) { item.texture = (Texture)(object)_cam.targetTexture; } } _shown.Clear(); if (_aaOff && (Object)(object)_post != (Object)null && (Object)(object)_post.profile != (Object)null) { ((PostProcessingModel)_post.profile.antialiasing).enabled = _oldAa; } _aaOff = false; } private void Release() { Restore(); RenderTexture[] array = (RenderTexture[])(object)new RenderTexture[4] { _color, _depth, _motion, _output }; foreach (RenderTexture val in array) { if ((Object)(object)val != (Object)null) { val.Release(); Object.Destroy((Object)(object)val); } } _color = (_depth = (_motion = (_output = null))); _inW = (_inH = (_outW = (_outH = 0))); _reset = true; } } }