Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of ThrowableItems v1.0.0
ThrowableItems.dll
Decompiled a day agousing System; using System.Collections.Generic; 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 Microsoft.CodeAnalysis; using Photon.Pun; using REPOLib.Modules; 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("McHorse")] [assembly: AssemblyConfiguration("Debug")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+e8dc9ad15ba7f48521568df5331d8d4a311e6e97")] [assembly: AssemblyProduct("ThrowableItems")] [assembly: AssemblyTitle("ThrowableItems")] [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; } } } namespace ThrowableItems { [HarmonyPatch(typeof(PhysGrabber), "StartGrabbingPhysObject")] internal static class PhysGrabberStartGrabbingPhysObjectPatch { [HarmonyPrefix] private static bool Prefix(PhysGrabber __instance, PhysGrabObject _physGrabObject) { ThrowableItemsRuntime throwableItemsRuntime = ThrowableItems.Instance?.Runtime; if (throwableItemsRuntime == null || (Object)(object)_physGrabObject == (Object)null) { return true; } return throwableItemsRuntime.CanStartGrabbingLocal(__instance, _physGrabObject); } } [HarmonyPatch(typeof(PhysGrabObject), "Throw")] internal static class PhysGrabObjectThrowPatch { [HarmonyPrefix] private static bool Prefix(PhysGrabObject __instance, PhysGrabber player) { //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0057: Unknown result type (might be due to invalid IL or missing references) //IL_00c3: Unknown result type (might be due to invalid IL or missing references) //IL_00d1: Unknown result type (might be due to invalid IL or missing references) //IL_00e3: Unknown result type (might be due to invalid IL or missing references) //IL_00e9: Unknown result type (might be due to invalid IL or missing references) ThrowableItemsRuntime throwableItemsRuntime = ThrowableItems.Instance?.Runtime; if (throwableItemsRuntime == null || !throwableItemsRuntime.TryConsumePendingThrow(__instance, out (Vector3, float) throwData)) { return true; } Vector3 val = (((Object)(object)Camera.main != (Object)null) ? ((Component)Camera.main).transform.right : Vector3.right); float mass = __instance.rb.mass; float num = Mathf.Clamp01((mass - 1f) / 8f); float num2 = Mathf.Max(0f, player.throwStrength); float num3 = Mathf.Max(0f, player.grabStrength - 1f) * 0.25f; float num4 = num2 + num3; float num5 = 1f + num4 * num; __instance.rb.AddForce(throwData.Item1 * (throwData.Item2 * num5), (ForceMode)1); __instance.rb.AddTorque(val * 5f, (ForceMode)1); return false; } } [BepInPlugin("McHorse.ThrowableItems", "ThrowableItems", "1.0")] [BepInDependency(/*Could not decode attribute arguments.*/)] public class ThrowableItems : BaseUnityPlugin { internal static ThrowableItems Instance { get; private set; } internal static ManualLogSource Logger => Instance._logger; private ManualLogSource _logger => ((BaseUnityPlugin)this).Logger; internal Harmony? Harmony { get; set; } internal static ConfigEntry<KeyCode> ThrowKey { get; private set; } internal static ConfigEntry<float> ThrowForce { get; private set; } internal static ConfigEntry<bool> HostForce { get; private set; } internal static NetworkedEvent? ThrowEvent { get; private set; } internal ThrowableItemsRuntime Runtime { get; private set; } = null; private void Awake() { //IL_0078: Unknown result type (might be due to invalid IL or missing references) //IL_0082: Expected O, but got Unknown //IL_00d2: Unknown result type (might be due to invalid IL or missing references) //IL_00dc: Expected O, but got Unknown Instance = this; ((Component)this).gameObject.transform.parent = null; ((Object)((Component)this).gameObject).hideFlags = (HideFlags)61; ThrowKey = ((BaseUnityPlugin)this).Config.Bind<KeyCode>("General", "ThrowKey", (KeyCode)118, "Key to press to throw a held object."); ThrowForce = ((BaseUnityPlugin)this).Config.Bind<float>("General", "ThrowForce", 18f, new ConfigDescription("Force with which objects will be thrown.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 200f), Array.Empty<object>())); HostForce = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "HostDeterminesForce", true, "If enabled, the host's ThrowForce value is used for all players."); Runtime = new ThrowableItemsRuntime(); Patch(); ThrowEvent = new NetworkedEvent("ThrowableItems Throw", (Action<EventData>)Runtime.OnThrowEvent); Logger.LogInfo((object)$"{((BaseUnityPlugin)this).Info.Metadata.GUID} v{((BaseUnityPlugin)this).Info.Metadata.Version} has loaded!"); } 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(); } } private void Update() { Runtime.Tick(); } } internal class ThrowableItemsRuntime { private const float RegrabDelaySeconds = 1f; private const float DirectionEpsilon = 0.0001f; private readonly Dictionary<PhysGrabObject, (Vector3 direction, float force)> _pendingThrows = new Dictionary<PhysGrabObject, (Vector3, float)>(); private readonly Dictionary<PhysGrabObject, float> _localRegrabBlockUntil = new Dictionary<PhysGrabObject, float>(); private Vector3 _lastCameraForward = Vector3.forward; private bool _hasLastCameraForward; public void Tick() { //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_0032: 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_0037: 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) //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) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_005b: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0104: Unknown result type (might be due to invalid IL or missing references) //IL_0105: Unknown result type (might be due to invalid IL or missing references) //IL_010a: Unknown result type (might be due to invalid IL or missing references) //IL_012a: Unknown result type (might be due to invalid IL or missing references) //IL_012b: Unknown result type (might be due to invalid IL or missing references) //IL_012d: 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_014f: Unknown result type (might be due to invalid IL or missing references) //IL_0150: Unknown result type (might be due to invalid IL or missing references) //IL_0154: Unknown result type (might be due to invalid IL or missing references) //IL_0159: Unknown result type (might be due to invalid IL or missing references) //IL_015d: Unknown result type (might be due to invalid IL or missing references) //IL_0162: Unknown result type (might be due to invalid IL or missing references) //IL_0191: Unknown result type (might be due to invalid IL or missing references) //IL_01e0: Unknown result type (might be due to invalid IL or missing references) //IL_01ef: Unknown result type (might be due to invalid IL or missing references) //IL_01fe: Unknown result type (might be due to invalid IL or missing references) //IL_021a: Unknown result type (might be due to invalid IL or missing references) Camera main = Camera.main; if ((Object)(object)main == (Object)null) { return; } Vector3 forward = ((Component)main).transform.forward; Vector3 val = (_hasLastCameraForward ? _lastCameraForward : forward); _lastCameraForward = Vector3.Slerp(_lastCameraForward, forward, 0.2f); _hasLastCameraForward = true; if (!Input.GetKeyDown(ThrowableItems.ThrowKey.Value)) { return; } PhysGrabber instance = PhysGrabber.instance; if ((Object)(object)instance == (Object)null || !instance.isLocal || !instance.grabbed) { return; } PhysGrabObject grabbedPhysGrabObject = instance.grabbedPhysGrabObject; if ((Object)(object)grabbedPhysGrabObject == (Object)null || (grabbedPhysGrabObject.hasHinge && (Object)(object)grabbedPhysGrabObject.hinge != (Object)null && !grabbedPhysGrabObject.hinge.dead && !grabbedPhysGrabObject.hinge.broken)) { return; } Vector3 val2 = forward - val; if (((Vector3)(ref val2)).sqrMagnitude > 0.0001f) { ((Vector3)(ref val2)).Normalize(); } else { val2 = forward; } float num = Mathf.Clamp01(Vector3.Dot(forward, val)); float num2 = 1f - Mathf.Pow(num, 3f); Vector3 val3 = Vector3.Slerp(forward, val2, num2); Vector3 normalized = ((Vector3)(ref val3)).normalized; float value = ThrowableItems.ThrowForce.Value; _localRegrabBlockUntil[grabbedPhysGrabObject] = Time.time + 1f; _pendingThrows[grabbedPhysGrabObject] = (normalized, value); if (SemiFunc.IsMultiplayer() && !PhotonNetwork.IsMasterClient) { NetworkedEvent? throwEvent = ThrowableItems.ThrowEvent; if (throwEvent != null) { throwEvent.RaiseEvent((object)new object[5] { grabbedPhysGrabObject.photonView.ViewID, normalized.x, normalized.y, normalized.z, value }, NetworkingEvents.RaiseMasterClient, SendOptions.SendReliable); } } instance.ReleaseObject(-1, 0.1f); } public void OnThrowEvent(EventData eventData) { //IL_00c2: Unknown result type (might be due to invalid IL or missing references) if (!SemiFunc.IsMasterClientOrSingleplayer() || !(eventData.CustomData is object[] array) || array.Length < 5) { return; } int num = (int)array[0]; Vector3 item = default(Vector3); ((Vector3)(ref item))..ctor((float)array[1], (float)array[2], (float)array[3]); float item2 = (float)array[4]; PhotonView val = PhotonView.Find(num); if ((Object)(object)val == (Object)null) { return; } PhysGrabObject component = ((Component)val).GetComponent<PhysGrabObject>(); if (!((Object)(object)component == (Object)null)) { if (ThrowableItems.HostForce.Value) { item2 = ThrowableItems.ThrowForce.Value; } _pendingThrows[component] = (item, item2); } } public bool CanStartGrabbingLocal(PhysGrabber grabber, PhysGrabObject grabObject) { if (!grabber.isLocal) { return true; } if (!_localRegrabBlockUntil.TryGetValue(grabObject, out var value)) { return true; } if (Time.time >= value) { _localRegrabBlockUntil.Remove(grabObject); return true; } return false; } public bool TryConsumePendingThrow(PhysGrabObject grabObject, out (Vector3 direction, float force) throwData) { if (!_pendingThrows.TryGetValue(grabObject, out throwData)) { return false; } _pendingThrows.Remove(grabObject); return true; } } }