Decompiled source of Visible Hampered v1.1.0

plugins/VisibleHampered.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;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using SideLoader;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("OutwardModTemplate")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("OutwardModTemplate")]
[assembly: AssemblyCopyright("Copyright ©  2021")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("c5450fe0-edcf-483f-b9ea-4b1ef9d36da7")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.0.0")]
[module: UnverifiableCode]
namespace VisibleHampered;

[BepInPlugin("johbenji.visiblehampered", "Visible Hampered", "1.1.0")]
public class VisibleHamperedPlugin : BaseUnityPlugin
{
	[HarmonyPatch(typeof(StatusEffectManager), "AddStatusEffect")]
	[HarmonyPatch(new Type[]
	{
		typeof(StatusEffect),
		typeof(Character)
	})]
	public class StatusEffectManager_Hampered_Patch
	{
		private static void Postfix(StatusEffectManager __instance, StatusEffect _statusEffect, Character _dealer)
		{
			if ((Object)(object)__instance != (Object)null && (Object)(object)_statusEffect != (Object)null && _statusEffect.IdentifierName == Instance.statusEffectIdentifier)
			{
				string text = "Hampered Visuals";
				__instance.AddStatusEffect(text);
			}
		}
	}

	public const string GUID = "johbenji.visiblehampered";

	public const string NAME = "Visible Hampered";

	public const string VERSION = "1.1.0";

	public string statusEffectIdentifier = "Hampered";

	private float statusEffectDuration = 6f;

	internal static ManualLogSource Log;

	public static VisibleHamperedPlugin Instance { get; private set; }

	internal void Awake()
	{
		//IL_0018: Unknown result type (might be due to invalid IL or missing references)
		Instance = this;
		Log = ((BaseUnityPlugin)this).Logger;
		new Harmony("johbenji.visiblehampered").PatchAll();
		SL.OnPacksLoaded += FindStatusEffectIdentifier;
	}

	private void FindStatusEffectIdentifier()
	{
		//IL_0001: Unknown result type (might be due to invalid IL or missing references)
		//IL_0007: Expected O, but got Unknown
		GameObject val = new GameObject();
		Enchantment val2 = ResourcesPrefabManager.Instance.GenerateEnchantment(111, val.transform);
		if ((Object)(object)val2 != (Object)null)
		{
			Effect[] effects = val2.Effects;
			if (effects.Length != 0)
			{
				Effect[] array = effects;
				foreach (Effect val3 in array)
				{
					if (val3 is AddStatusEffectBuildUp && ((Object)val3).name.Contains("Hit"))
					{
						AddStatusEffectBuildUp val4 = (AddStatusEffectBuildUp)(object)((val3 is AddStatusEffectBuildUp) ? val3 : null);
						if ((Object)(object)val4 != (Object)null)
						{
							StatusEffect status = val4.Status;
							if ((Object)(object)status != (Object)null)
							{
								string identifierName = status.IdentifierName;
								if (identifierName != "")
								{
									Log.LogMessage((object)("Telekinesis enchantment contains effect with the name " + identifierName + "."));
									statusEffectIdentifier = identifierName;
									statusEffectDuration = status.StartLifespan;
									StatusEffect statusEffectPrefab = ResourcesPrefabManager.Instance.GetStatusEffectPrefab("Hampered Visuals");
									if ((Object)(object)statusEffectPrefab != (Object)null)
									{
										Log.LogMessage((object)"Found Hampered Visuals status effect prefab.");
										StatusData statusData = statusEffectPrefab.StatusData;
										if (statusData != null)
										{
											Log.LogMessage((object)"Setting Hampered Visuals status effect duration...");
											statusData.LifeSpan = statusEffectDuration;
											Log.LogMessage((object)$"Set Hampered Visuals status effect LifeSpan to {statusData.LifeSpan} seconds.");
										}
										else
										{
											Log.LogWarning((object)"Hampered Visuals status effect has no StatusData.");
										}
										Log.LogMessage((object)$"Set Hampered Visuals status effect duration to {statusEffectPrefab.RemainingLifespan} seconds.");
									}
									else
									{
										Log.LogWarning((object)"Could not find Hampered Visuals status effect prefab.");
									}
									break;
								}
								Log.LogWarning((object)"Status effect has no identifier name.");
							}
							else
							{
								Log.LogWarning((object)"Hit status effect is null.");
							}
						}
						else
						{
							Log.LogWarning((object)"Could not cast effect to AddStatusEffectBuildUp.");
						}
					}
					else
					{
						Log.LogMessage((object)("Effect " + ((Object)val3).name + " is not an AddStatusEffectBuildUp with Hit in the name."));
					}
				}
			}
			else
			{
				Log.LogWarning((object)"Telekinesis enchantment has no effects.");
			}
		}
		else
		{
			Log.LogWarning((object)"Could not find Telekinesis enchantment prefab.");
		}
		Object.Destroy((Object)(object)val);
	}
}