Decompiled source of CCTV Stalk Ur Friends Patcher v1.0.0

BepInEx/plugins/CCTV_Patcher.dll

Decompiled a month ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Krild_CCTV_Stalk_Ur_Friends.Behaviours;
using Microsoft.CodeAnalysis;
using UnityEngine;

[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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("JustDave2")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("CCTV_Patcher")]
[assembly: AssemblyTitle("CCTV_Patcher")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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;
		}
	}
}
namespace CCTVPatch
{
	[BepInPlugin("JustDave2.CCTVPatch", "CCTV_Stalk_Ur_Friends_Patch", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class CCTVPatchPlugin : BaseUnityPlugin
	{
		internal static ManualLogSource log;

		private void Awake()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			log = ((BaseUnityPlugin)this).Logger;
			new Harmony("JustDave2.CCTVPatch").PatchAll();
			log.LogInfo((object)"CCTV Patch loaded — replacing Start() to avoid the broken localCameraTransform field.");
		}
	}
	[HarmonyPatch(typeof(KrildItemMonitor), "Start")]
	public static class Start_Patch
	{
		private static readonly Type monitorType = typeof(KrildItemMonitor);

		private static readonly Type cctvPlayerType = monitorType.GetNestedType("CCTVPlayer", BindingFlags.Public);

		private static readonly ConstructorInfo cctvPlayerCtor = cctvPlayerType.GetConstructor(new Type[3]
		{
			typeof(string),
			typeof(Transform),
			typeof(PlayerAvatar)
		});

		private static readonly FieldInfo cameraItemField = monitorType.GetField("cameraItem", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo cameraTransformField = monitorType.GetField("cameraTransform", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo itemToggleField = monitorType.GetField("itemToggle", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo defaultTextCamNameField = monitorType.GetField("defaultTextCamName", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo transformShipCamField = monitorType.GetField("transformShipCam", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo listPlayerSortedField = monitorType.GetField("listPlayerSorted", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo cameraPlayerLocalPositionField = monitorType.GetField("cameraPlayerLocalPosition", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo cameraPlayerClippingPlaneNearField = monitorType.GetField("cameraPlayerClippingPlaneNear", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly FieldInfo cameraFOVField = monitorType.GetField("cameraFOV", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly MethodInfo setCamNameMethod = monitorType.GetMethod("SetCamName", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly MethodInfo setShipCamMethod = monitorType.GetMethod("SetShipCam", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly MethodInfo setMaxPlayerMethod = monitorType.GetMethod("SetMaxPlayer", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly MethodInfo waitAndLoadDeadHeadMethod = monitorType.GetMethod("WaitAndLoadDeadHead", BindingFlags.Instance | BindingFlags.NonPublic);

		private static readonly MethodInfo startCoroutineMethod = typeof(MonoBehaviour).GetMethod("StartCoroutine", new Type[1] { typeof(IEnumerator) });

		private static bool Prefix(KrildItemMonitor __instance)
		{
			//IL_0077: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fe: Unknown result type (might be due to invalid IL or missing references)
			//IL_0105: Expected O, but got Unknown
			Type type = monitorType.Assembly.GetType("Krild_CCTV_Stalk_Ur_Friends.KrildPatcher");
			object value = type.GetField("current", BindingFlags.Static | BindingFlags.NonPublic).GetValue(null);
			object value2 = type.GetField("_CameraPlayerLocalPositionOverview").GetValue(value);
			object value3 = type.GetField("_CameraPlayerClippingPlaneNear").GetValue(value);
			object value4 = type.GetField("_CameraFOV").GetValue(value);
			Vector3 val = (Vector3)value2.GetType().GetProperty("Value").GetValue(value2);
			float num = (float)value3.GetType().GetProperty("Value").GetValue(value3);
			float num2 = (float)value4.GetType().GetProperty("Value").GetValue(value4);
			cameraPlayerLocalPositionField.SetValue(__instance, val);
			cameraPlayerClippingPlaneNearField.SetValue(__instance, num);
			cameraFOVField.SetValue(__instance, num2);
			Camera val2 = (Camera)cameraItemField.GetValue(__instance);
			cameraTransformField.SetValue(__instance, ((Component)val2).transform);
			val2.fieldOfView = num2;
			itemToggleField.SetValue(__instance, ((Component)__instance).GetComponent<ItemToggle>());
			setCamNameMethod.Invoke(__instance, new object[1] { (string)defaultTextCamNameField.GetValue(__instance) });
			transformShipCamField.SetValue(__instance, GameObject.Find("cctv camera").transform);
			setShipCamMethod.Invoke(__instance, null);
			setMaxPlayerMethod.Invoke(__instance, null);
			List<string> list = new List<string>();
			foreach (PlayerAvatar player in GameDirector.instance.PlayerList)
			{
				list.Add(SemiFunc.PlayerGetName(player));
			}
			list.Sort();
			IList list2 = Activator.CreateInstance(typeof(List<>).MakeGenericType(cctvPlayerType)) as IList;
			foreach (string item in list)
			{
				for (int i = 0; i < list.Count; i++)
				{
					if (item == SemiFunc.PlayerGetName(GameDirector.instance.PlayerList[i]))
					{
						object value5 = cctvPlayerCtor.Invoke(new object[3]
						{
							item,
							((Component)GameDirector.instance.PlayerList[i].localCamera).transform,
							GameDirector.instance.PlayerList[i]
						});
						list2.Add(value5);
					}
				}
			}
			listPlayerSortedField.SetValue(__instance, list2);
			if ((Object)(object)KrildCameraManager.current == (Object)null)
			{
				GameObject.Find("Pun Manager").AddComponent<KrildCameraManager>();
			}
			IEnumerator enumerator3 = (IEnumerator)waitAndLoadDeadHeadMethod.Invoke(__instance, null);
			startCoroutineMethod.Invoke(__instance, new object[1] { enumerator3 });
			return false;
		}
	}
}