Decompiled source of QualityEffects v1.1.0

QualityEffects.dll

Decompiled 3 weeks ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using HarmonyLib;
using Il2CppInterop.Runtime;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppScheduleOne.ItemFramework;
using Il2CppScheduleOne.PlayerScripts;
using Il2CppScheduleOne.Properties;
using Il2CppSystem;
using Il2CppSystem.Reflection;
using MelonLoader;
using Microsoft.CodeAnalysis;
using QualityEffects;
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::QualityEffects.QualityEffects), "QualityEffects", "1.0.0", "SoulDaSythe", null)]
[assembly: MelonGame("TVGS", "Schedule I")]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("QualityEffects")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("QualityEffects")]
[assembly: AssemblyTitle("QualityEffects")]
[assembly: NeutralResourcesLanguage("en-US")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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 QualityEffects
{
	public static class BuildInfo
	{
		public const string Name = "Quality Effects";

		public const string Description = "This weed is awful, I can barely feel it!";

		public const string Author = "SoulDaSythe & Jumble";

		public const string Company = null;

		public const string Version = "1.0";

		public const string DownloadLink = null;
	}
	public class QualityEffects : MelonMod
	{
		[HarmonyPatch(typeof(Athletic), "ApplyToPlayer")]
		public static class Patch_Athletic_ApplyToPlayer
		{
			public static void Postfix(Athletic __instance, Player player)
			{
				try
				{
					PlayerMovement componentInChildren = ((Component)player).GetComponentInChildren<PlayerMovement>();
					if ((Object)(object)componentInChildren == (Object)null)
					{
						Melon<QualityEffects>.Logger.Msg("[ATHLETIC] ❌ PlayerMovement not found in children.");
						return;
					}
					Melon<QualityEffects>.Logger.Msg($"[ATHLETIC] Base Value -> {componentInChildren.MoveSpeedMultiplier}");
					float multiplier = QualityEffectsHelper.GetMultiplier(player.ConsumedProduct, "ATHLETIC");
					float num = (componentInChildren.MoveSpeedMultiplier - 1f) * multiplier + 1f;
					AthleticDifference = num - 1f;
					componentInChildren.MoveSpeedMultiplier = num;
					if (EnergizingActive && EnergizingDifference != 0f)
					{
						num += EnergizingDifference;
					}
					AthleticActive = true;
					Melon<QualityEffects>.Logger.Msg($"[ATHLETIC] ✅ Applied multiplier: {multiplier:F2}, New Speed: {num:F2}");
				}
				catch (Exception ex)
				{
					Melon<QualityEffects>.Logger.Msg("[ATHLETIC] ❌ Exception in Postfix: " + ex.Message);
				}
			}
		}

		[HarmonyPatch(typeof(Athletic), "ClearFromPlayer")]
		public static class Patch_Athletic_ClearFromPlayer
		{
			public static void Postfix()
			{
				AthleticActive = false;
			}
		}

		[HarmonyPatch(typeof(Energizing), "ApplyToPlayer")]
		public static class Patch_Energizing_ApplyToPlayer
		{
			public static void Postfix(Energizing __instance, Player player)
			{
				try
				{
					PlayerMovement componentInChildren = ((Component)player).GetComponentInChildren<PlayerMovement>();
					if ((Object)(object)componentInChildren == (Object)null)
					{
						Melon<QualityEffects>.Logger.Msg("[Energizing] ❌ PlayerMovement not found in children.");
						return;
					}
					float multiplier = QualityEffectsHelper.GetMultiplier(player.ConsumedProduct, "Energizing");
					Melon<QualityEffects>.Logger.Msg($"[Energizing] Base Value -> {componentInChildren.MoveSpeedMultiplier}");
					float num = (componentInChildren.MoveSpeedMultiplier - 1f) * multiplier + 1f;
					EnergizingDifference = num - 1f;
					componentInChildren.MoveSpeedMultiplier = num;
					if (AthleticActive && AthleticDifference != 0f)
					{
						num += AthleticDifference;
					}
					EnergizingActive = true;
					Melon<QualityEffects>.Logger.Msg($"[Energizing] ✅ Applied multiplier: {multiplier:F2}, New Speed: {componentInChildren.MoveSpeedMultiplier:F2}");
				}
				catch (Exception ex)
				{
					Melon<QualityEffects>.Logger.Msg("[Energizing] ❌ Exception in Postfix: " + ex.Message);
				}
			}
		}

		[HarmonyPatch(typeof(Energizing), "ClearFromPlayer")]
		public static class Patch_Energizing_ClearFromPlayer
		{
			public static void Postfix()
			{
				EnergizingActive = false;
			}
		}

		[HarmonyPatch(typeof(AntiGravity), "ApplyToPlayer")]
		public static class Patch_AntiGrav_ApplyToPlayer
		{
			public static void Postfix(AntiGravity __instance, Player player)
			{
				try
				{
					PlayerMovement componentInChildren = ((Component)player).GetComponentInChildren<PlayerMovement>();
					if ((Object)(object)componentInChildren == (Object)null)
					{
						Melon<QualityEffects>.Logger.Msg("[AntiGrav] ❌ PlayerMovement not found in children.");
						return;
					}
					float multiplier = QualityEffectsHelper.GetMultiplier(player.ConsumedProduct, "AntiGrav");
					componentInChildren.gravityMultiplier += multiplier;
					Melon<QualityEffects>.Logger.Msg($"[AntiGrav] ✅ Applied multiplier: {multiplier:F2}, New GravityMult: {componentInChildren.gravityMultiplier:F2}");
				}
				catch (Exception ex)
				{
					Melon<QualityEffects>.Logger.Msg("[AntiGrav] ❌ Exception in Postfix: " + ex.Message);
				}
			}
		}

		[HarmonyPatch(typeof(AntiGravity), "ClearFromPlayer")]
		public static class Patch_AntiGrav_ClearFromPlayer
		{
			public static void Postfix(AntiGravity __instance, Player player)
			{
				PlayerMovement componentInChildren = ((Component)player).GetComponentInChildren<PlayerMovement>();
				componentInChildren.gravityMultiplier = 1.4f;
			}
		}

		public static float AthleticDifference;

		public static float EnergizingDifference;

		public static float LastMultiplier { get; private set; }

		public static bool AthleticActive { get; private set; }

		public static bool EnergizingActive { get; private set; }
	}
	public static class QualityEffectsHelper
	{
		public static List<float> defaultMultipliers = new List<float> { 0.5f, 0.75f, 1f, 1.25f, 1.5f, 1f };

		public static Dictionary<string, List<float>> multipliers = new Dictionary<string, List<float>>
		{
			{ "ATHLETIC", defaultMultipliers },
			{ "Energizing", defaultMultipliers },
			{
				"AntiGrav",
				new List<float> { 0.2f, 0.1f, 0f, -0.3f, -0.6f, 0f }
			}
		};

		public static float GetMultiplier(object instance, string drugName)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0013: Expected O, but got Unknown
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009f: Expected O, but got Unknown
			//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0109: Unknown result type (might be due to invalid IL or missing references)
			//IL_0124: Expected I4, but got Unknown
			//IL_01aa: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				Object val = new Object(((Il2CppObjectBase)(Object)instance).Pointer);
				FieldInfo field = val.GetIl2CppType().GetField("Quality");
				if (field == (FieldInfo)null)
				{
					Melon<QualityEffects>.Logger.Msg("[" + drugName + "] ❌ No Quality field found.");
					return 1f;
				}
				Object value = field.GetValue(val);
				if (value == null)
				{
					Melon<QualityEffects>.Logger.Msg("[" + drugName + "] ⚠\ufe0f Quality field is null.");
					return 1f;
				}
				Object val2 = new Object(((Il2CppObjectBase)value).Pointer);
				Object val3 = Enum.ToObject(Il2CppType.Of<EQuality>(), val2);
				int num = Convert.ToInt32(val3);
				EQuality val4 = (EQuality)num;
				List<float> list = multipliers[drugName];
				if (list == null || list.Count < 6)
				{
					Melon<QualityEffects>.Logger.Msg("[" + drugName + "] ⚠\ufe0f Null or incomplete multiplier list.");
					return 1f;
				}
				if (1 == 0)
				{
				}
				float num2 = (int)val4 switch
				{
					0 => list[0], 
					1 => list[1], 
					2 => list[2], 
					3 => list[3], 
					4 => list[4], 
					_ => list[5], 
				};
				if (1 == 0)
				{
				}
				float num3 = num2;
				Melon<QualityEffects>.Logger.Msg($"[{drugName}] Quality: {val4} ({num}) → Multiplier: {num3}");
				return num3;
			}
			catch (Exception ex)
			{
				Melon<QualityEffects>.Logger.Msg("[" + drugName + "] ❌ Exception while reading Quality: " + ex.Message);
				return 1f;
			}
		}
	}
}