Decompiled source of GuodaLight v0.1.0

Tomatobird.GuodaLight.dll

Decompiled 13 hours ago
using System;
using System.Diagnostics;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using GameNetcodeStuff;
using GuodaLight.Utils;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;
using UnityEngine.Rendering;
using UnityEngine.Rendering.HighDefinition;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Tomatobird.GuodaLight")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("0.1.0.0")]
[assembly: AssemblyInformationalVersion("0.1.0+d3571639d5e019c96b813d78a660c12d13bb2bf6")]
[assembly: AssemblyProduct("GuodaLight")]
[assembly: AssemblyTitle("Tomatobird.GuodaLight")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.1.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
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;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
[HarmonyPatch(typeof(NetworkManager))]
internal static class RegisterNetworkPrefabPatch
{
	private static readonly string MOD_GUID = "Tomatobird.GuodaLight";

	[HarmonyPatch("SetSingleton")]
	[HarmonyPostfix]
	private static void RegisterPrefab()
	{
		//IL_0010: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		//IL_001f: 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>();
		FieldInfo field = typeof(NetworkObject).GetField("GlobalObjectIdHash", BindingFlags.Instance | BindingFlags.NonPublic);
		field.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;
		}
	}
}
namespace GuodaLight
{
	[BepInPlugin("Tomatobird.GuodaLight", "GuodaLight", "0.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class GuodaLight : BaseUnityPlugin
	{
		internal static LightKey InputActionInstance = new LightKey();

		public static float lightIntensity = 486.8536f;

		public static float lightRange = 55f;

		public static float lightColorTemperature = 8371f;

		public static GuodaLight Instance { get; private set; } = null;


		internal static ManualLogSource Logger { get; private set; } = null;


		internal static Harmony? Harmony { get; set; }

		private void Awake()
		{
			Logger = ((BaseUnityPlugin)this).Logger;
			Instance = this;
			lightIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("General", "LightIntensity", 486.8536f, "Intensity of the light").Value;
			lightRange = ((BaseUnityPlugin)this).Config.Bind<float>("General", "LightRange", 55f, "Light reach distance").Value;
			lightColorTemperature = ((BaseUnityPlugin)this).Config.Bind<float>("General", "lightColorTemperature", 8371f, "Color temperature of the light").Value;
			Patch();
			Logger.LogInfo((object)"Tomatobird.GuodaLight v0.1.0 has loaded!");
		}

		internal static void Patch()
		{
			//IL_000d: 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_0018: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony = new Harmony("Tomatobird.GuodaLight");
			}
			Logger.LogDebug((object)"Patching...");
			Harmony.PatchAll();
			Logger.LogDebug((object)"Finished patching!");
		}

		internal static void Unpatch()
		{
			Logger.LogDebug((object)"Unpatching...");
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
			Logger.LogDebug((object)"Finished unpatching!");
		}
	}
	public class LightKey : LcInputActions
	{
		[InputAction(/*Could not decode attribute arguments.*/)]
		public InputAction? LightButton { get; set; }
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Tomatobird.GuodaLight";

		public const string PLUGIN_NAME = "GuodaLight";

		public const string PLUGIN_VERSION = "0.1.0";
	}
}
namespace GuodaLight.Utils
{
	internal class FlashKeyPressListener : MonoBehaviour
	{
		private Light? light;

		private HDAdditionalLightData? lightdata;

		public void Awake()
		{
			if (GuodaLight.InputActionInstance.LightButton != null)
			{
				GuodaLight.InputActionInstance.LightButton.performed += OnActionPerformed;
				light = ((Component)this).GetComponent<Light>();
				if ((Object)(object)light != (Object)null)
				{
					Texture cookie = StartOfRound.Instance.allPlayerScripts[0].allHelmetLights[0].cookie;
					light.cookie = cookie;
				}
				SceneManager.sceneLoaded += OnSceneLoaded;
			}
		}

		private void OnSceneLoaded(Scene scene, LoadSceneMode mode)
		{
			lightdata = ((Component)this).GetComponent<HDAdditionalLightData>();
			if ((Object)(object)lightdata != (Object)null)
			{
				lightdata.fadeDistance = 1000f;
				lightdata.shadowFadeDistance = 1000f;
				lightdata.shadowNearPlane = 0.66f;
				SceneManager.sceneLoaded -= OnSceneLoaded;
			}
		}

		public void OnActionPerformed(CallbackContext context)
		{
			if (!((Object)(object)light == (Object)null))
			{
				((Behaviour)light).enabled = !((Behaviour)light).enabled;
			}
		}
	}
}
namespace GuodaLight.Patches
{
	[HarmonyPatch(typeof(PlayerControllerB))]
	public class AddLightObject
	{
		[HarmonyPatch("ConnectClientToPlayerObject")]
		[HarmonyPostfix]
		public static void AddLightObjectPatch(PlayerControllerB __instance)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_014a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0168: Unknown result type (might be due to invalid IL or missing references)
			//IL_017a: Unknown result type (might be due to invalid IL or missing references)
			GameObject val = new GameObject();
			((Object)val).name = "GuodaLight";
			Light val2 = val.AddComponent<Light>();
			((Behaviour)val2).enabled = true;
			val2.boundingSphereOverride = new Vector4(0f, 0f, 0f, 0f);
			val2.bounceIntensity = 0f;
			val2.colorTemperature = GuodaLight.lightColorTemperature;
			val2.cookieSize = 10f;
			val2.cullingMask = -1;
			val2.innerSpotAngle = 21.8021f;
			val2.intensity = GuodaLight.lightIntensity;
			val2.lightShadowCasterMode = (LightShadowCasterMode)2;
			val2.range = GuodaLight.lightRange;
			val2.renderingLayerMask = 1;
			val2.shadowBias = 0.05f;
			val2.shadowNearPlane = 0.2f;
			val2.shadowNormalBias = 0.4f;
			val2.shadowResolution = (LightShadowResolution)(-1);
			val2.shadows = (LightShadows)1;
			val2.shadowStrength = 1f;
			val2.shape = (LightShape)0;
			val2.spotAngle = 73f;
			val2.type = (LightType)0;
			val2.useBoundingSphereOverride = false;
			val2.useColorTemperature = true;
			val2.useShadowMatrixOverride = false;
			val2.useViewFrustumForShadowCasterCull = true;
			val.transform.SetParent(((Component)__instance.gameplayCamera).transform);
			val.transform.localScale = new Vector3(0.3627f, 0.4234f, 0.4918f);
			val.transform.SetPositionAndRotation(((Component)__instance.allHelmetLights[0]).transform.position, ((Component)__instance.allHelmetLights[0]).transform.rotation);
			val.AddComponent<FlashKeyPressListener>();
		}
	}
}