Decompiled source of HitTheLights v0.0.9

HitTheLights.dll

Decompiled a month ago
using System;
using System.CodeDom.Compiler;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using BepInEx.Unity.IL2CPP.Utils.Collections;
using GTFO.API;
using GameData;
using Gear;
using HarmonyLib;
using Il2CppSystem;
using LevelGeneration;
using Microsoft.CodeAnalysis;
using Player;
using SNetwork;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("HitTheLights")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("HitTheLights")]
[assembly: AssemblyTitle("HitTheLights")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
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;
		}
	}
}
namespace HitTheLights
{
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[BepInPlugin("HitTheLights", "HitTheLights", "0.0.9")]
	public class Plugin : BasePlugin
	{
		public struct HTLNetInfo
		{
			public float X;

			public float Y;

			public float Z;

			public bool C;

			public static string NetworkIdentity => "HTLNetInfo";

			public HTLNetInfo(float x, float y, float z, bool C)
			{
				this = default(HTLNetInfo);
				X = x;
				Y = y;
				Z = z;
				C = C;
				HitTheLights.Log.LogInfo((object)"sent a broken light package");
			}
		}

		public struct HTLInfo
		{
			public float X;

			public float Y;

			public float Z;

			public bool C;

			public HTLInfo(float x, float y, float z, bool c)
			{
				this = default(HTLInfo);
				X = x;
				Y = y;
				Z = z;
				C = c;
			}

			public HTLInfo(HTLNetInfo network)
			{
				this = default(HTLInfo);
				X = network.X;
				Y = network.Y;
				Z = network.Z;
				C = network.C;
			}
		}

		public class HitTheLights : MonoBehaviour
		{
			public static ManualLogSource Log;

			public static Dictionary<Vector3, LG_Light> LightsTable = new Dictionary<Vector3, LG_Light>();

			public static Dictionary<Vector3, LG_Light> KilledTable = new Dictionary<Vector3, LG_Light>();

			public void Initialize()
			{
				//IL_0081: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
				LightsTable.Clear();
				KilledTable.Clear();
				Vector3 key = default(Vector3);
				foreach (LG_Light item in Object.FindObjectsOfType<LG_Light>())
				{
					((Object)item).name = "HitTheLights";
					SphereCollider obj = ((Component)item).gameObject.AddComponent<SphereCollider>();
					Collider component = ((Component)PlayerManager.GetLocalPlayerAgent()).gameObject.GetComponent<Collider>();
					Physics.IgnoreCollision((Collider)(object)obj, component, true);
					obj.radius = 0.4f;
					((Collider)obj).isTrigger = false;
					((Component)item).gameObject.AddComponent<ColliderMaterial>().MaterialId = 3;
					float num = Mathf.Round(((Component)item).transform.position.x * 10f) * 0.1f;
					float num2 = Mathf.Round(((Component)item).transform.position.y * 10f) * 0.1f;
					float num3 = Mathf.Round(((Component)item).transform.position.z * 10f) * 0.1f;
					((Vector3)(ref key))..ctor(num, num2, num3);
					LightsTable[key] = item;
				}
				CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(HTLSync()), (Action)null);
				CoroutineManager.StartCoroutine(CollectionExtensions.WrapToIl2Cpp(HTLKill()), (Action)null);
			}

			private void Start()
			{
				Log.LogInfo((object)"Plugin is loaded!");
			}

			private void Update()
			{
			}

			public static void ReceiveHTLNetInfo(ulong sender, HTLNetInfo netInfo)
			{
				//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_013d: 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_00f0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f9: Unknown result type (might be due to invalid IL or missing references)
				//IL_0112: Unknown result type (might be due to invalid IL or missing references)
				//IL_0113: Unknown result type (might be due to invalid IL or missing references)
				//IL_0119: Unknown result type (might be due to invalid IL or missing references)
				Log.LogInfo((object)("received data from sender " + sender + ": x:" + netInfo.X + " y:" + netInfo.Y + " z:" + netInfo.Z + " c:" + netInfo.C));
				Vector3 key = default(Vector3);
				((Vector3)(ref key))..ctor(netInfo.X, netInfo.Y, netInfo.Z);
				LG_Light val = LightsTable[key];
				if (((Behaviour)val).enabled)
				{
					if (_GlassBreak)
					{
						PlayerManager.Current.m_localPlayerAgentInLevel.Sound.Post(425881253u, true);
					}
					if (netInfo.C)
					{
						Debug.Log(Object.op_Implicit("HitTheLights - random cough playing"));
						pTriggerDialog val2 = default(pTriggerDialog);
						val2.character = (DialogCharFilter)4;
						val2.forced = true;
						val2.dialogID = _CoughDialogID;
						pTriggerDialog val3 = val2;
						PlayerDialogManager.Current.DoStartDialog(val3);
					}
					val.ChangeIntensity(0f);
					val.SetEnabled(false);
					((Behaviour)val).enabled = false;
				}
				if (!KilledTable.ContainsKey(key))
				{
					KilledTable[key] = val;
				}
			}

			private static IEnumerator HTLKill()
			{
				while (true)
				{
					foreach (KeyValuePair<Vector3, LG_Light> item in KilledTable)
					{
						if (((Behaviour)item.Value).enabled)
						{
							item.Value.ChangeIntensity(0f);
							item.Value.SetEnabled(false);
							((Behaviour)item.Value).enabled = false;
						}
					}
					yield return (object)new WaitForSeconds(1f);
				}
			}

			private static IEnumerator HTLSync()
			{
				yield return (object)new WaitForSeconds(120f);
				while (true)
				{
					if (SNet.IsMaster)
					{
						Log.LogInfo((object)"Syncing all disabled lights to peers..");
						foreach (KeyValuePair<Vector3, LG_Light> item in KilledTable)
						{
							Vector3 key = item.Key;
							new HTLInfo(key.x, key.y, key.z, c: false);
							NetworkAPI.InvokeEvent<HTLNetInfo>("HTLNetInfo", new HTLNetInfo(key.x, key.y, key.z, C: false), (SNet_ChannelType)2);
							yield return (object)new WaitForSeconds(0.5f);
						}
					}
					yield return (object)new WaitForSeconds(60f);
				}
			}
		}

		[HarmonyPatch]
		private class HitTheLights_Patches
		{
			[HarmonyPrefix]
			[HarmonyPatch(typeof(BulletWeapon), "BulletHit")]
			public static bool BulletHit(BulletWeapon __instance, WeaponHitData weaponRayData, bool doDamage, float additionalDis = 0f, uint damageSearchID = 0u)
			{
				//IL_0001: Unknown result type (might be due to invalid IL or missing references)
				//IL_0006: Unknown result type (might be due to invalid IL or missing references)
				//IL_015b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0160: Unknown result type (might be due to invalid IL or missing references)
				//IL_0171: Unknown result type (might be due to invalid IL or missing references)
				//IL_0176: Unknown result type (might be due to invalid IL or missing references)
				//IL_00d6: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f8: 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)
				//IL_019e: Unknown result type (might be due to invalid IL or missing references)
				//IL_01a3: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c3: Unknown result type (might be due to invalid IL or missing references)
				//IL_0086: 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_00a8: 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_00b1: Unknown result type (might be due to invalid IL or missing references)
				RaycastHit rayHit = weaponRayData.rayHit;
				GameObject gameObject = ((Component)((RaycastHit)(ref rayHit)).collider).gameObject;
				if (((Object)gameObject).name == "HitTheLights")
				{
					bool flag = false;
					if (Random.RandomRange(0, 100) < _CoughPercentage)
					{
						flag = true;
					}
					LG_Light component = gameObject.GetComponent<LG_Light>();
					if (((Behaviour)component).enabled)
					{
						if (_GlassBreak)
						{
							PlayerManager.Current.m_localPlayerAgentInLevel.Sound.Post(425881253u, true);
						}
						if (_Cough && flag)
						{
							Debug.Log(Object.op_Implicit("HitTheLights - random cough playing"));
							pTriggerDialog val = new pTriggerDialog
							{
								character = (DialogCharFilter)4,
								forced = true,
								dialogID = _CoughDialogID
							};
							PlayerDialogManager.Current.DoStartDialog(val);
						}
					}
					component.ChangeIntensity(0f);
					component.SetEnabled(false);
					((Behaviour)component).enabled = false;
					float x = Mathf.Round(gameObject.transform.position.x * 10f) * 0.1f;
					float y = Mathf.Round(gameObject.transform.position.y * 10f) * 0.1f;
					float z = Mathf.Round(gameObject.transform.position.z * 10f) * 0.1f;
					new HTLInfo(x, y, z, flag);
					NetworkAPI.InvokeEvent<HTLNetInfo>("HTLNetInfo", new HTLNetInfo(x, y, z, flag), (SNet_ChannelType)2);
				}
				rayHit = weaponRayData.rayHit;
				if ((Object)(object)((RaycastHit)(ref rayHit)).collider != (Object)null)
				{
					rayHit = weaponRayData.rayHit;
					if ((Object)(object)((Component)((RaycastHit)(ref rayHit)).collider).gameObject != (Object)null && weaponRayData.owner.Owner.IsBot)
					{
						rayHit = weaponRayData.rayHit;
						if (CustomExtensions.IsInLayerMask(((Component)((RaycastHit)(ref rayHit)).collider).gameObject, LayerMask.op_Implicit(LayerMask.GetMask(new string[1] { "PlayerSynced" }))))
						{
							doDamage = false;
							HitTheLights.Log.LogInfo((object)"bot FF prevented");
							return false;
						}
					}
				}
				return true;
			}

			[HarmonyPostfix]
			[HarmonyPatch(typeof(MeleeWeaponFirstPerson), "DoAttackDamage")]
			public static void DoAttackDamage(MeleeWeaponFirstPerson __instance, MeleeWeaponDamageData data)
			{
				//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
				//IL_00eb: Unknown result type (might be due to invalid IL or missing references)
				//IL_010d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0079: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_009d: Unknown result type (might be due to invalid IL or missing references)
				//IL_00a4: Unknown result type (might be due to invalid IL or missing references)
				GameObject damageGO = data.damageGO;
				if (!(((Object)damageGO).name == "HitTheLights"))
				{
					return;
				}
				bool flag = false;
				if (Random.RandomRange(0, 100) < _CoughPercentage)
				{
					flag = true;
				}
				LG_Light component = damageGO.GetComponent<LG_Light>();
				if (((Behaviour)component).enabled)
				{
					if (_GlassBreak)
					{
						PlayerManager.Current.m_localPlayerAgentInLevel.Sound.Post(425881253u, true);
					}
					if (_Cough && flag)
					{
						Debug.Log(Object.op_Implicit("HitTheLights - random cough playing"));
						pTriggerDialog val = new pTriggerDialog
						{
							character = (DialogCharFilter)4,
							forced = true,
							dialogID = _CoughDialogID
						};
						PlayerDialogManager.Current.DoStartDialog(val);
					}
				}
				component.ChangeIntensity(0f);
				component.SetEnabled(false);
				((Behaviour)component).enabled = false;
				float x = Mathf.Round(damageGO.transform.position.x * 10f) * 0.1f;
				float y = Mathf.Round(damageGO.transform.position.y * 10f) * 0.1f;
				float z = Mathf.Round(damageGO.transform.position.z * 10f) * 0.1f;
				new HTLInfo(x, y, z, flag);
				NetworkAPI.InvokeEvent<HTLNetInfo>("HTLNetInfo", new HTLNetInfo(x, y, z, flag), (SNet_ChannelType)2);
			}
		}

		public static bool _GlassBreak = false;

		public static bool _Cough = false;

		public static int _CoughPercentage = 0;

		public static uint _CoughDialogID = 173u;

		public override void Load()
		{
			//IL_0019: 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)
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0044: Expected O, but got Unknown
			//IL_0044: Expected O, but got Unknown
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			//IL_0050: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Expected O, but got Unknown
			//IL_006b: Expected O, but got Unknown
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			//IL_0093: Expected O, but got Unknown
			//IL_0093: Expected O, but got Unknown
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bd: Expected O, but got Unknown
			//IL_00bd: Expected O, but got Unknown
			//IL_00ed: Unknown result type (might be due to invalid IL or missing references)
			AcceptableValueRange<int> val = new AcceptableValueRange<int>(0, 100);
			ConfigFile val2 = new ConfigFile(Path.Combine(Paths.ConfigPath, "HitTheLights.cfg"), true);
			ConfigEntry<bool> val3 = val2.Bind<bool>(new ConfigDefinition("General", "Glass_Breaking"), true, new ConfigDescription("Extra clear glass breaking sound?", (AcceptableValueBase)null, Array.Empty<object>()));
			ConfigEntry<bool> val4 = val2.Bind<bool>(new ConfigDefinition("General", "Random_Coughing"), false, new ConfigDescription("Randomly Play hard cough on breaking a light?", (AcceptableValueBase)null, Array.Empty<object>()));
			ConfigEntry<int> val5 = val2.Bind<int>(new ConfigDefinition("General", "Chance"), 20, new ConfigDescription("Cough random chance?", (AcceptableValueBase)(object)val, Array.Empty<object>()));
			ConfigEntry<uint> obj = val2.Bind<uint>(new ConfigDefinition("General", "DialogID"), 173u, new ConfigDescription("Cough DialogID from PlayerDialogDataBlock?", (AcceptableValueBase)null, Array.Empty<object>()));
			_GlassBreak = val3.Value;
			_Cough = val4.Value;
			_CoughPercentage = val5.Value;
			_CoughDialogID = obj.Value;
			new Harmony("HitTheLights").PatchAll();
			NetworkAPI.RegisterEvent<HTLNetInfo>(HTLNetInfo.NetworkIdentity, (Action<ulong, HTLNetInfo>)HitTheLights.ReceiveHTLNetInfo);
			HitTheLights @object = ((BasePlugin)this).AddComponent<HitTheLights>();
			HitTheLights.Log = ((BasePlugin)this).Log;
			EventAPI.OnExpeditionStarted += @object.Initialize;
		}
	}
	[GeneratedCode("VersionInfoGenerator", "2.0.0+git50a4b1a-master")]
	[CompilerGenerated]
	internal static class VersionInfo
	{
		public const string RootNamespace = "HitTheLights";

		public const string Version = "1.0.0";

		public const string VersionPrerelease = null;

		public const string VersionMetadata = null;

		public const string SemVer = "1.0.0";

		public const string GitRevShort = null;

		public const string GitRevLong = null;

		public const string GitBranch = null;

		public const string GitTag = null;

		public const bool GitIsDirty = false;
	}
}