Decompiled source of DisfiguredEnemies v1.1.0

DisfiguredEnemies.dll

Decompiled 2 months 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.Logging;
using DisfiguredEnemies.Patches;
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: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[module: UnverifiableCode]
[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 DisfiguredEnemies
{
	[BepInPlugin("benjamin.disfiguredenemies", "DisfiguredEnemies", "1.1.0")]
	[BepInProcess("REPO.exe")]
	public class Plugin : BaseUnityPlugin
	{
		public const string Guid = "benjamin.disfiguredenemies";

		public const string Name = "DisfiguredEnemies";

		public const string Version = "1.1.0";

		internal static ManualLogSource Log;

		private Harmony _harmony;

		internal static ConfigEntry<bool> Enabled;

		internal static ConfigEntry<bool> ScaleDistortion;

		internal static ConfigEntry<float> MinStretch;

		internal static ConfigEntry<float> MaxStretch;

		internal static ConfigEntry<float> MinSquash;

		internal static ConfigEntry<float> MaxSquash;

		internal static ConfigEntry<bool> NonUniformScale;

		internal static ConfigEntry<bool> ColorTint;

		internal static ConfigEntry<Color> TintColor;

		internal static ConfigEntry<float> TintStrength;

		internal static ConfigEntry<bool> EyeGlow;

		internal static ConfigEntry<Color> GlowColor;

		internal static ConfigEntry<float> GlowIntensity;

		internal static ConfigEntry<float> GlowRange;

		internal static ConfigEntry<bool> Verbose;

		private void Awake()
		{
			//IL_0079: Unknown result type (might be due to invalid IL or missing references)
			//IL_0083: Expected O, but got Unknown
			//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Expected O, but got Unknown
			//IL_00f3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00fd: Expected O, but got Unknown
			//IL_0130: Unknown result type (might be due to invalid IL or missing references)
			//IL_013a: Expected O, but got Unknown
			//IL_019e: 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_01ea: Expected O, but got Unknown
			//IL_022e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0270: Unknown result type (might be due to invalid IL or missing references)
			//IL_027a: Expected O, but got Unknown
			//IL_02ad: Unknown result type (might be due to invalid IL or missing references)
			//IL_02b7: Expected O, but got Unknown
			//IL_02e2: Unknown result type (might be due to invalid IL or missing references)
			//IL_02ec: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Master switch.");
			ScaleDistortion = ((BaseUnityPlugin)this).Config.Bind<bool>("Scale", "ScaleDistortion", true, "Randomly resize each enemy per spawn.");
			MinStretch = ((BaseUnityPlugin)this).Config.Bind<float>("Scale", "MinStretch", 1f, new ConfigDescription("Minimum overall size multiplier.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 3f), Array.Empty<object>()));
			MaxStretch = ((BaseUnityPlugin)this).Config.Bind<float>("Scale", "MaxStretch", 1.35f, new ConfigDescription("Maximum overall size multiplier.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.5f, 3f), Array.Empty<object>()));
			MinSquash = ((BaseUnityPlugin)this).Config.Bind<float>("Scale", "MinSquash", 0.85f, new ConfigDescription("Minimum width/depth multiplier, ONLY used if NonUniformScale is on.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.3f, 2f), Array.Empty<object>()));
			MaxSquash = ((BaseUnityPlugin)this).Config.Bind<float>("Scale", "MaxSquash", 1.15f, new ConfigDescription("Maximum width/depth multiplier, ONLY used if NonUniformScale is on.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.3f, 2f), Array.Empty<object>()));
			NonUniformScale = ((BaseUnityPlugin)this).Config.Bind<bool>("Scale", "NonUniformScale", false, "EXPERIMENTAL - stretch height independently from width/depth for gaunt/squat proportions. Off by default: applying non-uniform scale to a parent whose child colliders are rotated relative to it can produce a shear Unity's physics engine can't invert, which surfaces as 'Infinity or NaN floating point numbers... Collider' errors in the log. Confirmed on Bomb Thrower, Head Grabber, Tumbler and Head in testing. Uniform scale (the default) resizes without this risk, at the cost of losing independent height/width variation.");
			ColorTint = ((BaseUnityPlugin)this).Config.Bind<bool>("Tint", "ColorTint", true, "Tint every renderer on the enemy toward TintColor. Uses a MaterialPropertyBlock per-renderer, so it never modifies the shared material asset other instances (or other mods) also use.");
			TintColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Tint", "TintColor", new Color(0.55f, 0.05f, 0.05f), "Colour tinted toward. Default is a sickly dark red.");
			TintStrength = ((BaseUnityPlugin)this).Config.Bind<float>("Tint", "TintStrength", 0.35f, new ConfigDescription("0 = no tint, 1 = fully replaced by TintColor.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>()));
			EyeGlow = ((BaseUnityPlugin)this).Config.Bind<bool>("EyeGlow", "EyeGlow", true, "Attach a small glowing point light near the top of each enemy - an approximation of glowing eyes without needing a custom model.");
			GlowColor = ((BaseUnityPlugin)this).Config.Bind<Color>("EyeGlow", "GlowColor", new Color(1f, 0.15f, 0.1f), "Glow colour.");
			GlowIntensity = ((BaseUnityPlugin)this).Config.Bind<float>("EyeGlow", "GlowIntensity", 1.4f, new ConfigDescription("Light intensity.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 8f), Array.Empty<object>()));
			GlowRange = ((BaseUnityPlugin)this).Config.Bind<float>("EyeGlow", "GlowRange", 1.2f, new ConfigDescription("Light range in metres - kept small so it reads as eyes, not a lamp.", (AcceptableValueBase)(object)new AcceptableValueRange<float>(0.2f, 5f), Array.Empty<object>()));
			Verbose = ((BaseUnityPlugin)this).Config.Bind<bool>("Debug", "Verbose", false, "Log every distortion applied, with the values rolled.");
			_harmony = new Harmony("benjamin.disfiguredenemies");
			_harmony.PatchAll(typeof(SpawnDistortPatch));
			Log.LogInfo((object)"DisfiguredEnemies v1.1.0 loaded.");
		}

		private void OnDestroy()
		{
			Harmony harmony = _harmony;
			if (harmony != null)
			{
				harmony.UnpatchSelf();
			}
		}

		internal static void Trace(string msg)
		{
			if (Verbose != null && Verbose.Value)
			{
				Log.LogInfo((object)msg);
			}
		}
	}
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "DisfiguredEnemies";

		public const string PLUGIN_NAME = "DisfiguredEnemies";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}
namespace DisfiguredEnemies.Patches
{
	[HarmonyPatch(typeof(EnemyParent))]
	internal static class SpawnDistortPatch
	{
		[HarmonyPostfix]
		[HarmonyPatch("Spawn")]
		private static void AfterSpawn(EnemyParent __instance)
		{
			if (!Plugin.Enabled.Value)
			{
				return;
			}
			Enemy enemy = __instance.Enemy;
			if (!((Object)(object)enemy == (Object)null))
			{
				int num = (((Object)(object)enemy.PhotonView != (Object)null) ? enemy.PhotonView.ViewID : ((Object)enemy).GetInstanceID());
				Random rng = new Random(num);
				Plugin.Trace($"[DisfiguredEnemies] Distorting '{__instance.enemyName}' (seed {num}).");
				if (Plugin.ScaleDistortion.Value)
				{
					ApplyScale(enemy, rng);
				}
				if (Plugin.ColorTint.Value)
				{
					ApplyTint(enemy);
				}
				if (Plugin.EyeGlow.Value)
				{
					ApplyGlow(enemy, rng);
				}
			}
		}

		private static void ApplyScale(Enemy enemy, Random rng)
		{
			//IL_0008: Unknown result type (might be due to invalid IL or missing references)
			//IL_000d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ac: Unknown result type (might be due to invalid IL or missing references)
			//IL_00af: Unknown result type (might be due to invalid IL or missing references)
			//IL_0051: Unknown result type (might be due to invalid IL or missing references)
			//IL_0059: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			Transform transform = ((Component)enemy).transform;
			Vector3 localScale = transform.localScale;
			if (Plugin.NonUniformScale.Value)
			{
				float num = Lerp(rng, Plugin.MinStretch.Value, Plugin.MaxStretch.Value);
				float num2 = Lerp(rng, Plugin.MinSquash.Value, Plugin.MaxSquash.Value);
				transform.localScale = new Vector3(localScale.x * num2, localScale.y * num, localScale.z * num2);
				Plugin.Trace($"[DisfiguredEnemies]   scale (non-uniform, experimental): height x{num:F2}, width x{num2:F2}");
			}
			else
			{
				float num3 = Lerp(rng, Plugin.MinStretch.Value, Plugin.MaxStretch.Value);
				transform.localScale = localScale * num3;
				Plugin.Trace($"[DisfiguredEnemies]   scale (uniform): x{num3:F2}");
			}
		}

		private static void ApplyTint(Enemy enemy)
		{
			//IL_0005: Unknown result type (might be due to invalid IL or missing references)
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_001e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0024: Expected O, but got Unknown
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: 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_0047: Unknown result type (might be due to invalid IL or missing references)
			//IL_005a: Unknown result type (might be due to invalid IL or missing references)
			//IL_005c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0053: Unknown result type (might be due to invalid IL or missing references)
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_0068: 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_007d: Unknown result type (might be due to invalid IL or missing references)
			Color value = Plugin.TintColor.Value;
			float value2 = Plugin.TintStrength.Value;
			Renderer[] componentsInChildren = ((Component)enemy).GetComponentsInChildren<Renderer>(true);
			MaterialPropertyBlock val = new MaterialPropertyBlock();
			Renderer[] array = componentsInChildren;
			foreach (Renderer obj in array)
			{
				obj.GetPropertyBlock(val);
				Vector4 vector = val.GetVector("_Color");
				Color val2 = Color.Lerp((vector != Vector4.zero) ? Color.op_Implicit(vector) : Color.white, value, value2);
				val.SetColor("_Color", val2);
				val.SetColor("_BaseColor", val2);
				obj.SetPropertyBlock(val);
			}
			Plugin.Trace($"[DisfiguredEnemies]   tinted {componentsInChildren.Length} renderer(s)");
		}

		private static void ApplyGlow(Enemy enemy, Random rng)
		{
			//IL_0010: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Unknown result type (might be due to invalid IL or missing references)
			//IL_0043: Unknown result type (might be due to invalid IL or missing references)
			//IL_0049: Expected O, but got Unknown
			//IL_0063: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Unknown result type (might be due to invalid IL or missing references)
			//IL_007b: Unknown result type (might be due to invalid IL or missing references)
			//IL_008e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0098: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b5: 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)
			Renderer[] componentsInChildren = ((Component)enemy).GetComponentsInChildren<Renderer>(true);
			if (componentsInChildren.Length != 0)
			{
				Bounds bounds = componentsInChildren[0].bounds;
				Renderer[] array = componentsInChildren;
				foreach (Renderer val in array)
				{
					((Bounds)(ref bounds)).Encapsulate(val.bounds);
				}
				GameObject val2 = new GameObject("DisfiguredEnemies_EyeGlow");
				val2.transform.SetParent(((Component)enemy).transform, false);
				val2.transform.position = new Vector3(((Bounds)(ref bounds)).center.x, ((Bounds)(ref bounds)).max.y - ((Bounds)(ref bounds)).size.y * 0.12f, ((Bounds)(ref bounds)).center.z);
				Light obj = val2.AddComponent<Light>();
				obj.type = (LightType)2;
				obj.color = Plugin.GlowColor.Value;
				obj.intensity = Plugin.GlowIntensity.Value;
				obj.range = Plugin.GlowRange.Value;
				obj.shadows = (LightShadows)0;
				rng.NextDouble();
				Plugin.Trace($"[DisfiguredEnemies]   eye glow placed at {val2.transform.position}");
			}
		}

		private static float Lerp(Random rng, float min, float max)
		{
			return min + (float)rng.NextDouble() * (max - min);
		}
	}
}