Decompiled source of IcePhysics v1.0.2

IcePhysics.dll

Decompiled 7 months ago
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 BepInEx.Logging;
using GameNetcodeStuff;
using HarmonyLib;
using IcePhysicsBase.Patches;
using UnityEngine;
using UnityEngine.AI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("IcePhysics")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("IcePhysics")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("5c2ece68-fc4a-4f98-a8c3-7c8a8c2545d3")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace IcePhysicsBase.Patches
{
	[HarmonyPatch(typeof(EnemyAI))]
	internal class EnemyAIPatch : BaseUnityPlugin
	{
		internal static Dictionary<int, Vector3> nextPrePosition = new Dictionary<int, Vector3>();

		internal static Dictionary<int, Vector3> nextPreVelocity = new Dictionary<int, Vector3>();

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void EnemyIcePhysicsPatch(ref bool ___isEnemyDead, ref int ___thisEnemyIndex, ref NavMeshAgent ___agent)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0107: Unknown result type (might be due to invalid IL or missing references)
			//IL_010c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0114: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Unknown result type (might be due to invalid IL or missing references)
			//IL_0126: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			int key = ___thisEnemyIndex;
			if (___isEnemyDead)
			{
				nextPrePosition.Remove(key);
				nextPreVelocity.Remove(key);
				return;
			}
			Vector3 position = ((Component)___agent).transform.position;
			if (position.z < 1000f)
			{
				if (!nextPrePosition.ContainsKey(key))
				{
					nextPrePosition.Add(key, ((Component)___agent).transform.position);
					nextPreVelocity.Add(key, Vector3.zero);
				}
				Vector3 val = nextPrePosition[key];
				Vector3 val2 = nextPreVelocity[key];
				Vector3 val3 = val + val2;
				Vector3 val4 = val3 - position;
				Vector3 val5 = default(Vector3);
				((Vector3)(ref val5))..ctor(val4.x * 0.98f, 0f, val4.z * 0.98f);
				if (((Vector3)(ref val5)).magnitude < 5f)
				{
					___agent.Move(val5);
				}
				Vector3 position2 = ((Component)___agent).transform.position;
				nextPrePosition[key] = position2;
				nextPreVelocity[key] = position2 - val;
			}
		}
	}
	[HarmonyPatch(typeof(PlayerControllerB))]
	internal class PlayerControllerBPatch : BaseUnityPlugin
	{
		internal static Dictionary<ulong, Vector3> nextPrePosition = new Dictionary<ulong, Vector3>();

		internal static Dictionary<ulong, Vector3> nextPreVelocity = new Dictionary<ulong, Vector3>();

		[HarmonyPatch("Update")]
		[HarmonyPostfix]
		private static void IcePhysicsPatch(ref Vector3 __state, ref CharacterController ___thisController, ref ulong ___playerClientId, ref bool ___isPlayerDead, ref bool ___teleportingThisFrame, ref bool ___teleportedLastFrame, ref bool ___isFallingFromJump)
		{
			//IL_0031: Unknown result type (might be due to invalid IL or missing references)
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0037: Unknown result type (might be due to invalid IL or missing references)
			//IL_0091: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ae: 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_00b2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bc: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ce: 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_007f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_0135: Unknown result type (might be due to invalid IL or missing references)
			//IL_013d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014b: Unknown result type (might be due to invalid IL or missing references)
			//IL_014d: Unknown result type (might be due to invalid IL or missing references)
			//IL_014f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0120: Unknown result type (might be due to invalid IL or missing references)
			//IL_0122: Unknown result type (might be due to invalid IL or missing references)
			ulong key = ___playerClientId;
			if (___isPlayerDead)
			{
				nextPrePosition.Remove(key);
				nextPreVelocity.Remove(key);
				return;
			}
			Vector3 position = ((Component)___thisController).transform.position;
			if (position.z < 1000f)
			{
				if (!nextPrePosition.ContainsKey(key))
				{
					nextPrePosition.Add(key, ((Component)___thisController).transform.position);
					nextPreVelocity.Add(key, Vector3.zero);
				}
				Vector3 val = nextPrePosition[key];
				Vector3 val2 = nextPreVelocity[key];
				Vector3 val3 = val + val2;
				Vector3 val4 = val3 - position;
				Vector3 val5 = default(Vector3);
				((Vector3)(ref val5))..ctor(val4.x * 0.97f, 0f, val4.z * 0.97f);
				if (___thisController.isGrounded && !___teleportingThisFrame && !___teleportedLastFrame && !___isFallingFromJump && ((Vector3)(ref val5)).magnitude > 0f && ((Vector3)(ref val5)).magnitude < 5f)
				{
					___thisController.Move(val5);
				}
				Vector3 position2 = ((Component)___thisController).transform.position;
				nextPrePosition[key] = position2;
				nextPreVelocity[key] = position2 - val;
			}
		}
	}
}
namespace IcePhysics
{
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "IcePhysics";

		public const string PLUGIN_NAME = "IcePhysics";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	[BepInPlugin("IcePhysics", "IcePhysics", "1.0.0")]
	public class IcePhysicsBase : BaseUnityPlugin
	{
		public static ConfigEntry<bool> playerIceEnabled;

		public static ConfigEntry<bool> enemyIceEnabled;

		private readonly Harmony harmony = new Harmony("IcePhysics");

		internal ManualLogSource mls;

		private static IcePhysicsBase Instance;

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			playerIceEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Player", "PlayerIceEnabled", true, "Whether or not the player gets ice physics");
			enemyIceEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>("Enemies", "EnemyIceEnabled", true, "Whether or not enemies get ice physics");
			mls = Logger.CreateLogSource("IcePhysics");
			harmony.PatchAll(typeof(IcePhysicsBase));
			if (playerIceEnabled.Value)
			{
				harmony.PatchAll(typeof(PlayerControllerBPatch));
			}
			if (enemyIceEnabled.Value)
			{
				harmony.PatchAll(typeof(EnemyAIPatch));
			}
		}
	}
}