Decompiled source of GrapplingHarpoonHook v0.0.1

plugins\GrapplingHarpoonHook.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using System.Security.Permissions;
using BepInEx;
using GrapplingHarpoonHook.Helpers;
using GrapplingHarpoonHook.Models;
using HarmonyLib;
using Jotunn;
using Jotunn.Entities;
using Jotunn.Managers;
using Jotunn.Utils;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("GrapplingHarpoonHook")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("GrapplingHarpoonHook")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("e3243d22-4307-4008-ba36-9f326008cde5")]
[assembly: AssemblyFileVersion("0.0.1")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.1.0")]
namespace GrapplingHarpoonHook
{
	[BepInPlugin("DeathWizsh.GrapplingHarpoonHook", "GrapplingHarpoonHook", "0.0.1")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	[NetworkCompatibility(/*Could not decode attribute arguments.*/)]
	internal class GrapplingHarpoonHook : BaseUnityPlugin
	{
		public const string PluginGUID = "DeathWizsh.GrapplingHarpoonHook";

		public const string PluginName = "GrapplingHarpoonHook";

		public const string PluginVersion = "0.0.1";

		public static GrapplingHarpoonHook Instance;

		private static readonly Harmony harmony = new Harmony("DeathWizsh.GrapplingHarpoonHook");

		private AssetBundle assetBundle;

		public CustomPrefabs prefabs = new CustomPrefabs();

		public CustomStatusEffects effects = new CustomStatusEffects();

		public static CustomLocalization Localization = LocalizationManager.Instance.GetLocalization();

		private void Awake()
		{
			Instance = this;
			InitAssetBundle();
			PrefabManager.OnVanillaPrefabsAvailable += AttackHelper.ConfigureGrapplingHookSecondaryAttack;
			harmony.PatchAll(Assembly.GetExecutingAssembly());
		}

		private void InitAssetBundle()
		{
			//IL_003c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0046: Expected O, but got Unknown
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Expected O, but got Unknown
			//IL_00a8: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b2: Expected O, but got Unknown
			assetBundle = AssetUtils.LoadAssetBundleFromResources("grapplingharpoonhook_dw");
			prefabs.HarpoonProjectile = assetBundle.LoadAsset<GameObject>("HarpoonHook_Projectile_GHH");
			PrefabManager.Instance.AddPrefab(new CustomPrefab(prefabs.HarpoonProjectile, true));
			prefabs.HarpoonVfx = assetBundle.LoadAsset<GameObject>("vfx_Harpooned_GHH");
			PrefabManager.Instance.AddPrefab(new CustomPrefab(prefabs.HarpoonVfx, true));
			effects.Harpoon = assetBundle.LoadAsset<StatusEffect>("Harpooned_GHH");
			ItemManager.Instance.AddStatusEffect(new CustomStatusEffect(effects.Harpoon, true));
		}
	}
}
namespace GrapplingHarpoonHook.Models
{
	internal class CustomPrefabs
	{
		public GameObject HarpoonProjectile;

		public GameObject HarpoonVfx;
	}
	internal class CustomStatusEffects
	{
		public StatusEffect Harpoon;
	}
}
namespace GrapplingHarpoonHook.Helpers
{
	internal static class AttackHelper
	{
		private const string CloneSuffix = "(Clone)";

		private static string _hookItemName;

		internal static void ConfigureGrapplingHookSecondaryAttack()
		{
			GameObject prefab = PrefabManager.Instance.GetPrefab("GrapplingHook");
			if (!Object.op_Implicit((Object)(object)prefab))
			{
				Logger.LogError((object)"AttackSetup: could not find GrapplingHook prefab.");
				return;
			}
			SharedData shared = prefab.GetComponent<ItemDrop>().m_itemData.m_shared;
			Attack secondaryAttack = shared.m_secondaryAttack;
			if (secondaryAttack == null)
			{
				Logger.LogError((object)"AttackSetup: GrapplingHook has no secondary attack to modify.");
				return;
			}
			secondaryAttack.m_attackProjectile = GrapplingHarpoonHook.Instance.prefabs.HarpoonProjectile;
			secondaryAttack.m_spawnOnHit = null;
			secondaryAttack.m_requiresReload = shared.m_attack.m_requiresReload;
			_hookItemName = shared.m_name;
		}

		internal static void RestoreHarpoonEffect(Projectile projectile, ItemData weapon)
		{
			if (IsGrapplingHookSecondaryShot(projectile, weapon))
			{
				projectile.m_statusEffectHash = StringExtensionMethods.GetStableHashCode(projectile.m_statusEffect = ((Object)GrapplingHarpoonHook.Instance.effects.Harpoon).name);
			}
		}

		private static bool IsGrapplingHookSecondaryShot(Projectile projectile, ItemData weapon)
		{
			if (!Object.op_Implicit((Object)(object)GrapplingHarpoonHook.Instance.prefabs.HarpoonProjectile) || !Object.op_Implicit((Object)(object)GrapplingHarpoonHook.Instance.effects.Harpoon))
			{
				return false;
			}
			if (weapon?.m_shared == null || weapon.m_shared.m_name != _hookItemName)
			{
				return false;
			}
			string text = ((Object)((Component)projectile).gameObject).name;
			if (text.EndsWith("(Clone)"))
			{
				text = text.Substring(0, text.Length - "(Clone)".Length);
			}
			return text == ((Object)GrapplingHarpoonHook.Instance.prefabs.HarpoonProjectile).name;
		}
	}
}
namespace GrapplingHarpoonHook.Harmony
{
	[HarmonyPatch]
	internal class ProjectilePatches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(Projectile), "Setup")]
		public static void Setup_Postfix(Projectile __instance, ItemData item)
		{
			try
			{
				AttackHelper.RestoreHarpoonEffect(__instance, item);
			}
			catch (Exception ex)
			{
				Logger.LogError((object)("Something went wrong in Setup_Postfix: " + ex));
			}
		}
	}
}