Decompiled source of ThrowableObjects v1.0.2

ThrowableObjects.dll

Decompiled a day ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using ExitGames.Client.Photon;
using HarmonyLib;
using KeybindLib.Classes;
using Microsoft.CodeAnalysis;
using Photon.Pun;
using Photon.Realtime;
using ThrowableObjects;
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: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("Sourca")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0+0f46cee60dfe0a8d5a920764d7260be1e8aac87b")]
[assembly: AssemblyProduct("ThrowableObjects")]
[assembly: AssemblyTitle("ThrowableObjects")]
[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.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;
		}
	}
}
[HarmonyPatch(typeof(PhysGrabber), "Update")]
internal static class GrabberPatch
{
	private static void Postfix(PhysGrabber __instance)
	{
		//IL_0063: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a5: Unknown result type (might be due to invalid IL or missing references)
		//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_0114: Unknown result type (might be due to invalid IL or missing references)
		//IL_011e: 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_0131: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0138: Unknown result type (might be due to invalid IL or missing references)
		//IL_0142: Expected O, but got Unknown
		//IL_00f4: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f6: Unknown result type (might be due to invalid IL or missing references)
		if (!__instance.isLocal || !__instance.grabbed || (Object)(object)__instance.grabbedPhysGrabObject == (Object)null || !global::ThrowableObjects.ThrowableObjects.Instance.IsGameReady() || !InputManager.instance.KeyDown(global::ThrowableObjects.ThrowableObjects.Instance.throwKey.inputKey))
		{
			return;
		}
		PhysGrabObject grabbedPhysGrabObject = __instance.grabbedPhysGrabObject;
		PhotonView component = ((Component)grabbedPhysGrabObject).GetComponent<PhotonView>();
		if (!((Object)(object)component == (Object)null))
		{
			Vector3 forward = ((Component)Camera.main).transform.forward;
			Vector3 right = ((Component)Camera.main).transform.right;
			int viewID = component.ViewID;
			__instance.ReleaseObject(-1, 1f);
			__instance.grabbed = false;
			__instance.grabbedPhysGrabObject = null;
			if (SemiFunc.IsMasterClientOrSingleplayer())
			{
				global::ThrowableObjects.ThrowableObjects.Instance.ApplyThrowObject(grabbedPhysGrabObject, forward, right);
				return;
			}
			object[] array = new object[3] { viewID, forward, right };
			PhotonNetwork.RaiseEvent((byte)123, (object)array, new RaiseEventOptions
			{
				Receivers = (ReceiverGroup)2
			}, SendOptions.SendReliable);
		}
	}
}
namespace ThrowableObjects
{
	[BepInPlugin("Sourca.ThrowableObjects", "Throwable Objects", "1.0.2")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class ThrowableObjects : BaseUnityPlugin, IOnEventCallback
	{
		public Keybind throwKey;

		public ConfigEntry<float> ThrowPower;

		public const byte ThrowEventCode = 123;

		private bool _callbacks;

		internal static ThrowableObjects Instance { get; private set; }

		internal static ManualLogSource Logger => Instance._logger;

		private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger;

		internal Harmony? Harmony { get; set; }

		private void Awake()
		{
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			Instance = this;
			((Component)this).gameObject.transform.parent = null;
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			Patch();
			Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!");
			throwKey = Keybinds.Bind("Throw Object", "<Keyboard>/f");
			ThrowPower = ((BaseUnityPlugin)this).Config.Bind<float>("General", "Throw Power", 15f, new ConfigDescription("The power of your thorw.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 100f), Array.Empty<object>()));
		}

		public static float GetThrowPower()
		{
			return Instance.ThrowPower.Value;
		}

		public bool IsGameReady()
		{
			if (!PhotonNetwork.IsConnected)
			{
				return false;
			}
			if (!PhotonNetwork.InRoom)
			{
				return false;
			}
			if (SemiFunc.MenuLevel())
			{
				return false;
			}
			if (!Object.op_Implicit((Object)(object)SemiFunc.PlayerAvatarLocal()))
			{
				return false;
			}
			return true;
		}

		private void Update()
		{
			if (IsGameReady())
			{
				if (!_callbacks)
				{
					PhotonNetwork.AddCallbackTarget((object)this);
					_callbacks = true;
				}
			}
			else if (_callbacks)
			{
				PhotonNetwork.RemoveCallbackTarget((object)this);
				_callbacks = false;
			}
		}

		private void OnDestroy()
		{
			if (_callbacks)
			{
				PhotonNetwork.RemoveCallbackTarget((object)this);
			}
		}

		internal void ApplyThrow(int viewID, Vector3 forward, Vector3 right)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0032: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			PhotonView val = PhotonView.Find(viewID);
			if (!((Object)(object)val == (Object)null))
			{
				Rigidbody component = ((Component)val).GetComponent<Rigidbody>();
				if (!((Object)(object)component == (Object)null))
				{
					component.AddForce(forward * GetThrowPower(), (ForceMode)1);
					component.AddTorque(right * GetThrowPower(), (ForceMode)1);
				}
			}
		}

		internal void ApplyThrowObject(PhysGrabObject Object, Vector3 forward, Vector3 right)
		{
			//IL_0017: Unknown result type (might be due to invalid IL or missing references)
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			//IL_002a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Unknown result type (might be due to invalid IL or missing references)
			Rigidbody rb = Object.rb;
			if (!((Object)(object)rb == (Object)null))
			{
				rb.AddForce(forward * GetThrowPower(), (ForceMode)1);
				rb.AddTorque(right * GetThrowPower(), (ForceMode)1);
			}
		}

		public void OnEvent(EventData photonEvent)
		{
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: 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)
			//IL_005f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			if (photonEvent.Code == 123 && SemiFunc.IsMasterClientOrSingleplayer() && IsGameReady())
			{
				object[] array = (object[])photonEvent.CustomData;
				int viewID = (int)array[0];
				Vector3 forward = (Vector3)array[1];
				Vector3 right = (Vector3)array[2];
				ApplyThrow(viewID, forward, right);
			}
		}

		internal void Patch()
		{
			//IL_001a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0026: Expected O, but got Unknown
			if (Harmony == null)
			{
				Harmony val = new Harmony(((BaseUnityPlugin)this).Info.Metadata.GUID);
				Harmony val2 = val;
				Harmony = val;
			}
			Harmony.PatchAll();
		}

		internal void Unpatch()
		{
			Harmony? harmony = Harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}
	}
}