Decompiled source of FreezeItem v1.3.0

FreezeItem.dll

Decompiled 11 hours ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: AssemblyCompany("FreezeItem")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("FreezeItem")]
[assembly: AssemblyTitle("FreezeItem")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace FreezeItem;

[BepInPlugin("lch.freezeitem", "FreezeItem", "1.3.0")]
public class FreezeItemPlugin : BaseUnityPlugin
{
	public const string GUID = "lch.freezeitem";

	public const string MODNAME = "FreezeItem";

	public const string VERSION = "1.3.0";

	private ConfigEntry<KeyCode> _freezeKey;

	private Rigidbody _frozen;

	private bool _wasKinematic;

	private void Awake()
	{
		_freezeKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "FreezeKey", (KeyCode)109, "Freeze held item in air");
	}

	private void Update()
	{
		//IL_0006: Unknown result type (might be due to invalid IL or missing references)
		try
		{
			if (!Input.GetKeyDown(_freezeKey.Value))
			{
				return;
			}
			if ((Object)(object)_frozen != (Object)null)
			{
				_frozen.isKinematic = _wasKinematic;
				_frozen.useGravity = true;
				_frozen = null;
				return;
			}
			PhysGrabber instance = PhysGrabber.instance;
			if ((Object)(object)instance == (Object)null)
			{
				return;
			}
			object? value = AccessTools.Field(typeof(PhysGrabber), "grabbedPhysGrabObject").GetValue(instance);
			PhysGrabObject val = (PhysGrabObject)((value is PhysGrabObject) ? value : null);
			if (!((Object)(object)val == (Object)null))
			{
				Rigidbody component = ((Component)val).GetComponent<Rigidbody>();
				if (!((Object)(object)component == (Object)null))
				{
					instance.ReleaseObject(0, 0f);
					_frozen = component;
					_wasKinematic = component.isKinematic;
					component.isKinematic = true;
					component.useGravity = false;
				}
			}
		}
		catch
		{
		}
	}
}