Decompiled source of FraudPortalFix v0.2.2

plugins/FraudPortalsFix-Mod/FraudPortalFix.dll

Decompiled 6 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using PluginConfig.API;
using PluginConfig.API.Fields;
using ULTRAKILL.Portal;
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("FraudPortalFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FraudPortalFix")]
[assembly: AssemblyTitle("FraudPortalFix")]
[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 FraudPortalFix
{
	[BepInPlugin("italogames.fraudportalfix", "Fraud Portal Fix", "0.2.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(PortalRenderV2), "Start")]
		private static class PortalStartPatch
		{
			private static void Postfix(PortalRenderV2 __instance)
			{
				if ((Object)(object)instance != (Object)null)
				{
					instance.RegisterPortal(__instance);
				}
			}
		}

		private const string PluginGuid = "italogames.fraudportalfix";

		private PluginConfigurator config;

		private BoolField enabledField;

		private Harmony harmony;

		private static Plugin instance;

		private BoolValueChangeEventDelegate configChangedHandler;

		private readonly Dictionary<PortalRenderV2, bool> originalValues = new Dictionary<PortalRenderV2, bool>();

		private void Awake()
		{
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Expected O, but got Unknown
			//IL_00b4: Unknown result type (might be due to invalid IL or missing references)
			//IL_00be: Expected O, but got Unknown
			//IL_00d5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: Expected O, but got Unknown
			instance = this;
			try
			{
				config = PluginConfigurator.Create("Fraud Portal Fix", "italogames.fraudportalfix");
				string text = Path.Combine(Path.GetDirectoryName(typeof(Plugin).Assembly.Location), "icon.png");
				if (File.Exists(text))
				{
					config.SetIconWithURL(new Uri(text).AbsoluteUri);
					((BaseUnityPlugin)this).Logger.LogInfo((object)("Loading icon: " + text));
				}
				else
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Icon not found: " + text));
				}
				enabledField = new BoolField(config.rootPanel, "Enable Fraud Portal Fix", "enabled", true);
				configChangedHandler = (BoolValueChangeEventDelegate)delegate
				{
					ApplyConfiguration();
				};
				enabledField.onValueChange += configChangedHandler;
				harmony = new Harmony("italogames.fraudportalfix");
				harmony.PatchAll();
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Fraud Portal Fix v0.2.2 loaded!");
				((BaseUnityPlugin)this).Logger.LogInfo((object)"Harmony patches registered.");
			}
			catch (Exception ex)
			{
				((BaseUnityPlugin)this).Logger.LogError((object)("Fraud Portal Fix initialization failed: " + ex));
			}
		}

		private void ApplyConfiguration()
		{
			if (enabledField == null)
			{
				return;
			}
			List<PortalRenderV2> list = new List<PortalRenderV2>();
			foreach (KeyValuePair<PortalRenderV2, bool> originalValue in originalValues)
			{
				PortalRenderV2 key = originalValue.Key;
				if ((Object)(object)key == (Object)null)
				{
					list.Add(key);
				}
				else
				{
					key.doOcclusionPass = !enabledField.value && originalValue.Value;
				}
			}
			foreach (PortalRenderV2 item in list)
			{
				originalValues.Remove(item);
			}
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Fraud Portal Fix enabled: " + enabledField.value));
		}

		private void RegisterPortal(PortalRenderV2 renderer)
		{
			if (!((Object)(object)renderer == (Object)null) && enabledField != null)
			{
				if (!originalValues.ContainsKey(renderer))
				{
					originalValues.Add(renderer, renderer.doOcclusionPass);
				}
				if (enabledField.value)
				{
					renderer.doOcclusionPass = false;
				}
				((BaseUnityPlugin)this).Logger.LogDebug((object)("Portal initialized. Occlusion pass: " + renderer.doOcclusionPass));
			}
		}

		private void RestorePortals()
		{
			foreach (KeyValuePair<PortalRenderV2, bool> originalValue in originalValues)
			{
				PortalRenderV2 key = originalValue.Key;
				if ((Object)(object)key != (Object)null)
				{
					key.doOcclusionPass = originalValue.Value;
				}
			}
			originalValues.Clear();
		}

		private void OnDestroy()
		{
			if (enabledField != null && configChangedHandler != null)
			{
				enabledField.onValueChange -= configChangedHandler;
			}
			RestorePortals();
			if (harmony != null)
			{
				harmony.UnpatchAll("italogames.fraudportalfix");
			}
			instance = null;
			((BaseUnityPlugin)this).Logger.LogInfo((object)"Fraud Portal Fix unloaded.");
		}
	}
}