Decompiled source of SendEmFlying v1.0.0

SendEmFlying.dll

Decompiled 2 weeks ago
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using MelonLoader;
using MelonLoader.Preferences;
using ScheduleOne.Dragging;
using SendEmFlying;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: MelonInfo(typeof(global::SendEmFlying.SendEmFlying), "Send 'Em Flying", "1.0.0", "ByteOfRamen", null)]
[assembly: MelonColor]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETFramework,Version=v4.8.1", FrameworkDisplayName = ".NET Framework 4.8.1")]
[assembly: AssemblyCompany("SendEmFlying")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("SendEmFlying")]
[assembly: AssemblyTitle("SendEmFlying")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace SendEmFlying;

public static class BuildInfo
{
	public const string Name = "Send 'Em Flying";

	public const string Description = "Send draggable items and NPCs flying.";

	public const string Author = "ByteOfRamen";

	public const string Version = "1.0.0";
}
public class SendEmFlying : MelonMod
{
	[HarmonyPatch(typeof(Draggable), "Awake")]
	public class DraggableAwakePatch
	{
		public class ThrowEnhancer : MonoBehaviour
		{
			private Draggable _draggable;

			private Rigidbody _rb;

			private Vector3 _lastDragPosition;

			private float _velocityMultiplier = 1f;

			private void Awake()
			{
				//IL_0020: Unknown result type (might be due to invalid IL or missing references)
				//IL_0025: Unknown result type (might be due to invalid IL or missing references)
				_draggable = ((Component)this).GetComponent<Draggable>();
				_rb = ((Component)this).GetComponent<Rigidbody>();
				_lastDragPosition = ((Component)this).transform.position;
			}

			private void FixedUpdate()
			{
				//IL_0068: 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_0073: Unknown result type (might be due to invalid IL or missing references)
				//IL_007d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0082: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
				//IL_00f3: 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_00d0: Unknown result type (might be due to invalid IL or missing references)
				if (Object.op_Implicit((Object)(object)_draggable) && Object.op_Implicit((Object)(object)_rb))
				{
					_draggable.HoldDistanceMultiplier = _holdDistanceMultiplierEntry.Value;
					_draggable.DragForceMultiplier = _dragForceMultiplierEntry.Value;
					if (_draggable.IsBeingDragged)
					{
						Vector3 val = (((Component)this).transform.position - _lastDragPosition) / Time.fixedDeltaTime;
						_velocityMultiplier = Mathf.Lerp(_velocityMultiplier, _throwForceMultiplierEntry.Value, Time.fixedDeltaTime * 2f);
					}
					else if (_velocityMultiplier > 1f)
					{
						Rigidbody rb = _rb;
						rb.velocity *= _velocityMultiplier;
						_velocityMultiplier = 1f;
					}
					_lastDragPosition = ((Component)this).transform.position;
				}
			}
		}

		public static void Postfix(Draggable __instance)
		{
			__instance.HoldDistanceMultiplier = _holdDistanceMultiplierEntry.Value;
			__instance.DragForceMultiplier = _dragForceMultiplierEntry.Value;
			if ((Object)(object)((Component)__instance).GetComponent<ThrowEnhancer>() == (Object)null)
			{
				((Component)__instance).gameObject.AddComponent<ThrowEnhancer>();
			}
			if (_debugLoggingEntry.Value)
			{
				MelonLogger.Msg($"[SendEmFlying] Applied config: HoldDistance={__instance.HoldDistanceMultiplier}, DragForce={__instance.DragForceMultiplier} on {((Object)__instance).name}");
			}
		}
	}

	private static MelonPreferences_Category _configCategory;

	private static MelonPreferences_Entry<bool> _debugLoggingEntry;

	private static MelonPreferences_Entry<float> _holdDistanceMultiplierEntry;

	private static MelonPreferences_Entry<float> _dragForceMultiplierEntry;

	private static MelonPreferences_Entry<float> _throwForceMultiplierEntry;

	public override void OnInitializeMelon()
	{
		MelonLogger.Msg("SendEmFlying Initialized!");
		_configCategory = MelonPreferences.CreateCategory("SendEmFlying", "Send 'Em Flying");
		_debugLoggingEntry = _configCategory.CreateEntry<bool>("EnableDebugLogs", false, "Enable detailed debug logs (default: false)", (string)null, false, false, (ValueValidator)null, (string)null);
		_holdDistanceMultiplierEntry = _configCategory.CreateEntry<float>("HoldDistanceMultiplier", 2f, "Multiplier for how far objects are held from you while dragging. Recommended range: 0.5 – 2.0 (default: 1.0). Note: Range is not enforced.", (string)null, false, false, (ValueValidator)null, (string)null);
		_dragForceMultiplierEntry = _configCategory.CreateEntry<float>("DragForceMultiplier", 2f, "Controls how much force is applied when dragging objects via mouse movement. Recommended range: 0 – 5 (default: 1.0). Note: Range is not enforced.", (string)null, false, false, (ValueValidator)null, (string)null);
		_throwForceMultiplierEntry = _configCategory.CreateEntry<float>("ThrowForceMultiplier", 2f, "Multiplier for the force applied when releasing (throwing) an object. Higher values may cause physics issues. Recommended range: 1 – 20 (default: 2.0). Note: Range is not enforced.", (string)null, false, false, (ValueValidator)null, (string)null);
		MelonPreferences.Save();
	}
}