Decompiled source of VEM Extended v1.1.0

VEMExtended.dll

Decompiled 9 hours ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using Dissonance;
using HarmonyLib;
using LethalLib.Modules;
using Microsoft.CodeAnalysis;
using Unity.Netcode;
using UnityEngine;
using VEMExtended.Behaviours;
using VEMExtended.NetcodePatcher;
using VEMExtended.Networking;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("VEMExtended")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("VEMExtended")]
[assembly: AssemblyTitle("VEMExtended")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: NetcodePatchedAssembly]
internal class <Module>
{
	static <Module>()
	{
	}
}
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 VEMExtended
{
	[BepInPlugin("rico.VEMExtended", "VEM Extended", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		private const string GUID = "rico.VEMExtended";

		private const string NAME = "VEM Extended";

		private const string VERSION = "1.0.0";

		public static Plugin instance;

		private static void NetcodePatcher()
		{
			Type[] types = Assembly.GetExecutingAssembly().GetTypes();
			for (int i = 0; i < types.Length; i++)
			{
				MethodInfo[] methods = types[i].GetMethods(BindingFlags.Instance | BindingFlags.Static | BindingFlags.NonPublic);
				foreach (MethodInfo methodInfo in methods)
				{
					if (methodInfo.GetCustomAttributes(typeof(RuntimeInitializeOnLoadMethodAttribute), inherit: false).Length != 0)
					{
						methodInfo.Invoke(null, null);
					}
				}
			}
		}

		public void Awake()
		{
			NetcodePatcher();
			AssetBundle obj = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "vemassets"));
			Item val = obj.LoadAsset<Item>("Assets/VEM/HorlosWatch/HorlosWatchItem.asset");
			Item val2 = obj.LoadAsset<Item>("Assets/VEM/ReubenViool/ReubenVioolItem.asset");
			Item val3 = obj.LoadAsset<Item>("Assets/VEM/CharlGoldKrink/CharlKrinkItem.asset");
			Item val4 = obj.LoadAsset<Item>("Assets/VEM/AndriesMicrophone/AndriesMicItem.asset");
			ExtendMicDistance extendMicDistance = val4.spawnPrefab.AddComponent<ExtendMicDistance>();
			((GrabbableObject)extendMicDistance).grabbable = true;
			((GrabbableObject)extendMicDistance).grabbableToEnemies = true;
			((GrabbableObject)extendMicDistance).isInFactory = true;
			((GrabbableObject)extendMicDistance).itemProperties = val4;
			Utilities.FixMixerGroups(val.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(val.spawnPrefab);
			Utilities.FixMixerGroups(val2.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(val2.spawnPrefab);
			Utilities.FixMixerGroups(val3.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(val3.spawnPrefab);
			Utilities.FixMixerGroups(val4.spawnPrefab);
			NetworkPrefabs.RegisterNetworkPrefab(val4.spawnPrefab);
			val.minValue = 100;
			val.maxValue = 190;
			val2.minValue = 150;
			val2.maxValue = 230;
			Items.RegisterScrap(val, 25, (LevelTypes)(-1));
			Items.RegisterScrap(val2, 10, (LevelTypes)256);
			Items.RegisterScrap(val3, 20, (LevelTypes)512);
			Items.RegisterScrap(val4, 35, (LevelTypes)(-1));
			Items.RegisterShopItem(val4, 0);
			string text = "-~-~-~-~-~-~-~-~-~-~-~-~-~- VEM EXTENDED -~-~-~-~-~-~-~-~-~-~-~-~-~-\r\n                                                                                \r\n                     .(#/           *(. ,,                                      \r\n                   ,     /  ./##((((*    *   .*(// *                            \r\n                   *   */               .*    *   (                             \r\n                     *            */(.    #     %,                              \r\n                   .,   *  ..    ,.  *    /        .                            \r\n                   ,   *                  /       ./#                           \r\n                    (          .%  #     *      *, .*                           \r\n                     /                 ./     ,*  #                             \r\n                        /.            #**.   (  (.                              \r\n                             ,%#((#*       .%#                                  \r\n                            *,               /                                  \r\n               #    ,*     /                 /                                  \r\n                 .(    (, *                  /                                  \r\n                          *                  /                                  \r\n                          /                ./                                   \r\n                           .,             #, #                                  \r\n                              #,       ,/  ,  *.                                \r\n                                 /  ,      /   ..                               \r\n                                /   *      ,,  ..                               \r\n                               ,.   *       ./ /                                \r\n                                # **                                            ";
			Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "rico.VEMExtended");
			((BaseUnityPlugin)this).Logger.LogInfo((object)"VEM Extended 1.0.0 has succesfully loaded!");
			((BaseUnityPlugin)this).Logger.LogInfo((object)text);
		}
	}
	[HarmonyPatch]
	public class NetworkObjectManager
	{
		public static AssetBundle networkBundle = AssetBundle.LoadFromFile(Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location), "networkassets"));

		[HarmonyPostfix]
		[HarmonyPatch(typeof(GameNetworkManager))]
		[HarmonyPatch("Start")]
		public static void Init()
		{
			GameObject val = networkBundle.LoadAsset<GameObject>("Assets/VEM/Utilities/VEM_NetworkHandler.prefab");
			val.AddComponent<VEM_NetworkHandler>();
			NetworkManager.Singleton.AddNetworkPrefab(val);
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(StartOfRound))]
		[HarmonyPatch("Awake")]
		private static void SpawnNetworkHandler()
		{
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				Object.Instantiate<GameObject>(networkBundle.LoadAsset<GameObject>("Assets/VEM/Utilities/VEM_NetworkHandler.prefab"), Vector3.zero, Quaternion.identity).GetComponent<NetworkObject>().Spawn(false);
			}
		}
	}
	[HarmonyPatch]
	public class VEMEvent_Manager
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(RoundManager))]
		[HarmonyPatch("GenerateNewFloor")]
		private static void SubscribeToMicUpdate()
		{
			VEM_NetworkHandler.updateMic += updateMicRange;
			Console.WriteLine("Added updateMicRange method to event");
			Console.WriteLine("Added updateMicRange method to event");
			Console.WriteLine("Added updateMicRange method to event");
			Console.WriteLine("Added updateMicRange method to event");
			Console.WriteLine("Added updateMicRange method to event");
			Console.WriteLine("Added updateMicRange method to event");
			Console.WriteLine("Added updateMicRange method to event");
			Console.WriteLine("Added updateMicRange method to event");
		}

		[HarmonyPostfix]
		[HarmonyPatch(typeof(RoundManager))]
		[HarmonyPatch("DespawnPropsAtEndOfRound")]
		private static void UnSubscribeToMicUpdate()
		{
			VEM_NetworkHandler.updateMic -= updateMicRange;
		}

		private static void updateMicRange(string eventName, string playbackUUID, int rangeModification)
		{
			string localPlayerName = GameObject.Find("DissonanceSetup").GetComponent<DissonanceComms>().LocalPlayerName;
			if (!(playbackUUID == localPlayerName))
			{
				GameObject val = GameObject.Find("Player " + playbackUUID + " voice comms");
				val.GetComponent<AudioSource>().maxDistance = val.GetComponent<AudioSource>().maxDistance + (float)rangeModification;
			}
		}
	}
}
namespace VEMExtended.Networking
{
	public class VEM_NetworkHandler : NetworkBehaviour
	{
		public static VEM_NetworkHandler Instance { get; private set; }

		public static event Action<string, string, int> updateMic;

		[ClientRpc]
		public void updateMicClientRpc(string playbackUUID, int rangeModification)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_002e: Invalid comparison between Unknown and I4
			//IL_00d7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Invalid comparison between Unknown and I4
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: Unknown result type (might be due to invalid IL or missing references)
			//IL_006d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0088: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c7: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = ((NetworkBehaviour)this).NetworkManager;
			if (networkManager == null || !networkManager.IsListening)
			{
				return;
			}
			if ((int)base.__rpc_exec_stage != 2 && (networkManager.IsServer || networkManager.IsHost))
			{
				ClientRpcParams val = default(ClientRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendClientRpc(2162863389u, val, (RpcDelivery)0);
				bool flag = playbackUUID != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(playbackUUID, false);
				}
				BytePacker.WriteValueBitPacked(val2, rangeModification);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 2162863389u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost))
			{
				string arg = "updateMic";
				if (VEM_NetworkHandler.updateMic != null)
				{
					VEM_NetworkHandler.updateMic(arg, playbackUUID, rangeModification);
				}
			}
		}

		public override void OnNetworkSpawn()
		{
			VEM_NetworkHandler.updateMic = null;
			if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
			{
				VEM_NetworkHandler instance = Instance;
				if (instance != null)
				{
					((Component)instance).gameObject.GetComponent<NetworkObject>().Despawn(true);
				}
			}
			Instance = this;
			((NetworkBehaviour)this).OnNetworkSpawn();
		}

		protected override void __initializeVariables()
		{
			((NetworkBehaviour)this).__initializeVariables();
		}

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_VEM_NetworkHandler()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(2162863389u, new RpcReceiveHandler(__rpc_handler_2162863389));
		}

		private static void __rpc_handler_2162863389(NetworkBehaviour target, FastBufferReader reader, __RpcParams rpcParams)
		{
			//IL_002f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_008c: Unknown result type (might be due to invalid IL or missing references)
			NetworkManager networkManager = target.NetworkManager;
			if (networkManager != null && networkManager.IsListening)
			{
				bool flag = default(bool);
				((FastBufferReader)(ref reader)).ReadValueSafe<bool>(ref flag, default(ForPrimitives));
				string playbackUUID = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref playbackUUID, false);
				}
				int rangeModification = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref rangeModification);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((VEM_NetworkHandler)(object)target).updateMicClientRpc(playbackUUID, rangeModification);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string __getTypeName()
		{
			return "VEM_NetworkHandler";
		}
	}
}
namespace VEMExtended.Behaviours
{
	internal class ExtendMicDistance : PhysicsProp
	{
		public override void GrabItem()
		{
			((GrabbableObject)this).GrabItem();
			string localPlayerName = GameObject.Find("DissonanceSetup").GetComponent<DissonanceComms>().LocalPlayerName;
			VEM_NetworkHandler.Instance.updateMicClientRpc(localPlayerName, 200);
		}

		public override void DiscardItem()
		{
			string localPlayerName = GameObject.Find("DissonanceSetup").GetComponent<DissonanceComms>().LocalPlayerName;
			VEM_NetworkHandler.Instance.updateMicClientRpc(localPlayerName, -200);
			((GrabbableObject)this).DiscardItem();
		}

		protected override void __initializeVariables()
		{
			((PhysicsProp)this).__initializeVariables();
		}

		protected internal override string __getTypeName()
		{
			return "ExtendMicDistance";
		}
	}
}
namespace VEMExtended.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}