Decompiled source of HellDivers v1.0.0

HellDivers.dll

Decompiled 8 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using ExitGames.Client.Photon;
using HarmonyLib;
using Photon.Pun;
using Photon.Realtime;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("HellDivers")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("HellDivers")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("87f31bde-0273-448d-b6e7-2ea88bd80f15")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace HellDivers;

[BepInPlugin("com.coomzy.HellDivers", "HellDivers", "1.0.0")]
public class Main : BaseUnityPlugin
{
	public static class Reflector
	{
		public static MethodInfo fallMethodInfo = typeof(PlayerRagdoll).GetMethod("Fall", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[1] { typeof(float) }, null);

		public static object[] fallParameters = new object[1];

		public static MethodInfo addForceMethodInfo = typeof(PlayerRagdoll).GetMethod("AddForce", BindingFlags.Instance | BindingFlags.NonPublic, null, new Type[2]
		{
			typeof(Vector3),
			typeof(ForceMode)
		}, null);

		public static object[] addForceParameters = new object[2];

		public static FieldInfo bodypartListFieldInfo = typeof(PlayerRagdoll).GetField("bodypartList", BindingFlags.Instance | BindingFlags.NonPublic);

		public static FieldInfo rigidbodyFieldInfo = typeof(Bodypart).GetField("rig", BindingFlags.Instance | BindingFlags.NonPublic);

		public static void Fall(PlayerRagdoll inst, float force)
		{
			if (fallMethodInfo == null)
			{
				Log("fallMethodInfo not found.");
				return;
			}
			fallParameters[0] = force;
			fallMethodInfo.Invoke(inst, fallParameters);
		}

		public static void AddForce(PlayerRagdoll inst, Vector3 force, ForceMode mode)
		{
			//IL_0024: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			if (addForceMethodInfo == null)
			{
				Log("addForceMethodInfo not found.");
				return;
			}
			addForceParameters[0] = force;
			addForceParameters[1] = mode;
			addForceMethodInfo.Invoke(inst, addForceParameters);
		}

		public static List<Bodypart> GetBodypartList(PlayerRagdoll inst)
		{
			if (bodypartListFieldInfo == null)
			{
				Log("bodypartListFieldInfo not found.");
				return null;
			}
			return (List<Bodypart>)bodypartListFieldInfo.GetValue(inst);
		}

		public static Rigidbody GetBodypartList(Bodypart inst)
		{
			//IL_002b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0031: Expected O, but got Unknown
			if (bodypartListFieldInfo == null)
			{
				Log("rigidbodyFieldInfo not found.");
				return null;
			}
			return (Rigidbody)rigidbodyFieldInfo.GetValue(inst);
		}
	}

	private static Main instance;

	public static Harmony harmony;

	public const byte DIVE_EVENT_CODE = 138;

	public ConfigEntry<KeyCode> diveKeybind { get; set; }

	public static void Log(string msg)
	{
		((BaseUnityPlugin)instance).Logger.LogInfo((object)msg);
	}

	public void Awake()
	{
		//IL_000c: Unknown result type (might be due to invalid IL or missing references)
		//IL_0016: Expected O, but got Unknown
		instance = this;
		harmony = new Harmony("coomzy.HellDivers");
		harmony.PatchAll();
		diveKeybind = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("Hotkeys", "Dive", (KeyCode)102, (ConfigDescription)null);
	}

	private void OnEnable()
	{
		PhotonNetwork.NetworkingClient.EventReceived += OnEvent;
	}

	private void OnDisable()
	{
		PhotonNetwork.NetworkingClient.EventReceived -= OnEvent;
	}

	private void OnEvent(EventData photonEvent)
	{
		if (photonEvent.Code == 138)
		{
			object[] array = (object[])photonEvent.CustomData;
			int num = (int)array[0];
			Player player = default(Player);
			if (PlayerHandler.instance.TryGetPlayerFromOwnerID(num, ref player))
			{
				OnRagdoll(player);
			}
			else
			{
				Log($"Diving Player not found {num}");
			}
		}
	}

	public void Update()
	{
		//IL_0007: 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_0093: Unknown result type (might be due to invalid IL or missing references)
		//IL_0095: Unknown result type (might be due to invalid IL or missing references)
		//IL_009b: Expected O, but got Unknown
		//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
		if (Input.GetKeyDown(diveKeybind.Value))
		{
			Player localPlayer = Player.localPlayer;
			if (!localPlayer.data.dead && localPlayer.data.isGrounded && !(((Vector3)(ref localPlayer.data.movementVector)).magnitude < 0.35f))
			{
				object[] array = new object[1] { localPlayer.refs.view.OwnerActorNr };
				RaiseEventOptions val = new RaiseEventOptions
				{
					Receivers = (ReceiverGroup)0
				};
				PhotonNetwork.RaiseEvent((byte)138, (object)array, val, SendOptions.SendReliable);
				OnRagdoll(localPlayer);
			}
		}
	}

	public void OnRagdoll(Player player)
	{
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: 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_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_0086: Unknown result type (might be due to invalid IL or missing references)
		//IL_0110: Unknown result type (might be due to invalid IL or missing references)
		//IL_0125: Unknown result type (might be due to invalid IL or missing references)
		//IL_012a: Unknown result type (might be due to invalid IL or missing references)
		//IL_0136: 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_009a: Unknown result type (might be due to invalid IL or missing references)
		//IL_009f: 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_00c5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b0: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		Reflector.Fall(player.refs.ragdoll, 3f);
		player.data.isGrounded = false;
		player.data.sinceJump = 0f;
		player.data.sinceGrounded = 0f;
		List<Bodypart> bodypartList = Reflector.GetBodypartList(player.refs.ragdoll);
		Vector3 val = ((Vector3)(ref player.data.movementVector)).normalized * 5f;
		for (int i = 0; i < bodypartList.Count; i++)
		{
			Rigidbody bodypartList2 = Reflector.GetBodypartList(bodypartList[i]);
			Vector3 val2 = val;
			if (i < 9)
			{
				val2 = val * 1.2f;
			}
			else if (i < 15)
			{
				val2 = val * 0.8f;
			}
			Vector3 velocity = bodypartList2.velocity;
			velocity.y = Mathf.Clamp(velocity.y, 0f, 100000f);
			bodypartList2.velocity = velocity;
			bodypartList2.AddForce(val2, (ForceMode)2);
		}
		Vector3 force = Vector3.up * player.refs.controller.jumpImpulse;
		Reflector.AddForce(player.refs.ragdoll, force, (ForceMode)2);
	}
}