Decompiled source of TamedHarpoon v1.0.0

TamedHarpoon.dll

Decompiled 13 hours ago
using System;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using BepInEx;
using BepInEx.Configuration;
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: AssemblyCompany("TamedHarpoon")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("TamedHarpoon")]
[assembly: AssemblyTitle("TamedHarpoon")]
[assembly: AssemblyVersion("1.0.0.0")]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[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 TamedHarpoon
{
	[BepInPlugin("com.Azura.tamedharpoon", "TamedHarpoon", "1.0.0")]
	public class Plugin : BaseUnityPlugin
	{
		public const string PluginGUID = "com.Azura.tamedharpoon";

		public const string PluginName = "TamedHarpoon";

		public const string PluginVersion = "1.0.0";

		public static ConfigEntry<bool> Actif;

		public static ConfigEntry<bool> SansDegats;

		private static int hashHarpon;

		private void Awake()
		{
			//IL_0045: Unknown result type (might be due to invalid IL or missing references)
			Actif = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "true = the harpoon also catches tamed animals.\ntrue = le harpon accroche aussi les animaux apprivoisés.");
			SansDegats = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "NoDamage", true, "true = the harpoon does no damage to tamed animals (it only pulls them).\ntrue = le harpon ne blesse pas les animaux apprivoisés (il ne fait que les tirer).");
			new Harmony("com.Azura.tamedharpoon").PatchAll();
			((BaseUnityPlugin)this).Logger.LogInfo((object)Texte("TamedHarpoon v1.0.0 loaded.", "TamedHarpoon v1.0.0 chargé."));
		}

		internal static string Texte(string anglais, string francais)
		{
			if (Localization.instance == null || !(Localization.instance.GetSelectedLanguage() == "French"))
			{
				return anglais;
			}
			return francais;
		}

		public static bool EstHarpon(int hashEffet)
		{
			if (hashEffet == 0 || (Object)(object)ObjectDB.instance == (Object)null)
			{
				return false;
			}
			if (hashHarpon != 0)
			{
				return hashEffet == hashHarpon;
			}
			if (ObjectDB.instance.GetStatusEffect(hashEffet) is SE_Harpooned)
			{
				hashHarpon = hashEffet;
				return true;
			}
			return false;
		}

		public static bool ApprivoiseHarponne(Projectile p, Character proprio, int hashEffet, Character cible)
		{
			if (Actif.Value && (Object)(object)cible != (Object)null && !cible.IsPlayer() && cible.IsTamed() && (Object)(object)proprio != (Object)null && proprio.IsPlayer())
			{
				return EstHarpon(hashEffet);
			}
			return false;
		}
	}
	[HarmonyPatch(typeof(Projectile), "IsValidTarget")]
	public static class Projectile_IsValidTarget_Patch
	{
		public static void Postfix(Projectile __instance, IDestructible destr, ref bool __result, Character ___m_owner, int ___m_statusEffectHash)
		{
			if (!__result && Plugin.ApprivoiseHarponne(__instance, ___m_owner, ___m_statusEffectHash, (Character)(object)((destr is Character) ? destr : null)))
			{
				__result = true;
			}
		}
	}
	[HarmonyPatch(typeof(Projectile), "OnHit")]
	public static class Projectile_OnHit_Patch
	{
		public struct Sauvegarde
		{
			public bool Change;

			public DamageTypes Degats;

			public float Force;
		}

		public static void Prefix(Projectile __instance, Collider collider, Character ___m_owner, int ___m_statusEffectHash, ref Sauvegarde __state)
		{
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_005e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			__state = default(Sauvegarde);
			if (Plugin.SansDegats.Value && !((Object)(object)collider == (Object)null))
			{
				GameObject val = Projectile.FindHitObject(collider);
				Character cible = (((Object)(object)val != (Object)null) ? val.GetComponent<Character>() : null);
				if (Plugin.ApprivoiseHarponne(__instance, ___m_owner, ___m_statusEffectHash, cible))
				{
					__state = new Sauvegarde
					{
						Change = true,
						Degats = __instance.m_damage,
						Force = __instance.m_attackForce
					};
					__instance.m_damage = default(DamageTypes);
					__instance.m_attackForce = 0f;
				}
			}
		}

		public static void Finalizer(Projectile __instance, Sauvegarde __state)
		{
			//IL_0014: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Unknown result type (might be due to invalid IL or missing references)
			if (__state.Change && !((Object)(object)__instance == (Object)null))
			{
				__instance.m_damage = __state.Degats;
				__instance.m_attackForce = __state.Force;
			}
		}
	}
}