Decompiled source of ItemClippingFix v1.1.4

ItemClippingFix.dll

Decompiled 8 months ago
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Bootstrap;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("ItemClippingFix")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyDescription("Fixes ground/storage clipping & rotation on almost all items")]
[assembly: AssemblyFileVersion("1.1.4.0")]
[assembly: AssemblyInformationalVersion("1.1.4")]
[assembly: AssemblyProduct("ItemClippingFix")]
[assembly: AssemblyTitle("ItemClippingFix")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.4.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.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;
		}
	}
	[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 ItemClippingFix
{
	[BepInPlugin("viviko.ItemClippingFix", "ItemClippingFix", "1.1.4")]
	public class ItemClippingFix : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(PlaceableObjectsSurface))]
		public class PlaceableObjectsSurfacePatch
		{
			[HarmonyPrefix]
			[HarmonyPatch("itemPlacementPosition")]
			public static bool itemPlacementPositionPatch(ref PlaceableObjectsSurface __instance, ref Vector3 __result, ref Transform gameplayCamera, ref GrabbableObject heldObject)
			{
				//IL_0002: Unknown result type (might be due to invalid IL or missing references)
				//IL_0009: Unknown result type (might be due to invalid IL or missing references)
				//IL_008d: Unknown result type (might be due to invalid IL or missing references)
				//IL_0092: Unknown result type (might be due to invalid IL or missing references)
				//IL_002e: Unknown result type (might be due to invalid IL or missing references)
				//IL_0033: Unknown result type (might be due to invalid IL or missing references)
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_006a: Unknown result type (might be due to invalid IL or missing references)
				//IL_006f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0074: Unknown result type (might be due to invalid IL or missing references)
				//IL_0076: Unknown result type (might be due to invalid IL or missing references)
				//IL_0080: Unknown result type (might be due to invalid IL or missing references)
				//IL_0085: Unknown result type (might be due to invalid IL or missing references)
				//IL_0047: Unknown result type (might be due to invalid IL or missing references)
				//IL_0055: Unknown result type (might be due to invalid IL or missing references)
				//IL_005a: Unknown result type (might be due to invalid IL or missing references)
				RaycastHit val = default(RaycastHit);
				if (Physics.Raycast(gameplayCamera.position, gameplayCamera.forward, ref val, 7f, StartOfRound.Instance.collidersAndRoomMask, (QueryTriggerInteraction)1))
				{
					Bounds bounds = __instance.placeableBounds.bounds;
					if (((Bounds)(ref bounds)).Contains(((RaycastHit)(ref val)).point))
					{
						__result = FixPlacement(((RaycastHit)(ref val)).point, ((Component)__instance).transform, heldObject);
						return false;
					}
					Vector3 hitPoint = __instance.placeableBounds.ClosestPoint(((RaycastHit)(ref val)).point);
					__result = FixPlacement(hitPoint, ((Component)__instance).transform, heldObject);
					return false;
				}
				__result = Vector3.zero;
				return false;
			}
		}

		[HarmonyPatch(typeof(StartOfRound))]
		public class StartOfRoundPatch
		{
			[HarmonyPostfix]
			[HarmonyPatch("Awake")]
			public static void AwakePatch(ref StartOfRound __instance)
			{
				foreach (Item items in __instance.allItemsList.itemsList)
				{
					if (ItemFixes.TryGetValue($"{items.itemName}[{items.itemId}]", out List<float> value))
					{
						items.verticalOffset = value[0];
						if (value.Count > 1)
						{
							((Vector3)(ref items.restingRotation)).Set(value[1], value[2], value[3]);
						}
					}
				}
			}
		}

		private const string modGUID = "viviko.ItemClippingFix";

		private const string modName = "ItemClippingFix";

		private const string modVersion = "1.1.4";

		private readonly Harmony harmony = new Harmony("viviko.ItemClippingFix");

		private static ItemClippingFix Instance;

		public static ManualLogSource mls;

		private static readonly Dictionary<string, List<float>> ItemFixes = new Dictionary<string, List<float>>
		{
			{
				"Flashlight[6]",
				new List<float>(4) { 0.02f, 270f, 0f, 90f }
			},
			{
				"Jetpack[13]",
				new List<float>(4) { 0.25f, 45f, 0f, 0f }
			},
			{
				"Key[14]",
				new List<float>(4) { 0.07f, 180f, 0f, 90f }
			},
			{
				"Apparatus[3]",
				new List<float>(4) { 0.25f, 0f, 0f, 135f }
			},
			{
				"Pro-flashlight[1]",
				new List<float>(4) { 0.03f, 0f, 0f, 90f }
			},
			{
				"Shovel[7]",
				new List<float>(4) { 0f, 0f, -90f, -90f }
			},
			{
				"Stun grenade[12]",
				new List<float>(4) { 0.03f, 0f, 0f, 90f }
			},
			{
				"Extension ladder[17]",
				new List<float>(4) { -0.01f, 0f, 0f, 0f }
			},
			{
				"TZP-Inhalant[15]",
				new List<float>(4) { 0.05f, 0f, 0f, -90f }
			},
			{
				"Walkie-talkie[7]",
				new List<float>(1) { 0.05f }
			},
			{
				"Zap gun[5]",
				new List<float>(4) { 0.06f, 95f, 0f, 90f }
			},
			{
				"Magic 7 ball[0]",
				new List<float>(4) { 0.1f, 0f, 0f, 0f }
			},
			{
				"Airhorn[0]",
				new List<float>(4) { 0.05f, 0f, 90f, 270f }
			},
			{
				"Big bolt[0]",
				new List<float>(4) { 0.15f, -21f, 0f, 0f }
			},
			{
				"Bottles[0]",
				new List<float>(4) { 0.25f, -90f, 0f, 0f }
			},
			{
				"Brush[0]",
				new List<float>(4) { 0.01f, 90f, 0f, 0f }
			},
			{
				"Candy[0]",
				new List<float>(4) { -0.01f, 90f, 0f, 0f }
			},
			{
				"Chemical jug[0]",
				new List<float>(4) { 0.3f, -90f, 0f, 0f }
			},
			{
				"Clown horn[0]",
				new List<float>(4) { 0.07f, -90f, 0f, 0f }
			},
			{
				"Large axle[0]",
				new List<float>(4) { 0.55f, 7f, 0f, 0f }
			},
			{
				"Teeth[0]",
				new List<float>(4) { 0.03f, -90f, 0f, 0f }
			},
			{
				"V-type engine[0]",
				new List<float>(4) { 0.3f, -90f, 0f, 0f }
			},
			{
				"Plastic fish[0]",
				new List<float>(4) { 0.08f, -45f, 0f, 90f }
			},
			{
				"Laser pointer[1]",
				new List<float>(4) { 0f, 0f, 0f, 0f }
			},
			{
				"Gold bar[0]",
				new List<float>(4) { 0.05f, -90f, 0f, -90f }
			},
			{
				"Magnifying glass[0]",
				new List<float>(4) { 0.01f, 0f, 90f, -90f }
			},
			{
				"Metal sheet[0]",
				new List<float>(1) { 0.024f }
			},
			{
				"Cookie mold pan[0]",
				new List<float>(4) { -0.01f, -90f, 0f, 90f }
			},
			{
				"Mug[0]",
				new List<float>(4) { 0.05f, -90f, 0f, 0f }
			},
			{
				"Perfume bottle[0]",
				new List<float>(4) { 0.05f, -90f, 0f, 0f }
			},
			{
				"Old phone[0]",
				new List<float>(4) { 0.04f, -90f, 0f, -90f }
			},
			{
				"Jar of pickles[0]",
				new List<float>(4) { 0.25f, -90f, 0f, 0f }
			},
			{
				"Pill bottle[0]",
				new List<float>(4) { 0.01f, -90f, 0f, 0f }
			},
			{
				"Ring[0]",
				new List<float>(4) { -0.01f, 0f, -90f, 90f }
			},
			{
				"Toy robot[0]",
				new List<float>(4) { 0.4f, -90f, 0f, 0f }
			},
			{
				"Rubber Ducky[0]",
				new List<float>(4) { 0.05f, -90f, 0f, -90f }
			},
			{
				"Steering wheel[0]",
				new List<float>(4) { 0f, -90f, 0f, 0f }
			},
			{
				"Toothpaste[0]",
				new List<float>(4) { 0f, -90f, 0f, 0f }
			},
			{
				"Hive[1531]",
				new List<float>(4) { 0.3f, 7f, 0f, 0f }
			},
			{
				"Radar-booster[16]",
				new List<float>(4) { -0.02f, 0f, 0f, 0f }
			},
			{
				"Shotgun[17]",
				new List<float>(4) { 0.08f, 180f, 0f, -5f }
			},
			{
				"Ammo[17]",
				new List<float>(4) { 0f, 0f, 0f, 90f }
			},
			{
				"Spray paint[18]",
				new List<float>(4) { 0.03f, 0f, 0f, 195f }
			},
			{
				"Homemade flashbang[0]",
				new List<float>(4) { 0.05f, 0f, 0f, 90f }
			},
			{
				"Gift[152767]",
				new List<float>(4) { 0.4f, -90f, 0f, 0f }
			},
			{
				"Flask[0]",
				new List<float>(4) { 0.19f, 25f, 0f, 0f }
			},
			{
				"Tragedy[0]",
				new List<float>(4) { 0.05f, -90f, 0f, 0f }
			},
			{
				"Comedy[0]",
				new List<float>(4) { 0.05f, -90f, 0f, 0f }
			},
			{
				"Whoopie cushion[0]",
				new List<float>(4) { -0.01f, -90f, 0f, 0f }
			}
		};

		private void Awake()
		{
			if ((Object)(object)Instance == (Object)null)
			{
				Instance = this;
			}
			mls = Logger.CreateLogSource("ItemClippingFix");
			mls.LogInfo((object)"Checking for LobbyControl");
			if (Chainloader.PluginInfos.Values.ToList().Exists((PluginInfo x) => x.Metadata.GUID.Contains("mattymatty.LobbyControl")))
			{
				mls.LogInfo((object)"LobbyControl found! Disabling patches for compatibility");
				return;
			}
			harmony.PatchAll();
			mls.LogInfo((object)"Plugin ItemClippingFix is loaded!");
		}

		public static Vector3 FixPlacement(Vector3 hitPoint, Transform transform, GrabbableObject heldObject)
		{
			//IL_0003: Unknown result type (might be due to invalid IL or missing references)
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_003a: Unknown result type (might be due to invalid IL or missing references)
			hitPoint.y = transform.position.y + transform.localScale.z / 2f;
			return hitPoint + Vector3.up * heldObject.itemProperties.verticalOffset;
		}
	}
	internal static class GeneratedPluginInfo
	{
		public const string Identifier = "viviko.ItemClippingFix";

		public const string Name = "ItemClippingFix";

		public const string Version = "1.1.4";
	}
}
namespace System.Diagnostics.CodeAnalysis
{
	[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class ExperimentalAttribute : Attribute
	{
		public string DiagnosticId { get; }

		public string? UrlFormat { get; set; }

		public ExperimentalAttribute(string diagnosticId)
		{
			DiagnosticId = diagnosticId;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	internal sealed class MemberNotNullAttribute : Attribute
	{
		public string[] Members { get; }

		public MemberNotNullAttribute(string member)
		{
			Members = new string[1] { member };
		}

		public MemberNotNullAttribute(params string[] members)
		{
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property, Inherited = false, AllowMultiple = true)]
	[ExcludeFromCodeCoverage]
	internal sealed class MemberNotNullWhenAttribute : Attribute
	{
		public bool ReturnValue { get; }

		public string[] Members { get; }

		public MemberNotNullWhenAttribute(bool returnValue, string member)
		{
			ReturnValue = returnValue;
			Members = new string[1] { member };
		}

		public MemberNotNullWhenAttribute(bool returnValue, params string[] members)
		{
			ReturnValue = returnValue;
			Members = members;
		}
	}
	[AttributeUsage(AttributeTargets.Constructor, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class SetsRequiredMembersAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class StringSyntaxAttribute : Attribute
	{
		public const string CompositeFormat = "CompositeFormat";

		public const string DateOnlyFormat = "DateOnlyFormat";

		public const string DateTimeFormat = "DateTimeFormat";

		public const string EnumFormat = "EnumFormat";

		public const string GuidFormat = "GuidFormat";

		public const string Json = "Json";

		public const string NumericFormat = "NumericFormat";

		public const string Regex = "Regex";

		public const string TimeOnlyFormat = "TimeOnlyFormat";

		public const string TimeSpanFormat = "TimeSpanFormat";

		public const string Uri = "Uri";

		public const string Xml = "Xml";

		public string Syntax { get; }

		public object?[] Arguments { get; }

		public StringSyntaxAttribute(string syntax)
		{
			Syntax = syntax;
			Arguments = new object[0];
		}

		public StringSyntaxAttribute(string syntax, params object?[] arguments)
		{
			Syntax = syntax;
			Arguments = arguments;
		}
	}
	[AttributeUsage(AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class UnscopedRefAttribute : Attribute
	{
	}
}
namespace System.Runtime.Versioning
{
	[AttributeUsage(AttributeTargets.Assembly | AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Enum | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Interface | AttributeTargets.Delegate, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class RequiresPreviewFeaturesAttribute : Attribute
	{
		public string? Message { get; }

		public string? Url { get; set; }

		public RequiresPreviewFeaturesAttribute()
		{
		}

		public RequiresPreviewFeaturesAttribute(string? message)
		{
			Message = message;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
	[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class CallerArgumentExpressionAttribute : Attribute
	{
		public string ParameterName { get; }

		public CallerArgumentExpressionAttribute(string parameterName)
		{
			ParameterName = parameterName;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Interface, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class CollectionBuilderAttribute : Attribute
	{
		public Type BuilderType { get; }

		public string MethodName { get; }

		public CollectionBuilderAttribute(Type builderType, string methodName)
		{
			BuilderType = builderType;
			MethodName = methodName;
		}
	}
	[AttributeUsage(AttributeTargets.All, AllowMultiple = true, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class CompilerFeatureRequiredAttribute : Attribute
	{
		public const string RefStructs = "RefStructs";

		public const string RequiredMembers = "RequiredMembers";

		public string FeatureName { get; }

		public bool IsOptional { get; set; }

		public CompilerFeatureRequiredAttribute(string featureName)
		{
			FeatureName = featureName;
		}
	}
	[AttributeUsage(AttributeTargets.Parameter, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class InterpolatedStringHandlerArgumentAttribute : Attribute
	{
		public string[] Arguments { get; }

		public InterpolatedStringHandlerArgumentAttribute(string argument)
		{
			Arguments = new string[1] { argument };
		}

		public InterpolatedStringHandlerArgumentAttribute(params string[] arguments)
		{
			Arguments = arguments;
		}
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class InterpolatedStringHandlerAttribute : Attribute
	{
	}
	[EditorBrowsable(EditorBrowsableState.Never)]
	[ExcludeFromCodeCoverage]
	internal static class IsExternalInit
	{
	}
	[AttributeUsage(AttributeTargets.Method, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class ModuleInitializerAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Property | AttributeTargets.Field, AllowMultiple = false, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class RequiredMemberAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Parameter, Inherited = false)]
	[EditorBrowsable(EditorBrowsableState.Never)]
	[ExcludeFromCodeCoverage]
	internal sealed class RequiresLocationAttribute : Attribute
	{
	}
	[AttributeUsage(AttributeTargets.Module | AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Constructor | AttributeTargets.Method | AttributeTargets.Property | AttributeTargets.Event | AttributeTargets.Interface, Inherited = false)]
	[ExcludeFromCodeCoverage]
	internal sealed class SkipLocalsInitAttribute : Attribute
	{
	}
}