Decompiled source of RestoreVanillaVision v1.2.1

RestoreVanillaVision/RestoredVanillaVision.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using GameNetcodeStuff;
using HarmonyLib;
using LethalConfig;
using LethalConfig.ConfigItems;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
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("RestoredVanillaVision")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("RestoredVanillaVision")]
[assembly: AssemblyTitle("RestoredVanillaVision")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
}
[HarmonyPatch(typeof(NetworkManager))]
internal static class NetworkPrefabPatch2
{
	private static readonly string MOD_GUID = "blubbpaule.restorevision";

	[HarmonyPostfix]
	[HarmonyPatch("SetSingleton")]
	private static void RegisterPrefab()
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0015: Expected O, but got Unknown
		//IL_0017: Unknown result type (might be due to invalid IL or missing references)
		//IL_001e: Unknown result type (might be due to invalid IL or missing references)
		GameObject val = new GameObject(MOD_GUID + " Prefab");
		((Object)val).hideFlags = (HideFlags)(((Object)val).hideFlags | 0x3D);
		Object.DontDestroyOnLoad((Object)(object)val);
		NetworkObject obj = val.AddComponent<NetworkObject>();
		typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic).SetValue(obj, GetHash(MOD_GUID));
		NetworkManager.Singleton.PrefabHandler.AddNetworkPrefab(val);
		static uint GetHash(string value)
		{
			return value?.Aggregate(17u, (uint current, char c) => (current * 31) ^ c) ?? 0;
		}
	}
}
[BepInPlugin("blubbpaule.restorevision", "Restore Vanilla Vision", "1.2.0")]
[BepInDependency(/*Could not decode attribute arguments.*/)]
public class Plugin : BaseUnityPlugin
{
	public static ConfigEntry<bool> PreV80Lighting;

	private static bool LastState;

	private void Awake()
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_0030: Expected O, but got Unknown
		//IL_0044: Unknown result type (might be due to invalid IL or missing references)
		PreV80Lighting = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "RestoreVanillaVision", true, "Enable for brighter pre-v80 lighting. Disable for darker v80-style lighting.");
		LethalConfigManager.AddConfigItem((BaseConfigItem)new BoolCheckBoxConfigItem(PreV80Lighting, false));
		LastState = PreV80Lighting.Value;
		new Harmony("blubbpaule.restorevision").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"Restore Vanilla Vision loaded. Eating carrots for better vision");
	}

	private void Update()
	{
		if (PreV80Lighting.Value != LastState)
		{
			LastState = PreV80Lighting.Value;
			PlayerControllerB val = GameNetworkManager.Instance?.localPlayerController;
			if ((Object)(object)val != (Object)null)
			{
				ApplyLighting(val);
			}
		}
	}

	public static void ApplyLighting(PlayerControllerB player)
	{
		if (!((Object)(object)player.nightVision == (Object)null))
		{
			Light nightVision = player.nightVision;
			if (PreV80Lighting.Value)
			{
				nightVision.type = (LightType)2;
				nightVision.intensity = 366.9317f;
				nightVision.range = 110f;
				nightVision.shadowStrength = 0f;
			}
			else
			{
				nightVision.type = (LightType)2;
				nightVision.intensity = 200f;
				nightVision.range = 20f;
				nightVision.shadowStrength = 0f;
			}
		}
	}
}
[HarmonyPatch(typeof(PlayerControllerB), "SetNightVisionEnabled")]
public class NightVisionPatch
{
	[HarmonyPostfix]
	private static void Postfix(PlayerControllerB __instance)
	{
		if ((Object)(object)__instance.nightVision != (Object)null && ((Behaviour)__instance.nightVision).enabled)
		{
			Plugin.ApplyLighting(__instance);
		}
	}
}