Decompiled source of StrongerGrip v0.2.0

Mods/StrongerGrip.dll

Decompiled 2 days ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using HarmonyLib;
using Il2CppScheduleOne.PlayerTasks;
using MelonLoader;
using MelonLoader.Preferences;
using Microsoft.CodeAnalysis;
using StrongerGrip;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: MelonInfo(typeof(StrongerGripMod), "Stronger Grip", "0.2.0", "SeaDoge", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: MelonPlatformDomain(/*Could not decode attribute arguments.*/)]
[assembly: MelonOptionalDependencies(new string[] { "ModManager&PhoneApp" })]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("StrongerGrip")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("0.2.0.0")]
[assembly: AssemblyInformationalVersion("0.2.0")]
[assembly: AssemblyProduct("StrongerGrip")]
[assembly: AssemblyTitle("StrongerGrip")]
[assembly: AssemblyVersion("0.2.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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]
	[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]
	[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;
		}
	}
}
namespace StrongerGrip
{
	public sealed class StrongerGripMod : MelonMod
	{
		private const float DefaultMultiplier = 3f;

		private const float MinimumMultiplier = 1f;

		private const float MaximumMultiplier = 10f;

		private MelonPreferences_Entry<float> multiplierPreference;

		internal static float GripMultiplier { get; private set; } = 3f;

		public override void OnInitializeMelon()
		{
			MelonPreferences_Category val = MelonPreferences.CreateCategory("StrongerGrip", "Stronger Grip");
			multiplierPreference = val.CreateEntry<float>("GripMultiplier", 3f, "Grip Strength Multiplier", "Strength of workstation item dragging. Range: 1.0 to 10.0.", false, false, (ValueValidator)null, (string)null);
			GripMultiplier = Math.Clamp(multiplierPreference.Value, 1f, 10f);
			if (GripMultiplier != multiplierPreference.Value)
			{
				((MelonBase)this).LoggerInstance.Warning($"GripMultiplier {multiplierPreference.Value} is outside the supported range {1f}-{10f}; using {GripMultiplier}.");
				multiplierPreference.Value = GripMultiplier;
			}
			((MelonEventBase<LemonAction<float, float>>)(object)multiplierPreference.OnEntryValueChanged).Subscribe((LemonAction<float, float>)OnMultiplierChanged, 0, false);
			((MelonBase)this).HarmonyInstance.PatchAll(typeof(StrongerGripMod).Assembly);
			((MelonBase)this).LoggerInstance.Msg($"Initialized for IL2CPP. Task dragging force is {GripMultiplier:0.##}x.");
		}

		private void OnMultiplierChanged(float oldValue, float newValue)
		{
			float num = Math.Clamp(newValue, 1f, 10f);
			if (num != newValue)
			{
				((MelonBase)this).LoggerInstance.Warning($"GripMultiplier {newValue} is outside the supported range {1f}-{10f}; using {num}.");
				multiplierPreference.Value = num;
				return;
			}
			float gripMultiplier = GripMultiplier;
			if (gripMultiplier == num)
			{
				return;
			}
			GripMultiplier = num;
			float num2 = num / gripMultiplier;
			int num3 = 0;
			foreach (Draggable item in Resources.FindObjectsOfTypeAll<Draggable>())
			{
				if (!((Object)(object)item == (Object)null) && ((Behaviour)item).isActiveAndEnabled)
				{
					item.DragForceMultiplier *= num2;
					num3++;
				}
			}
			((MelonBase)this).LoggerInstance.Msg($"Task dragging force changed to {GripMultiplier:0.##}x; updated {num3} active object(s).");
		}
	}
	[HarmonyPatch(typeof(Draggable), "Awake")]
	internal static class DraggableAwakePatch
	{
		private static void Postfix(Draggable __instance)
		{
			__instance.DragForceMultiplier *= StrongerGripMod.GripMultiplier;
		}
	}
}