Decompiled source of OniMod v1.0.1

plugins/OniMod/MortsMod.dll

Decompiled 3 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using System.Threading;
using BepInEx;
using BepInEx.Logging;
using EmotesAPI;
using GameNetcodeStuff;
using HarmonyLib;
using LethalCompanyInputUtils.Api;
using LethalEmotesAPI.ImportV2;
using Microsoft.CodeAnalysis;
using MortsMod;
using MortsMod.NetcodePatcher;
using Unity.Netcode;
using UnityEngine;
using UnityEngine.InputSystem;

[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: AssemblyCompany("MortsMod")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("MortsMod")]
[assembly: AssemblyTitle("MortsMod")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
[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;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
[HarmonyPatch]
public class NetworkObjectManagerPatches
{
	private static GameObject networkPrefab;

	[HarmonyPostfix]
	[HarmonyPatch(typeof(GameNetworkManager), "Start")]
	public static void Init()
	{
		//IL_0033: Unknown result type (might be due to invalid IL or missing references)
		//IL_003d: Expected O, but got Unknown
		if (!((Object)(object)networkPrefab != (Object)null))
		{
			OniMod.Logs.LogInfo((object)networkPrefab);
			networkPrefab = (GameObject)OniMod.networkBundle.LoadAsset("OniNetworkHandler");
			networkPrefab.AddComponent<OniNetworker>();
			NetworkManager.Singleton.AddNetworkPrefab(networkPrefab);
		}
	}

	[HarmonyPostfix]
	[HarmonyPatch(typeof(StartOfRound), "Awake")]
	private static void SpawnNetworkHandler()
	{
		//IL_0024: 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)
		if (NetworkManager.Singleton.IsHost || NetworkManager.Singleton.IsServer)
		{
			GameObject val = Object.Instantiate<GameObject>(networkPrefab, Vector3.zero, Quaternion.identity);
			val.GetComponent<NetworkObject>().Spawn(false);
		}
	}
}
namespace MortsMod
{
	internal class Input
	{
		public class OniInput : LcInputActions
		{
			public static OniInput Instance = new OniInput();

			[InputAction("<Keyboard>/j", Name = "Toggle")]
			public InputAction? ToggleKey { get; set; }
		}
	}
	internal class OniNetworker : NetworkBehaviour
	{
		public static OniNetworker? Instance { get; private set; }

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

		[ServerRpc(RequireOwnership = false)]
		public void EventServerRpc(string eventName, int id)
		{
			//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 != 1 && (networkManager.IsClient || networkManager.IsHost))
			{
				ServerRpcParams val = default(ServerRpcParams);
				FastBufferWriter val2 = ((NetworkBehaviour)this).__beginSendServerRpc(2003577786u, val, (RpcDelivery)0);
				bool flag = eventName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(eventName, false);
				}
				BytePacker.WriteValueBitPacked(val2, id);
				((NetworkBehaviour)this).__endSendServerRpc(ref val2, 2003577786u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 1 && (networkManager.IsServer || networkManager.IsHost))
			{
				EventClientRpc(eventName, id);
			}
		}

		[ClientRpc]
		public void EventClientRpc(string eventName, int id)
		{
			//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(738200886u, val, (RpcDelivery)0);
				bool flag = eventName != null;
				((FastBufferWriter)(ref val2)).WriteValueSafe<bool>(ref flag, default(ForPrimitives));
				if (flag)
				{
					((FastBufferWriter)(ref val2)).WriteValueSafe(eventName, false);
				}
				BytePacker.WriteValueBitPacked(val2, id);
				((NetworkBehaviour)this).__endSendClientRpc(ref val2, 738200886u, val, (RpcDelivery)0);
			}
			if ((int)base.__rpc_exec_stage == 2 && (networkManager.IsClient || networkManager.IsHost) && eventName == "Demonstep")
			{
				OniMod.instance.DemonSFX(id);
			}
		}

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

		[RuntimeInitializeOnLoadMethod]
		internal static void InitializeRPCS_OniNetworker()
		{
			//IL_0011: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Expected O, but got Unknown
			NetworkManager.__rpc_func_table.Add(2003577786u, new RpcReceiveHandler(__rpc_handler_2003577786));
			NetworkManager.__rpc_func_table.Add(738200886u, new RpcReceiveHandler(__rpc_handler_738200886));
		}

		private static void __rpc_handler_2003577786(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 eventName = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref eventName, false);
				}
				int id = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref id);
				target.__rpc_exec_stage = (__RpcExecStage)1;
				((OniNetworker)(object)target).EventServerRpc(eventName, id);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		private static void __rpc_handler_738200886(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 eventName = null;
				if (flag)
				{
					((FastBufferReader)(ref reader)).ReadValueSafe(ref eventName, false);
				}
				int id = default(int);
				ByteUnpacker.ReadValueBitPacked(reader, ref id);
				target.__rpc_exec_stage = (__RpcExecStage)2;
				((OniNetworker)(object)target).EventClientRpc(eventName, id);
				target.__rpc_exec_stage = (__RpcExecStage)0;
			}
		}

		protected internal override string? __getTypeName()
		{
			return "OniNetworker";
		}
	}
	[BepInPlugin("TheOniMod", "OniMod", "1.0.0")]
	public class OniMod : BaseUnityPlugin
	{
		private readonly Harmony harmony = new Harmony("Oni.Harmony");

		public static OniMod instance;

		public static ManualLogSource Logs;

		public PlayerControllerB playerControllerInstance;

		private Vector3 forces;

		public static bool Combat = false;

		internal static AudioClip[] soundEffects;

		internal static AnimationClip[] animations;

		internal static AssetBundle bundle;

		public static AssetBundle networkBundle;

		public const string ModId = "TheOniMod";

		public const string ModName = "OniMod";

		public const string ModVersion = "1.0.0";

		internal float DemonCooldown = 1f;

		internal bool DemonOnCooldown = false;

		private float staminaDrain = 0.1f;

		private static readonly string[] controlTips = new string[1] { "Demonstep : [Right Click]" };

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

		public void ToggleCombat(CallbackContext context)
		{
			if ((Object)(object)playerControllerInstance == (Object)null)
			{
				if (!((Object)(object)GameNetworkManager.Instance.localPlayerController != (Object)null))
				{
					return;
				}
				playerControllerInstance = GameNetworkManager.Instance.localPlayerController;
			}
			if (((CallbackContext)(ref context)).performed && !playerControllerInstance.quickMenuManager.isMenuOpen && ((((NetworkBehaviour)playerControllerInstance).IsOwner && playerControllerInstance.isPlayerControlled && (!((NetworkBehaviour)playerControllerInstance).IsServer || playerControllerInstance.isHostPlayerObject)) || playerControllerInstance.isTestingPlayer) && !playerControllerInstance.inSpecialInteractAnimation && !playerControllerInstance.isTypingChat)
			{
				if (Combat)
				{
					Combat = false;
				}
				else
				{
					Combat = true;
				}
				StanceChange();
			}
		}

		public void DemonStep(CallbackContext context)
		{
			if (playerControllerInstance.sprintMeter >= staminaDrain)
			{
				if (DemonOnCooldown)
				{
					Logs.LogInfo((object)"on cooldown");
					return;
				}
				playerControllerInstance.sprintMeter = Mathf.Max(0f, playerControllerInstance.sprintMeter - staminaDrain);
				OniNetworker.Instance.EventServerRpc("Demonstep", (int)playerControllerInstance.playerClientId);
				DemonOnCooldown = true;
				try
				{
					CustomEmotesAPI.PlayAnimation("TheOniMod__Demonstep", -2);
				}
				catch
				{
					Logs.LogInfo((object)"failed to find animation");
				}
				Thread thread = new Thread(aux);
				thread.Start();
			}
			else
			{
				Logs.LogInfo((object)"Not enough stamina");
			}
			void aux()
			{
				//IL_000a: Unknown result type (might be due to invalid IL or missing references)
				//IL_000f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0016: Unknown result type (might be due to invalid IL or missing references)
				//IL_0026: Unknown result type (might be due to invalid IL or missing references)
				//IL_0030: 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_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: 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_0061: Unknown result type (might be due to invalid IL or missing references)
				//IL_0066: Unknown result type (might be due to invalid IL or missing references)
				//IL_006b: Unknown result type (might be due to invalid IL or missing references)
				for (int i = 0; i < 50; i++)
				{
					forces = Vector3.zero;
					forces = Vector3.Lerp(forces, Vector3.ClampMagnitude(((Component)playerControllerInstance).transform.forward * 125f, 75f), Time.deltaTime * 5f);
					PlayerControllerB obj2 = playerControllerInstance;
					obj2.externalForces += forces;
					Thread.Sleep((int)(DemonCooldown * 10f));
				}
				DemonOnCooldown = false;
			}
		}

		public void DemonSFX(int playerID)
		{
			AudioSource movementAudio = StartOfRound.Instance.allPlayerScripts[playerID].movementAudio;
			movementAudio.PlayOneShot(soundEffects[0]);
			WalkieTalkie.TransmitOneShotAudio(movementAudio, soundEffects[0], 1f);
		}

		public void StanceChange()
		{
			if (!playerControllerInstance.inSpecialInteractAnimation)
			{
				if (Combat)
				{
					playerControllerInstance.DropAllHeldItemsAndSync();
					playerControllerInstance.performingEmote = false;
					playerControllerInstance.StopPerformingEmoteServerRpc();
					playerControllerInstance.timeSinceStartingEmote = 0f;
					IngamePlayerSettings.Instance.playerInput.actions.FindAction("PingScan", false).performed += DemonStep;
					HUDManager.Instance.ClearControlTips();
					HUDManager.Instance.ChangeControlTipMultiple(controlTips, false, (Item)null);
				}
				else
				{
					IngamePlayerSettings.Instance.playerInput.actions.FindAction("PingScan", false).performed -= DemonStep;
					HUDManager.Instance.ClearControlTips();
				}
			}
		}

		private void Awake()
		{
			//IL_010e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0115: Expected O, but got Unknown
			NetcodePatcher();
			if ((Object)(object)instance == (Object)null)
			{
				instance = this;
			}
			harmony.PatchAll(typeof(OniMod));
			harmony.PatchAll(typeof(NetworkObjectManagerPatches));
			string location = ((BaseUnityPlugin)this).Info.Location;
			location = location.TrimEnd("Mort's mod.dll".ToCharArray());
			bundle = AssetBundle.LoadFromFile(location + "onicompany");
			Logs = Logger.CreateLogSource("TheOniMod");
			networkBundle = AssetBundle.LoadFromFile(location + "networker");
			if ((Object)(object)networkBundle == (Object)null)
			{
				Logs.LogInfo((object)"NetworkBundle failed to load");
			}
			Input.OniInput.Instance.ToggleKey.performed += ToggleCombat;
			if ((Object)(object)bundle != (Object)null)
			{
				soundEffects = bundle.LoadAllAssets<AudioClip>();
				animations = bundle.LoadAllAssets<AnimationClip>();
				CustomEmoteParams val = new CustomEmoteParams();
				val.primaryAnimationClips = animations;
				val.visible = false;
				val.audioLevel = 0f;
				val.audioLoops = false;
				val.allowJoining = false;
				val.thirdPerson = false;
				val.forceCameraMode = true;
				val.allowThirdPerson = false;
				val.displayName = " ";
				val.internalName = "Demonstep";
				val.useLocalTransforms = true;
				EmoteImporter.ImportEmote(val);
			}
			else
			{
				Logs.LogInfo((object)"Failed to load assetBundle");
			}
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "MortsMod";

		public const string PLUGIN_NAME = "MortsMod";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace MortsMod.NetcodePatcher
{
	[AttributeUsage(AttributeTargets.Module)]
	internal class NetcodePatchedAssemblyAttribute : Attribute
	{
	}
}