Decompiled source of ColorBubble v1.0.3

ColorBubble.dll

Decompiled 3 months ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
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.Configuration;
using HarmonyLib;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: AssemblyTitle("ColorBubble")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ColorBubble")]
[assembly: AssemblyCopyright("Copyright ©  2024")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("cc3703b3-081f-495a-8c37-88808386fd15")]
[assembly: AssemblyFileVersion("1.0.3")]
[assembly: TargetFramework(".NETFramework,Version=v4.8", FrameworkDisplayName = ".NET Framework 4.8")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
namespace ColorBubble;

[BepInPlugin("org.ssmvc.colorbubble", "ColorBubble", "1.0.3")]
[BepInProcess("valheim.exe")]
public class ColorBubble : BaseUnityPlugin
{
	[HarmonyPatch(typeof(SE_Shield))]
	private static class ShieldPatch
	{
		[HarmonyPatch("OnDamaged")]
		[HarmonyPrefix]
		public static void OnDamagedPrefix(SE_Shield __instance, HitData hit, Character attacker)
		{
			//IL_002c: Unknown result type (might be due to invalid IL or missing references)
			if (Enabled.Value && ShowBubbleHits.Value && hit.GetTotalDamage() > 0f)
			{
				DamageText.instance.ShowText((DamageModifier)0, hit.m_point, hit.GetTotalDamage(), false);
			}
		}

		[HarmonyPatch("Setup")]
		[HarmonyPostfix]
		public static void SetupPostfix(SE_Shield __instance, Character character)
		{
			if (!Enabled.Value || !EnableBubbleColor.Value || (BubbleColorSelfOnly.Value && character != Player.m_localPlayer))
			{
				return;
			}
			GameObject[] startEffectInstances = ((StatusEffect)__instance).m_startEffectInstances;
			foreach (GameObject val in startEffectInstances)
			{
				if (((Object)val).name.StartsWith("vfx_StaffShield"))
				{
					RecolorBubble(val);
				}
			}
		}

		public static void LoadTexture(string path, ref Material material)
		{
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000f: Expected O, but got Unknown
			byte[] array = File.ReadAllBytes(path);
			Texture2D val = new Texture2D(1, 1);
			ImageConversion.LoadImage(val, array);
			material.mainTexture = (Texture)(object)val;
		}
	}

	[HarmonyPatch(typeof(StatusEffect), "GetIconText")]
	private static class StatusEffectPatch
	{
		public static void Postfix(StatusEffect __instance, ref string __result)
		{
			if (!Enabled.Value)
			{
				return;
			}
			SE_Shield val = (SE_Shield)(object)((__instance is SE_Shield) ? __instance : null);
			if (val != null)
			{
				if (ShowBubblePercent.Value && ShowBubbleHitPoints.Value)
				{
					__result += "\r\n";
				}
				if (ShowBubblePercent.Value)
				{
					__result += $" ({100f - val.m_damage / val.m_totalAbsorbDamage * 100f:##}%)";
				}
				if (ShowBubbleHitPoints.Value)
				{
					__result += $" ({val.m_totalAbsorbDamage - val.m_damage:####})";
				}
			}
		}
	}

	public const string PluginGUID = "org.ssmvc.colorbubble";

	public const string PluginName = "ColorBubble";

	public const string PluginVersion = "1.0.3";

	private static Harmony _harmony;

	private static Texture _defaultTexture;

	public static ConfigEntry<bool> Enabled { get; set; }

	public static ConfigEntry<bool> EnableBubbleColor { get; set; }

	public static ConfigEntry<Color> BubbleColor { get; set; }

	public static ConfigEntry<bool> BubbleColorSelfOnly { get; set; }

	public static ConfigEntry<bool> ShowBubblePercent { get; set; }

	public static ConfigEntry<bool> ShowBubbleHitPoints { get; set; }

	public static ConfigEntry<bool> ShowBubbleHits { get; set; }

	public static ConfigEntry<float> ShaderVelocity { get; set; }

	public static ConfigEntry<float> ShaderRefraction { get; set; }

	public static ConfigEntry<float> ShaderGlossiness { get; set; }

	public static ConfigEntry<float> ShaderMetallic { get; set; }

	public static ConfigEntry<bool> ShaderTexture { get; set; }

	public void Awake()
	{
		//IL_0078: Unknown result type (might be due to invalid IL or missing references)
		_harmony = Harmony.CreateAndPatchAll(Assembly.GetExecutingAssembly(), "org.ssmvc.colorbubble");
		Enabled = ((BaseUnityPlugin)this).Config.Bind<bool>("_Global", "isModEnabled", true, "Globally enable or disable this mod.");
		EnableBubbleColor = ((BaseUnityPlugin)this).Config.Bind<bool>("Color", "Enable Bubble Color", true, "Enable or disable the bubble color");
		BubbleColor = ((BaseUnityPlugin)this).Config.Bind<Color>("Color", "Bubble Color", new Color(1f, 0f, 0f, 0.5f), (ConfigDescription)null);
		ShowBubblePercent = ((BaseUnityPlugin)this).Config.Bind<bool>("Misc", "Show Bubble Percent", true, "Show remaining bubble integrity");
		ShowBubbleHitPoints = ((BaseUnityPlugin)this).Config.Bind<bool>("Misc", "Show Bubble HitPoints", false, "Show remaining bubble hit points");
		ShowBubbleHits = ((BaseUnityPlugin)this).Config.Bind<bool>("Misc", "Show Bubble Hits", true, "Show bubble damage taken");
		BubbleColorSelfOnly = ((BaseUnityPlugin)this).Config.Bind<bool>("Misc", "Self Only", false, "Do not apply bubble colors to other player/creature bubbles");
		ShaderVelocity = ((BaseUnityPlugin)this).Config.Bind<float>("Shader", "ShaderVelocity", 5f, "Wavy Speed");
		ShaderRefraction = ((BaseUnityPlugin)this).Config.Bind<float>("Shader", "ShaderRefraction", 0.1f, "Bubble Distortion");
		ShaderGlossiness = ((BaseUnityPlugin)this).Config.Bind<float>("Shader", "ShaderGlossiness", 0.8f, "Bubble Glossiness");
		ShaderMetallic = ((BaseUnityPlugin)this).Config.Bind<float>("Shader", "ShaderMetallic", 1f, "Bubble Metallic");
		ShaderTexture = ((BaseUnityPlugin)this).Config.Bind<bool>("Shader", "DisableTexture", false, "Makes bubble more smoother");
		((BaseUnityPlugin)this).Config.SettingChanged += UpdateBubble;
	}

	private void UpdateBubble(object sender, SettingChangedEventArgs e)
	{
		if (Enabled.Value && EnableBubbleColor.Value)
		{
			Transform val = ((Component)Player.m_localPlayer).transform.Find("vfx_StaffShield(Clone)");
			if (Object.op_Implicit((Object)(object)val))
			{
				RecolorBubble(((Component)val).gameObject);
			}
		}
	}

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

	private static void RecolorBubble(GameObject effect)
	{
		//IL_0041: Unknown result type (might be due to invalid IL or missing references)
		//IL_005f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0069: Expected O, but got Unknown
		MeshRenderer componentInChildren = effect.GetComponentInChildren<MeshRenderer>();
		if (!((Object)(object)componentInChildren == (Object)null))
		{
			((Renderer)componentInChildren).material.mainTexture = _defaultTexture ?? (_defaultTexture = ((Renderer)componentInChildren).material.mainTexture);
			((Renderer)componentInChildren).material.color = BubbleColor.Value;
			if (ShaderTexture.Value)
			{
				((Renderer)componentInChildren).material.mainTexture = (Texture)new Texture2D(1, 1);
			}
			((Renderer)componentInChildren).material.SetFloat("_WaveVel", ShaderVelocity.Value);
			((Renderer)componentInChildren).material.SetFloat("_RefractionIntensity", ShaderRefraction.Value);
			((Renderer)componentInChildren).material.SetFloat("_Glossiness", ShaderGlossiness.Value);
			((Renderer)componentInChildren).material.SetFloat("_Metallic", ShaderMetallic.Value);
		}
	}

	public static List<Vector3> GetCirclePoints3D(int n, float radius)
	{
		//IL_0032: Unknown result type (might be due to invalid IL or missing references)
		List<Vector3> list = new List<Vector3>();
		for (int i = 0; i < n; i++)
		{
			float num = (float)Math.PI * 2f * (float)i / (float)n;
			float num2 = radius * Mathf.Cos(num);
			float num3 = radius * Mathf.Sin(num);
			list.Add(new Vector3(num2, 0f, num3));
		}
		return list;
	}

	public static Color[] GenerateRainbowColors(int n)
	{
		//IL_0026: Unknown result type (might be due to invalid IL or missing references)
		//IL_002b: Unknown result type (might be due to invalid IL or missing references)
		Color[] array = (Color[])(object)new Color[n];
		float num = 1f / (float)n;
		for (int i = 0; i < n; i++)
		{
			float num2 = (float)i * num;
			array[i] = Color.HSVToRGB(num2, 1f, 1f);
		}
		return array;
	}
}
public class RotateColor : MonoBehaviour
{
	public float Alpha = 0.5f;

	public static Color GetRainbowColor(float time, float duration, float alpha)
	{
		//IL_000f: Unknown result type (might be due to invalid IL or missing references)
		//IL_0014: 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)
		Color result = Color.HSVToRGB(time % duration / duration, 1f, 1f);
		result.a = alpha;
		return result;
	}

	public void Update()
	{
		//IL_001b: Unknown result type (might be due to invalid IL or missing references)
		((Renderer)((Component)this).GetComponentInChildren<MeshRenderer>()).material.color = GetRainbowColor(Time.time, 1f, Alpha);
	}
}