Decompiled source of Throwable v1.0.2

Throwable.dll

Decompiled a week 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.Core.Logging.Interpolation;
using BepInEx.Logging;
using BepInEx.Unity.IL2CPP;
using Bossa.Core.Entity;
using Entities.Weapons;
using HarmonyLib;
using Il2CppInterop.Runtime.Injection;
using Il2CppInterop.Runtime.InteropTypes;
using Il2CppInterop.Runtime.InteropTypes.Arrays;
using Il2CppSystem;
using Microsoft.CodeAnalysis;
using UISystem;
using UnityEngine;
using Utilities.Weapons;
using WildSkies;
using WildSkies.Entities.Health;
using WildSkies.Gameplay.Items;
using WildSkies.Service;
using WildSkies.Service.Interface;
using WildSkies.Weapon;
using Wildskies.UI.Hud;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETCoreApp,Version=v6.0", FrameworkDisplayName = ".NET 6.0")]
[assembly: AssemblyCompany("Throwable")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyCopyright("Nines (Natives)")]
[assembly: AssemblyFileVersion("1.0.2.0")]
[assembly: AssemblyInformationalVersion("1.0.2")]
[assembly: AssemblyProduct("Throwable")]
[assembly: AssemblyTitle("Throwable")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.2.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 ItemThrowable
{
	[BepInPlugin("Throwable", "Throwable", "1.0.2")]
	public class Plugin : BasePlugin
	{
		private class ThrowableSimpleChatCommands
		{
			public static string Duration(int value)
			{
				if (value < 0)
				{
					Throwable_Duration.Value = (int)((ConfigEntryBase)Throwable_Duration).DefaultValue;
				}
				else
				{
					Throwable_Duration.Value = value;
				}
				return "Throwable duration " + ((value > 0) ? $"now set to {value} second{((Math.Abs(value) == 1) ? "" : "s")}" : "disabled") + ".";
			}
		}

		private class ItemThrowable : Throwable
		{
			public ColliderLookupService _colliderLookupService { get; set; }

			public float Damage { get; set; }

			public int UpgradeLevel { get; set; }

			public ItemThrowable(IntPtr pointer)
				: base(pointer)
			{
				((Throwable)this)._destructionFx = (VfxType)22;
			}

			public ItemThrowable()
				: base(ClassInjector.DerivedConstructorPointer<ItemThrowable>())
			{
				ClassInjector.DerivedConstructorBody((Il2CppObjectBase)(object)this);
			}

			public override void Update()
			{
				//IL_0038: Unknown result type (might be due to invalid IL or missing references)
				//IL_0090: Unknown result type (might be due to invalid IL or missing references)
				//IL_0096: Unknown result type (might be due to invalid IL or missing references)
				//IL_009b: Unknown result type (might be due to invalid IL or missing references)
				//IL_00be: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
				//IL_00c5: Unknown result type (might be due to invalid IL or missing references)
				//IL_00cc: Unknown result type (might be due to invalid IL or missing references)
				//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
				Throwable_Update(this);
				if (((Throwable)this).Charged || !((Throwable)this).Thrown)
				{
					return;
				}
				if (Damage > 0f)
				{
					IUIService val = SceneContextInstaller.ResolveObject<IUIService>();
					IDamageable val2 = default(IDamageable);
					foreach (Collider item in (Il2CppArrayBase<Collider>)(object)Physics.OverlapSphere(((Component)this).transform.position, 0.75f, ~LayerMask.GetMask(new string[1] { "Interactable" })))
					{
						if (_colliderLookupService.TryGet<IDamageable>(item, ref val2))
						{
							DamageResponse val3 = val2.Damage(Damage, (DamageType)2, (DamageSrcObjectType)5, UpgradeLevel, 0, ((Component)item).transform.position, 1);
							if (val.HUDManager.IsHudElementShowing((UIHudType)37))
							{
								((Il2CppObjectBase)val.HUDManager.GetHudElement((UIHudType)37)).Cast<DamageNumbersHud>().AddDamageNumber(val3.WorldPoint, val3.ActualDamageDone, val3.HitType, false);
							}
						}
					}
				}
				((Throwable)this).DestroyThrowable();
			}
		}

		internal static ManualLogSource Log;

		internal static Harmony harmonyInstance;

		private static ConfigEntry<int> Throwable_Duration;

		public override void Load()
		{
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_001b: Expected O, but got Unknown
			Log = ((BasePlugin)this).Log;
			ManualLogSource log = Log;
			bool flag = default(bool);
			BepInExInfoLogInterpolatedStringHandler val = new BepInExInfoLogInterpolatedStringHandler(18, 1, ref flag);
			if (flag)
			{
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral("Plugin ");
				((BepInExLogInterpolatedStringHandler)val).AppendFormatted<string>("Throwable");
				((BepInExLogInterpolatedStringHandler)val).AppendLiteral(" is loaded!");
			}
			log.LogInfo(val);
			Throwable_Duration = ((BasePlugin)this).Config.Bind<int>("Throwable", "Duration", 300, "Throwable.Duration");
			ClassInjector.RegisterTypeInIl2Cpp<ItemThrowable>();
			harmonyInstance = Harmony.CreateAndPatchAll(typeof(Plugin), (string)null);
		}

		public override bool Unload()
		{
			Harmony obj = harmonyInstance;
			if (obj != null)
			{
				obj.UnpatchSelf();
			}
			return true;
		}

		[HarmonyPatch(typeof(ItemService), "OnLoadAddressable")]
		[HarmonyPrefix]
		public static void ItemInventoryComponent_OnLoadAddressable(ItemService __instance, ItemDefinition itemDefinition)
		{
			//IL_0001: 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_0035: Unknown result type (might be due to invalid IL or missing references)
			//IL_004d: Unknown result type (might be due to invalid IL or missing references)
			//IL_0086: Unknown result type (might be due to invalid IL or missing references)
			//IL_0090: Unknown result type (might be due to invalid IL or missing references)
			if (!((Enum)itemDefinition.ItemTypeFlags).HasFlag((Enum)(object)(ItemTypes)8192) && ((Enum)itemDefinition.ItemTypeFlags).HasFlag((Enum)(object)(ItemTypes)1) && ((Enum)itemDefinition.ItemTypeFlags).HasFlag((Enum)(object)(ItemTypes)2) && !((Enum)itemDefinition.ItemTypeFlags).HasFlag((Enum)(object)(ItemTypes)16))
			{
				if ((Object)(object)itemDefinition.GetComponent<ItemThrowableComponent>() == (Object)null)
				{
					itemDefinition.ItemCompositionList.Add((BaseItemComponent)(object)ScriptableObject.CreateInstance<ItemThrowableComponent>());
				}
				itemDefinition.ItemTypeFlags = (ItemTypes)(itemDefinition.ItemTypeFlags | 0x2000);
			}
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[HarmonyPatch(typeof(WeaponBase), "FiringHeldStop")]
		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		private static void WeaponBase_FiringHeldStop(GenericUtilityItem instance)
		{
		}

		[HarmonyPatch(typeof(GenericUtilityItem), "FiringHeldStop")]
		[HarmonyPrefix]
		public static bool GenericUtilityItem_FiringHeldStop(GenericUtilityItem __instance)
		{
			//IL_001d: Unknown result type (might be due to invalid IL or missing references)
			if (((WeaponBase)__instance).IsAiming || !((Enum)__instance._item.ParentItem.Item.ItemDefinition.ItemTypeFlags).HasFlag((Enum)(object)(ItemTypes)8))
			{
				return true;
			}
			if (!(__instance._cooldownTimer < __instance._cooldownDelay))
			{
				WeaponBase_FiringHeldStop(__instance);
			}
			return false;
		}

		[HarmonyPatch(typeof(GenericUtilityItem), "ThrowThrowable")]
		[HarmonyPrefix]
		public static bool GenericUtilityItem_ThrowThrowable(GenericUtilityItem __instance, Vector3 position, Vector3 forward)
		{
			//IL_004a: 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_005b: Unknown result type (might be due to invalid IL or missing references)
			//IL_006b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0070: Unknown result type (might be due to invalid IL or missing references)
			//IL_0075: 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_008a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0096: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ab: Unknown result type (might be due to invalid IL or missing references)
			//IL_00cb: Unknown result type (might be due to invalid IL or missing references)
			//IL_00d2: 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)
			//IL_00f0: Unknown result type (might be due to invalid IL or missing references)
			//IL_00f7: Unknown result type (might be due to invalid IL or missing references)
			//IL_0117: Unknown result type (might be due to invalid IL or missing references)
			//IL_0137: Unknown result type (might be due to invalid IL or missing references)
			//IL_015c: Expected O, but got Unknown
			if ((Object)(object)__instance._throwableComponent.ThowablePrefab != (Object)null)
			{
				return true;
			}
			Nullable<ColorDataInfo> customColor;
			try
			{
				customColor = __instance._item.ParentItem.itemColor;
			}
			catch
			{
				customColor = new Nullable<ColorDataInfo>();
			}
			Vector3 force = forward * __instance._forwardForce + Vector3.up * __instance._upwardForce;
			__instance._lootDropService.TrySpawnItem(new SpawnItemStruct
			{
				Position = ((Component)__instance).transform.position,
				Rotation = Quaternion.identity,
				ItemId = __instance._item.ParentItem.Item.UniqueID,
				Amount = 1,
				ItemSpawned = Action<GameObject, LootableInteraction>.op_Implicit((Action<GameObject, LootableInteraction>)delegate(GameObject gameObject, LootableInteraction loot)
				{
					//IL_00e0: Unknown result type (might be due to invalid IL or missing references)
					//IL_00c8: Unknown result type (might be due to invalid IL or missing references)
					//IL_00ce: Unknown result type (might be due to invalid IL or missing references)
					if (Throwable_Duration.Value > 0)
					{
						ItemThrowable itemThrowable = gameObject.AddComponent<ItemThrowable>();
						itemThrowable._colliderLookupService = ((WeaponBase)__instance)._colliderLookupService;
						itemThrowable.Damage = 20f;
						itemThrowable.UpgradeLevel = SceneContextInstaller.ResolveObject<IPlayerInventoryService>().GetCurrentMaxWeaponLevel();
						((Throwable)itemThrowable)._powerDecreaseSpeed = 1f / (float)Throwable_Duration.Value * Mathf.Log(10f);
						((Throwable)itemThrowable)._rigidbody = loot._rigidBody;
						((Throwable)itemThrowable)._throwableInteraction = ((Component)loot).gameObject.AddComponent<ThrowableInteraction>();
						((Behaviour)((Throwable)itemThrowable)._throwableInteraction).enabled = false;
						((Entity)itemThrowable)._coherenceSync = ((NetworkInteractable)loot)._sync;
						((Throwable)itemThrowable)._collider = (Collider)(object)loot._baseCollider;
						((Entity)itemThrowable)._health = gameObject.AddComponent<EntityHealth>();
						((Throwable)itemThrowable).Throw(loot._itemDefinition, ((Component)__instance).transform.GetChild(0).localScale, force, 0f);
					}
					else
					{
						loot.AddForce(force);
					}
				}),
				IsPlayerDriven = true,
				CustomColor = customColor,
				CreatorName = __instance._item.ParentItem.Item.CreatorName,
				ItemLevel = __instance._item.ParentItem.Item.ItemLevel,
				VariationSeed = __instance._item.ParentItem.Item.VariationSeed
			});
			return false;
		}

		[MethodImpl(MethodImplOptions.NoInlining)]
		[HarmonyPatch(typeof(Throwable), "Update")]
		[HarmonyReversePatch(/*Could not decode attribute arguments.*/)]
		private static void Throwable_Update(ItemThrowable instance)
		{
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "Throwable";

		public const string PLUGIN_NAME = "Throwable";

		public const string PLUGIN_VERSION = "1.0.2";
	}
}