Decompiled source of LyseZmniejszanieItemow v1.5.2

Lyse_Shrinker.dll

Decompiled a day ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("Lyse_Shrinker")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("Lyse_Shrinker")]
[assembly: AssemblyTitle("Lyse_Shrinker")]
[assembly: AssemblyVersion("1.0.0.0")]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
namespace LyseZmniejszanieItemow
{
	[BepInPlugin("com.qubi.lysezmniejszanie", "LyseZmniejszanieItemow", "16.0.0")]
	public class LyseZmniejszaniePlugin : BaseUnityPlugin
	{
		public static ConfigEntry<bool> EnTiny;

		public static ConfigEntry<bool> EnSmall;

		public static ConfigEntry<bool> EnMedium;

		public static ConfigEntry<bool> EnLarge;

		public static ConfigEntry<float> ScTiny;

		public static ConfigEntry<float> ScSmall;

		public static ConfigEntry<float> ScMedium;

		public static ConfigEntry<float> ScLarge;

		public static ConfigEntry<bool> InfEnergy;

		public static List<PhysGrabInCart> Carts = new List<PhysGrabInCart>();

		private float scanTimer = 0f;

		private void Awake()
		{
			//IL_0136: Unknown result type (might be due to invalid IL or missing references)
			EnTiny = ((BaseUnityPlugin)this).Config.Bind<bool>("1_Toggles", "Shrink_Tiny", true, "Waga 0-2kg");
			EnSmall = ((BaseUnityPlugin)this).Config.Bind<bool>("1_Toggles", "Shrink_Small", true, "Waga 2-5kg");
			EnMedium = ((BaseUnityPlugin)this).Config.Bind<bool>("1_Toggles", "Shrink_Medium", true, "Waga 5-15kg");
			EnLarge = ((BaseUnityPlugin)this).Config.Bind<bool>("1_Toggles", "Shrink_Large", true, "Waga > 15kg");
			ScTiny = ((BaseUnityPlugin)this).Config.Bind<float>("2_Scales", "Factor_Tiny", 0.5f, "Skala 0-2kg");
			ScSmall = ((BaseUnityPlugin)this).Config.Bind<float>("2_Scales", "Factor_Small", 0.4f, "Skala 2-5kg");
			ScMedium = ((BaseUnityPlugin)this).Config.Bind<float>("2_Scales", "Factor_Medium", 0.3f, "Skala 5-15kg");
			ScLarge = ((BaseUnityPlugin)this).Config.Bind<float>("2_Scales", "Factor_Large", 0.2f, "Skala > 15kg");
			InfEnergy = ((BaseUnityPlugin)this).Config.Bind<bool>("3_Misc", "InfiniteEnergy", true, "Ladowanie");
			new Harmony("com.qubi.lysezmniejszanie").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)"LyseZmniejszanie v16.0.0 (Arsenal & Physics Fix) zaladowane!");
		}

		private void Update()
		{
			scanTimer -= Time.deltaTime;
			if (scanTimer <= 0f)
			{
				Carts.Clear();
				PhysGrabInCart[] array = Object.FindObjectsOfType<PhysGrabInCart>();
				if (array != null)
				{
					Carts.AddRange(array);
				}
				scanTimer = 2f;
			}
		}
	}
	public class ScaleAnimator : MonoBehaviour
	{
		private Vector3 originalScale;

		private Vector3 targetScale;

		private PhysGrabObject pgo;

		private Rigidbody rb;

		private float mass = 1f;

		private bool hasBeenShrunk = false;

		private float rechargeTimer = 0f;

		private void Start()
		{
			//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)
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_007e: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0071: Unknown result type (might be due to invalid IL or missing references)
			pgo = ((Component)this).GetComponent<PhysGrabObject>();
			rb = ((Component)this).GetComponent<Rigidbody>();
			originalScale = ((Component)this).transform.localScale;
			if (originalScale.x <= 0.05f || originalScale.y <= 0.05f || originalScale.z <= 0.05f)
			{
				originalScale = Vector3.one;
			}
			targetScale = originalScale;
			if ((Object)(object)rb != (Object)null)
			{
				mass = rb.mass;
			}
		}

		private float GetFactor()
		{
			if (mass <= 2.1f)
			{
				return LyseZmniejszaniePlugin.EnTiny.Value ? LyseZmniejszaniePlugin.ScTiny.Value : 1f;
			}
			if (mass <= 5.1f)
			{
				return LyseZmniejszaniePlugin.EnSmall.Value ? LyseZmniejszaniePlugin.ScSmall.Value : 1f;
			}
			if (mass <= 15.1f)
			{
				return LyseZmniejszaniePlugin.EnMedium.Value ? LyseZmniejszaniePlugin.ScMedium.Value : 1f;
			}
			return LyseZmniejszaniePlugin.EnLarge.Value ? LyseZmniejszaniePlugin.ScLarge.Value : 1f;
		}

		private void Update()
		{
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00df: 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_0127: Unknown result type (might be due to invalid IL or missing references)
			//IL_012c: Unknown result type (might be due to invalid IL or missing references)
			//IL_012e: Unknown result type (might be due to invalid IL or missing references)
			//IL_013f: 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_0160: Unknown result type (might be due to invalid IL or missing references)
			//IL_0170: Unknown result type (might be due to invalid IL or missing references)
			//IL_017e: Unknown result type (might be due to invalid IL or missing references)
			//IL_028c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0291: Unknown result type (might be due to invalid IL or missing references)
			//IL_0271: Unknown result type (might be due to invalid IL or missing references)
			//IL_027c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0281: Unknown result type (might be due to invalid IL or missing references)
			//IL_023e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0244: Invalid comparison between Unknown and I4
			//IL_029d: Unknown result type (might be due to invalid IL or missing references)
			//IL_02a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_02c7: Unknown result type (might be due to invalid IL or missing references)
			//IL_02cd: Unknown result type (might be due to invalid IL or missing references)
			//IL_02dd: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)pgo == (Object)null || (((Component)this).transform.localScale.x <= 0.01f && ((Component)this).transform.localScale.y <= 0.01f))
			{
				return;
			}
			bool flag = false;
			bool flag2 = false;
			bool flag3 = false;
			try
			{
				flag3 = Traverse.Create((object)pgo).Field("physGrabCart").GetValue() != null;
			}
			catch
			{
			}
			float num = ((mass > 15f) ? 0.3f : 0f);
			foreach (PhysGrabInCart cart in LyseZmniejszaniePlugin.Carts)
			{
				if ((Object)(object)cart == (Object)null)
				{
					continue;
				}
				float num2 = Vector3.Distance(((Component)this).transform.position, ((Component)cart).transform.position);
				if (!(num2 > 4.5f))
				{
					if (num2 <= 3f)
					{
						flag2 = true;
					}
					Vector3 val = ((Component)cart).transform.InverseTransformPoint(((Component)this).transform.position);
					if (val.x >= 0f - (1f + num) && val.x <= 1f + num && val.z >= 0f - (1.2f + num) && val.z <= 0.4f + num && val.y >= -1f && val.y <= 8f)
					{
						flag = true;
					}
				}
			}
			if (flag2 && LyseZmniejszaniePlugin.InfEnergy.Value)
			{
				rechargeTimer += Time.deltaTime;
				if (rechargeTimer >= 0.7f)
				{
					rechargeTimer = 0f;
					DoRecharge();
				}
			}
			if (!hasBeenShrunk && (flag3 || flag))
			{
				hasBeenShrunk = true;
				if ((Object)(object)rb != (Object)null && (int)rb.collisionDetectionMode != 1)
				{
					rb.collisionDetectionMode = (CollisionDetectionMode)1;
				}
			}
			if (hasBeenShrunk)
			{
				targetScale = originalScale * GetFactor();
			}
			else
			{
				targetScale = originalScale;
			}
			if (Vector3.Distance(((Component)this).transform.localScale, targetScale) > 0.005f)
			{
				((Component)this).transform.localScale = Vector3.Lerp(((Component)this).transform.localScale, targetScale, Time.deltaTime * 8f);
			}
		}

		private void DoRecharge()
		{
			try
			{
				Component[] componentsInChildren = ((Component)this).GetComponentsInChildren<Component>(true);
				foreach (Component val in componentsInChildren)
				{
					if ((Object)(object)val == (Object)null)
					{
						continue;
					}
					Traverse val2 = Traverse.Create((object)val);
					Traverse val3 = val2.Field("numberOfBullets");
					if (val3.FieldExists())
					{
						val3.SetValue((object)30);
						Traverse val4 = val2.Field("hasOutOfAmmo");
						if (val4.FieldExists())
						{
							val4.SetValue((object)false);
						}
					}
					Traverse val5 = val2.Field("batteryLife");
					if (val5.FieldExists())
					{
						val5.SetValue((object)1f);
						val2.Method("SetBatteryLife", new object[1] { 100 }).GetValue();
					}
					object value = val2.Field("itemBattery").GetValue();
					if (value != null)
					{
						Traverse val6 = Traverse.Create(value);
						val6.Field("batteryLife").SetValue((object)1f);
						val6.Method("SetBatteryLife", new object[1] { 100 }).GetValue();
					}
				}
			}
			catch
			{
			}
		}
	}
	[HarmonyPatch(typeof(PhysGrabObject), "Start")]
	public class PhysGrabObject_Patch
	{
		private static void Postfix(PhysGrabObject __instance)
		{
			if (!((Object)(object)__instance == (Object)null))
			{
				string text = ((Object)__instance).name.ToLower();
				if (!text.Contains("cart") && !text.Contains("door") && !text.Contains("gate") && !text.Contains("wall") && !text.Contains("ship") && !text.Contains("player") && (Object)(object)((Component)__instance).gameObject.GetComponent<ScaleAnimator>() == (Object)null)
				{
					((Component)__instance).gameObject.AddComponent<ScaleAnimator>();
				}
			}
		}
	}
}