Decompiled source of didyouseethat v1.0.0

DidYouSeeThat.dll

Decompiled a day 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 System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Configuration;
using BepInEx.Logging;
using HG;
using HG.Reflection;
using Microsoft.CodeAnalysis;
using R2API;
using RiskOfOptions;
using RiskOfOptions.OptionConfigs;
using RiskOfOptions.Options;
using RoR2;
using RoR2.HudOverlay;
using RoR2.UI;
using UnityEngine;
using UnityEngine.Networking;
using UnityEngine.UI;
using UnityHotReloadNS;

[assembly: AssemblyTitle("DidYouSeeThat")]
[assembly: AssemblyProduct("DidYouSeeThat")]
[assembly: AssemblyInformationalVersion("1.0.0+a0d9a66ad92dc0a9928a5d1da4710b844398d8c5")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyCompany("DidYouSeeThat")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: OptIn]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: CompilationRelaxations(8)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[Embedded]
	[CompilerGenerated]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Module, AllowMultiple = false, Inherited = false)]
	[Embedded]
	[CompilerGenerated]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace DidYouSeeThat
{
	[BepInPlugin("kina.DidYouSeeThat", "DidYouSeeThat", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class DidYouSeeThat : BaseUnityPlugin
	{
		private const string PluginGUID = "kina.DidYouSeeThat";

		private const string PluginAuthor = "kina";

		private const string PluginName = "DidYouSeeThat";

		private const string PluginVersion = "1.0.0";

		public static DidYouSeeThat instance;

		public GameObject lookerControllerPrefab;

		public GameObject lookerOverlayPrefab;

		public GameObject lookerVisualizerPrefab;

		public GameObject runningPrefab;

		public GameObject grayscalePrefab;

		public Sprite eyes;

		public AssetBundle skeleBundle;

		public ConfigEntry<float> lookerChance;

		private static bool UHRInstalled => Chainloader.PluginInfos.ContainsKey("iDeathHD.UnityHotReload");

		public void Awake()
		{
			//IL_012f: Unknown result type (might be due to invalid IL or missing references)
			Log.Init(((BaseUnityPlugin)this).Logger);
			instance = this;
			lookerChance = ((BaseUnityPlugin)this).Config.Bind<float>("DidYouSeeThat", "odds for the looker ..,,.,", 0.1f, "odds for :eyes: .,,. 1 = 1%.,..,");
			skeleBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "skelebundle"));
			eyes = skeleBundle.LoadAsset<Sprite>("eyes");
			runningPrefab = skeleBundle.LoadAsset<GameObject>("RunningSkelly");
			grayscalePrefab = skeleBundle.LoadAsset<GameObject>("grayscaleObject");
			lookerControllerPrefab = PrefabAPI.CreateEmptyPrefab("lookerController");
			lookerControllerPrefab.AddComponent<LookerController>();
			lookerVisualizerPrefab = PrefabAPI.CreateEmptyPrefab("lookerVisualizer", false);
			lookerVisualizerPrefab.layer = LayerIndex.ui.intVal;
			NetworkIdentity val = default(NetworkIdentity);
			if (lookerVisualizerPrefab.TryGetComponent<NetworkIdentity>(ref val))
			{
				Object.Destroy((Object)(object)val);
			}
			Image val2 = lookerVisualizerPrefab.AddComponent<Image>();
			val2.sprite = eyes;
			((Transform)lookerVisualizerPrefab.GetComponent<RectTransform>()).localScale = new Vector3(10f, 10f, 10f);
			lookerOverlayPrefab = PrefabAPI.CreateEmptyPrefab("lookerOverlay", false);
			lookerOverlayPrefab.layer = LayerIndex.ui.intVal;
			NetworkIdentity val3 = default(NetworkIdentity);
			if (lookerOverlayPrefab.TryGetComponent<NetworkIdentity>(ref val3))
			{
				Object.Destroy((Object)(object)val3);
			}
			LookerTargetViewer lookerTargetViewer = lookerOverlayPrefab.AddComponent<LookerTargetViewer>();
			((SniperTargetViewer)lookerTargetViewer).visualizerPrefab = lookerVisualizerPrefab;
			((Behaviour)lookerTargetViewer).enabled = false;
			lookerOverlayPrefab.AddComponent<SkeleRunner>();
			Run.onRunStartGlobal += CreateLookerController;
		}

		private void CreateLookerController(Run obj)
		{
			if (NetworkServer.active)
			{
				GameObject val = Object.Instantiate<GameObject>(lookerControllerPrefab);
				NetworkServer.Spawn(val);
			}
		}

		private void Update()
		{
			if (Input.GetKeyUp((KeyCode)288))
			{
				if (UHRInstalled)
				{
					Log.Debug("DidYouSeeThat.dll");
					UHRSupport.hotReload(typeof(DidYouSeeThat).Assembly, Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "DidYouSeeThat.dll"));
				}
				else
				{
					Log.Debug("couldnt finds unity hot reload !!");
				}
			}
		}
	}
	internal static class Log
	{
		private static ManualLogSource _logSource;

		internal static void Init(ManualLogSource logSource)
		{
			_logSource = logSource;
		}

		internal static void Debug(object data)
		{
			_logSource.LogDebug(data);
		}

		internal static void Error(object data)
		{
			_logSource.LogError(data);
		}

		internal static void Fatal(object data)
		{
			_logSource.LogFatal(data);
		}

		internal static void Info(object data)
		{
			_logSource.LogInfo(data);
		}

		internal static void Message(object data)
		{
			_logSource.LogMessage(data);
		}

		internal static void Warning(object data)
		{
			_logSource.LogWarning(data);
		}
	}
	public class LookerController : NetworkBehaviour
	{
		private OverlayController overlayController;

		private float secondsTimer;

		private float timeout = -1f;

		private static int kRpcRpcActivateLooker;

		private static int kRpcRpcRemoveOverlay;

		public void OnEnable()
		{
			Log.Debug("OnEnable");
			Run.onRunDestroyGlobal += delegate
			{
				Object.Destroy((Object)(object)((Component)this).gameObject);
			};
			Object.DontDestroyOnLoad((Object)(object)((Component)this).gameObject);
		}

		public void Update()
		{
			if (NetworkServer.active && !Mathf.Approximately(timeout, -1f) && timeout < Time.unscaledTime)
			{
				timeout = -1f;
				Time.timeScale = 1f;
				CallRpcRemoveOverlay();
			}
		}

		public void FixedUpdate()
		{
			if (!NetworkServer.active)
			{
				return;
			}
			secondsTimer += Time.fixedDeltaTime;
			if (!(secondsTimer < 1f))
			{
				secondsTimer = 0f;
				if (Mathf.Approximately(timeout, -1f) && Object.op_Implicit((Object)(object)Run.instance) && Random.Range(0f, 100f) < DidYouSeeThat.instance.lookerChance.Value)
				{
					CallRpcActivateLooker();
				}
			}
		}

		public void ActivateLooker()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0042: Unknown result type (might be due to invalid IL or missing references)
			timeout = Time.unscaledTime + 3f;
			overlayController = HudOverlayManager.AddOverlay(LocalUserManager.GetFirstLocalUser().cachedBodyObject, new OverlayCreationParams
			{
				prefab = DidYouSeeThat.instance.lookerOverlayPrefab,
				childLocatorEntry = "ScopeContainer"
			});
		}

		[ClientRpc]
		public void RpcActivateLooker()
		{
			Log.Debug("RpcActivateLooker");
			ActivateLooker();
		}

		public void RemoveOverlay()
		{
			Time.timeScale = 1f;
			HudOverlayManager.RemoveOverlay(overlayController);
		}

		[ClientRpc]
		public void RpcRemoveOverlay()
		{
			Log.Debug("RpcRemoveOverlay");
			RemoveOverlay();
		}

		private void UNetVersion()
		{
		}

		protected static void InvokeRpcRpcActivateLooker(NetworkBehaviour obj, NetworkReader reader)
		{
			if (!NetworkClient.active)
			{
				Debug.LogError((object)"RPC RpcActivateLooker called on server.");
			}
			else
			{
				((LookerController)(object)obj).RpcActivateLooker();
			}
		}

		protected static void InvokeRpcRpcRemoveOverlay(NetworkBehaviour obj, NetworkReader reader)
		{
			if (!NetworkClient.active)
			{
				Debug.LogError((object)"RPC RpcRemoveOverlay called on server.");
			}
			else
			{
				((LookerController)(object)obj).RpcRemoveOverlay();
			}
		}

		public void CallRpcActivateLooker()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				Debug.LogError((object)"RPC Function RpcActivateLooker called on client.");
				return;
			}
			NetworkWriter val = new NetworkWriter();
			val.Write((short)0);
			val.Write((short)2);
			val.WritePackedUInt32((uint)kRpcRpcActivateLooker);
			val.Write(((Component)this).GetComponent<NetworkIdentity>().netId);
			((NetworkBehaviour)this).SendRPCInternal(val, 0, "RpcActivateLooker");
		}

		public void CallRpcRemoveOverlay()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			//IL_001c: Expected O, but got Unknown
			//IL_0041: Unknown result type (might be due to invalid IL or missing references)
			if (!NetworkServer.active)
			{
				Debug.LogError((object)"RPC Function RpcRemoveOverlay called on client.");
				return;
			}
			NetworkWriter val = new NetworkWriter();
			val.Write((short)0);
			val.Write((short)2);
			val.WritePackedUInt32((uint)kRpcRpcRemoveOverlay);
			val.Write(((Component)this).GetComponent<NetworkIdentity>().netId);
			((NetworkBehaviour)this).SendRPCInternal(val, 0, "RpcRemoveOverlay");
		}

		static LookerController()
		{
			//IL_0020: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Expected O, but got Unknown
			//IL_004a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0054: Expected O, but got Unknown
			kRpcRpcActivateLooker = 1592189821;
			NetworkBehaviour.RegisterRpcDelegate(typeof(LookerController), kRpcRpcActivateLooker, new CmdDelegate(InvokeRpcRpcActivateLooker));
			kRpcRpcRemoveOverlay = 1454091854;
			NetworkBehaviour.RegisterRpcDelegate(typeof(LookerController), kRpcRpcRemoveOverlay, new CmdDelegate(InvokeRpcRpcRemoveOverlay));
			NetworkCRC.RegisterBehaviour("LookerController", 0);
		}

		public override bool OnSerialize(NetworkWriter writer, bool forceAll)
		{
			bool result = default(bool);
			return result;
		}

		public override void OnDeserialize(NetworkReader reader, bool initialState)
		{
		}
	}
	public class LookerTargetViewer : SniperTargetViewer
	{
		public void Update()
		{
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			List<HurtBox> list = CollectionPool<HurtBox, List<HurtBox>>.RentCollection();
			if (Object.op_Implicit((Object)(object)base.hud) && Object.op_Implicit((Object)(object)base.hud.targetMaster))
			{
				TeamIndex teamIndex = base.hud.targetMaster.teamIndex;
				IReadOnlyList<HurtBox> readOnlySniperTargetsList = HurtBox.readOnlySniperTargetsList;
				int i = 0;
				for (int count = readOnlySniperTargetsList.Count; i < count; i++)
				{
					HurtBox val = readOnlySniperTargetsList[i];
					if (Object.op_Implicit((Object)(object)val.healthComponent) && val.healthComponent.alive && (Object)(object)val.healthComponent.body != (Object)(object)base.hud.targetMaster.GetBody())
					{
						list.Add(val);
					}
				}
			}
			((SniperTargetViewer)this).SetDisplayedTargets((IReadOnlyList<HurtBox>)list);
			list = CollectionPool<HurtBox, List<HurtBox>>.ReturnCollection(list);
		}
	}
	public class SkeleRunner : MonoBehaviour
	{
		private GameObject skeleton;

		private float timer;

		public void OnEnable()
		{
			skeleton = Object.Instantiate<GameObject>(DidYouSeeThat.instance.runningPrefab, ((Component)this).gameObject.transform);
		}

		public void FixedUpdate()
		{
			timer += Time.fixedDeltaTime;
			if (!(timer < 1f))
			{
				Object.Instantiate<GameObject>(DidYouSeeThat.instance.grayscalePrefab, ((Component)this).gameObject.transform);
				((Behaviour)((Component)this).gameObject.GetComponent<SniperTargetViewer>()).enabled = true;
				Object.Destroy((Object)(object)skeleton);
				timer = -1E+13f;
				Time.timeScale = 0f;
			}
		}
	}
	internal static class UHRSupport
	{
		internal static void hotReload(Assembly assembly, string path)
		{
			UnityHotReload.LoadNewAssemblyVersion(assembly, path);
		}
	}
	public static class Utils
	{
		public static void SliderConfig(float min, float max, ConfigEntry<float> config)
		{
			//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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0023: Unknown result type (might be due to invalid IL or missing references)
			//IL_0029: Expected O, but got Unknown
			StepSliderConfig val = new StepSliderConfig
			{
				max = max,
				min = min,
				FormatString = "{0:0}"
			};
			StepSliderOption val2 = new StepSliderOption(config, val);
			ModSettingsManager.AddOption((BaseOption)(object)val2);
		}

		public static void SliderConfig(int min, int max, ConfigEntry<int> config)
		{
			//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_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0020: Expected O, but got Unknown
			//IL_0022: Unknown result type (might be due to invalid IL or missing references)
			//IL_0028: Expected O, but got Unknown
			IntSliderConfig val = new IntSliderConfig
			{
				max = max,
				min = min,
				formatString = "{0:0}"
			};
			IntSliderOption val2 = new IntSliderOption(config, val);
			ModSettingsManager.AddOption((BaseOption)(object)val2);
		}

		public static void CheckboxConfig(ConfigEntry<bool> config, bool restartRequired = false)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0016: Expected O, but got Unknown
			CheckBoxConfig val = new CheckBoxConfig();
			((BaseOptionConfig)val).restartRequired = restartRequired;
			CheckBoxOption val2 = new CheckBoxOption(config, val);
			ModSettingsManager.AddOption((BaseOption)(object)val2);
		}

		public static void StringConfig(ConfigEntry<string> config)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			InputFieldConfig val = new InputFieldConfig();
			StringInputFieldOption val2 = new StringInputFieldOption(config, val);
			ModSettingsManager.AddOption((BaseOption)(object)val2);
		}

		public static void KeyboardConfig(ConfigEntry<KeyboardShortcut> config)
		{
			//IL_0001: Unknown result type (might be due to invalid IL or missing references)
			//IL_0007: Expected O, but got Unknown
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			KeyBindConfig val = new KeyBindConfig();
			KeyBindOption val2 = new KeyBindOption(config, val);
			ModSettingsManager.AddOption((BaseOption)(object)val2);
		}
	}
}