Decompiled source of CameraLocator v1.0.1

CW-CameraLocator.dll

Decompiled 4 hours ago
using System;
using System.CodeDom.Compiler;
using System.ComponentModel;
using System.Diagnostics;
using System.Globalization;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Logging;
using CW_CameraLocator.Properties;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using ShopUtils;
using TMPro;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("CW-CameraLocator")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("CW-CameraLocator")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c057dd1b-d367-4fab-915f-e235128f6bb5")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[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;
		}
	}
}
namespace CW_CameraLocator
{
	[BepInPlugin("Electric131.CameraLocator", "CameraLocator", "1.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public class CameraLocatorBehavior : ItemInstanceBehaviour
		{
			public enum LocatorState
			{
				OFF,
				NO_SIGNAL,
				LOCATED
			}

			private BatteryEntry? batteryEntry;

			private OnOffEntry? onOffEntry;

			private TimeEntry? lastPingEntry;

			private TMP_Text? screenText;

			public float maxCharge = 30f;

			public void UpdateScreenText(LocatorState state)
			{
				//IL_0057: Unknown result type (might be due to invalid IL or missing references)
				//IL_007b: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)screenText))
				{
					switch (state)
					{
					case LocatorState.OFF:
						screenText.text = "";
						break;
					case LocatorState.NO_SIGNAL:
						screenText.text = "No Signal";
						((Graphic)screenText).color = Color.red;
						break;
					case LocatorState.LOCATED:
						screenText.text = "Signal Located";
						((Graphic)screenText).color = Color.green;
						break;
					}
				}
			}

			public override void ConfigItem(ItemInstanceData data, PhotonView playerView)
			{
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_001b: 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_0038: Expected O, but got Unknown
				//IL_005b: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_006c: Expected O, but got Unknown
				//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_00a4: Expected O, but got Unknown
				if (!data.TryGetEntry<BatteryEntry>(ref batteryEntry))
				{
					batteryEntry = new BatteryEntry
					{
						m_charge = maxCharge,
						m_maxCharge = maxCharge
					};
					data.AddDataEntry((ItemDataEntry)(object)batteryEntry);
				}
				if (!data.TryGetEntry<OnOffEntry>(ref onOffEntry))
				{
					onOffEntry = new OnOffEntry
					{
						on = false
					};
					data.AddDataEntry((ItemDataEntry)(object)onOffEntry);
				}
				if (!data.TryGetEntry<TimeEntry>(ref lastPingEntry))
				{
					lastPingEntry = new TimeEntry
					{
						currentTime = 0f
					};
					data.AddDataEntry((ItemDataEntry)(object)lastPingEntry);
				}
				screenText = ((Component)((Component)this).transform.Find("Physical/Screen/ScreenText")).gameObject.GetComponent<TMP_Text>();
			}

			public void Update()
			{
				//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ff: Unknown result type (might be due to invalid IL or missing references)
				//IL_01c7: Unknown result type (might be due to invalid IL or missing references)
				if (base.isHeldByMe && !Player.localPlayer.HasLockedInput() && Player.localPlayer.input.clickWasPressed)
				{
					onOffEntry.on = !onOffEntry.on;
					((ItemDataEntry)onOffEntry).SetDirty();
				}
				if (onOffEntry.on && batteryEntry.m_charge > 0f)
				{
					BatteryEntry? obj = batteryEntry;
					obj.m_charge -= Time.deltaTime;
					ItemInstance[] array = Object.FindObjectsOfType<ItemInstance>();
					GameObject val = null;
					float num = 50f;
					ItemInstance[] array2 = array;
					foreach (ItemInstance val2 in array2)
					{
						if (((Object)val2).name == "Camera1(Clone)" || ((Object)val2).name == "BrokenCamera(Clone)")
						{
							float num2 = Vector3.Distance(((Component)val2).gameObject.transform.position, ((Component)this).transform.position);
							if (!(num2 >= num))
							{
								val = ((Component)val2).gameObject;
								num = num2;
							}
						}
					}
					if ((Object)(object)val != (Object)null)
					{
						UpdateScreenText(LocatorState.LOCATED);
						TimeEntry? obj2 = lastPingEntry;
						obj2.currentTime += Time.deltaTime;
						float num3 = Mathf.Max(0.0023f * Mathf.Pow(num, 1.8f) + 0.4f, 0.5f);
						if (num < 8f)
						{
							num3 = 0.2f;
						}
						if (lastPingEntry.currentTime > num3)
						{
							sfxInstance.Play(((Component)this).transform.position, false, 1f, (Transform)null);
							lastPingEntry.currentTime = 0f;
						}
					}
					else
					{
						UpdateScreenText(LocatorState.NO_SIGNAL);
						lastPingEntry.currentTime = 0f;
					}
				}
				else
				{
					UpdateScreenText(LocatorState.OFF);
					lastPingEntry.currentTime = 0f;
				}
			}
		}

		public const string ModGUID = "Electric131.CameraLocator";

		public const string ModName = "CameraLocator";

		public const string ModVersion = "1.0.1";

		public static ManualLogSource? logger;

		public static Item? locatorItem;

		public static GameObject? locatorObject;

		public static AudioClip? pingSound;

		public static SFX_Instance? sfxInstance;

		private void Awake()
		{
			logger = ((BaseUnityPlugin)this).Logger;
			logger.LogInfo((object)"Plugin Electric131.CameraLocator loaded, preparing to load resources!");
			AssetBundle val = AssetBundle.LoadFromMemory(Resources.cameralocator);
			locatorItem = val.LoadAsset<Item>("Assets/CameraLocatorItem.asset");
			locatorObject = val.LoadAsset<GameObject>("Assets/CameraLocatorObject.prefab");
			sfxInstance = val.LoadAsset<SFX_Instance>("Assets/CameraLocator-SFX.asset");
			locatorObject.AddComponent<ItemInstance>();
			locatorObject.AddComponent<CameraLocatorBehavior>();
			logger.LogInfo((object)"Assets loaded, registering item with game");
			Items.RegisterShopItem(locatorItem, (ShopItemCategory)0, -1);
			logger.LogInfo((object)"Item loaded and registered successfully");
		}
	}
}
namespace CW_CameraLocator.Properties
{
	[GeneratedCode("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")]
	[DebuggerNonUserCode]
	[CompilerGenerated]
	internal class Resources
	{
		private static ResourceManager resourceMan;

		private static CultureInfo resourceCulture;

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static ResourceManager ResourceManager
		{
			get
			{
				if (resourceMan == null)
				{
					ResourceManager resourceManager = new ResourceManager("CW_CameraLocator.Properties.Resources", typeof(Resources).Assembly);
					resourceMan = resourceManager;
				}
				return resourceMan;
			}
		}

		[EditorBrowsable(EditorBrowsableState.Advanced)]
		internal static CultureInfo Culture
		{
			get
			{
				return resourceCulture;
			}
			set
			{
				resourceCulture = value;
			}
		}

		internal static byte[] cameralocator
		{
			get
			{
				object @object = ResourceManager.GetObject("cameralocator", resourceCulture);
				return (byte[])@object;
			}
		}

		internal Resources()
		{
		}
	}
}