Decompiled source of OrbColors v1.0.3

OrbColors.dll

Decompiled 11 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using BepInEx.Logging;
using CodeTalker.Networking;
using CodeTalker.Packets;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using Mirror;
using Nessie.ATLYSS.EasySettings;
using Newtonsoft.Json;
using UnityEngine;
using UnityEngine.Events;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("OrbColors")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.3.0")]
[assembly: AssemblyInformationalVersion("1.0.3+925f75773211fd117ca435c9835e1dedb93426ab")]
[assembly: AssemblyProduct("OrbColors")]
[assembly: AssemblyTitle("OrbColors")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.3.0")]
[module: UnverifiableCode]
[module: RefSafetyRules(11)]
namespace Microsoft.CodeAnalysis
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	internal sealed class EmbeddedAttribute : Attribute
	{
	}
}
namespace System.Runtime.CompilerServices
{
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableAttribute : Attribute
	{
		public readonly byte[] NullableFlags;

		public NullableAttribute(byte P_0)
		{
			NullableFlags = new byte[1] { P_0 };
		}

		public NullableAttribute(byte[] P_0)
		{
			NullableFlags = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.Embedded]
	[AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)]
	internal sealed class NullableContextAttribute : Attribute
	{
		public readonly byte Flag;

		public NullableContextAttribute(byte P_0)
		{
			Flag = P_0;
		}
	}
	[CompilerGenerated]
	[Microsoft.CodeAnalysis.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;
		}
	}
}
internal static class LCMPluginInfo
{
	public const string PLUGIN_GUID = "OrbColors";

	public const string PLUGIN_NAME = "OrbColors";

	public const string PLUGIN_VERSION = "1.0.3";
}
namespace OrbColors
{
	[BepInPlugin("OrbColors", "OrbColors", "1.0.3")]
	public class Plugin : BaseUnityPlugin
	{
		[CompilerGenerated]
		private static class <>O
		{
			public static PacketListener <0>__ReceiveOrbColorPacket;

			public static PacketListener <1>__ReceivePlayerJoinPacket;
		}

		internal static ConfigEntry<bool> _customOrbColorEnabled;

		internal static Dictionary<string, ConfigEntry<float>> _myOrbColor = new Dictionary<string, ConfigEntry<float>>();

		internal static Dictionary<string, (bool, Color)> _playerOrbColors = new Dictionary<string, (bool, Color)>();

		internal static ManualLogSource Logger = null;

		private void Awake()
		{
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_004c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0056: Expected O, but got Unknown
			//IL_0062: Unknown result type (might be due to invalid IL or missing references)
			//IL_006c: Expected O, but got Unknown
			//IL_007c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0081: Unknown result type (might be due to invalid IL or missing references)
			//IL_0087: Expected O, but got Unknown
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a2: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a8: Expected O, but got Unknown
			Logger = ((BaseUnityPlugin)this).Logger;
			Logger.LogInfo((object)"Plugin OrbColors version 1.0.3 is loaded!");
			new Harmony("OrbColors").PatchAll(Assembly.GetExecutingAssembly());
			InitConfig();
			((BaseUnityPlugin)this).Config.SaveOnConfigSet = false;
			Settings.OnInitialized.AddListener(new UnityAction(AddSettings));
			Settings.OnApplySettings.AddListener((UnityAction)delegate
			{
				((BaseUnityPlugin)this).Config.Save();
			});
			object obj = <>O.<0>__ReceiveOrbColorPacket;
			if (obj == null)
			{
				PacketListener val = ReceiveOrbColorPacket;
				<>O.<0>__ReceiveOrbColorPacket = val;
				obj = (object)val;
			}
			CodeTalkerNetwork.RegisterListener<OrbColorPacket>((PacketListener)obj);
			object obj2 = <>O.<1>__ReceivePlayerJoinPacket;
			if (obj2 == null)
			{
				PacketListener val2 = ReceivePlayerJoinPacket;
				<>O.<1>__ReceivePlayerJoinPacket = val2;
				obj2 = (object)val2;
			}
			CodeTalkerNetwork.RegisterListener<PlayerJoinPacket>((PacketListener)obj2);
		}

		private void InitConfig()
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			//IL_001b: Unknown result type (might be due to invalid IL or missing references)
			//IL_0021: Expected O, but got Unknown
			//IL_0036: Unknown result type (might be due to invalid IL or missing references)
			//IL_0048: 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_006a: 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_00bd: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c4: Expected O, but got Unknown
			//IL_00da: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e1: Expected O, but got Unknown
			ConfigDefinition val = new ConfigDefinition("Example Category", "OrbColorsEnabled");
			ConfigDescription val2 = new ConfigDescription("Use Custom Orb Color?", (AcceptableValueBase)null, Array.Empty<object>());
			_customOrbColorEnabled = ((BaseUnityPlugin)this).Config.Bind<bool>(val, false, val2);
			Color val3 = default(Color);
			Dictionary<string, float> dictionary = new Dictionary<string, float>();
			dictionary.Add("Red", val3.r);
			dictionary.Add("Green", val3.g);
			dictionary.Add("Blue", val3.b);
			dictionary.Add("Alpha", val3.a);
			foreach (KeyValuePair<string, float> item in dictionary)
			{
				item.Deconstruct(out var key, out var value);
				string text = key;
				float num = value;
				ConfigDefinition val4 = new ConfigDefinition("Example Category", "Shield" + text);
				ConfigDescription val5 = new ConfigDescription(text, (AcceptableValueBase)(object)new AcceptableValueRange<float>(0f, 1f), Array.Empty<object>());
				_myOrbColor.Add(text, ((BaseUnityPlugin)this).Config.Bind<float>(val4, num, val5));
			}
		}

		private void AddSettings()
		{
			SettingsTab modTab = Settings.ModTab;
			modTab.AddHeader("Custom Shield Orb Color");
			modTab.AddToggle(((ConfigEntryBase)_customOrbColorEnabled).Description.Description, _customOrbColorEnabled);
			foreach (var (text2, val2) in _myOrbColor)
			{
				modTab.AddAdvancedSlider(text2, val2, false);
			}
		}

		internal static void SendOrbColorPacket()
		{
			if (NetworkClient.active && _myOrbColor.Count == 4)
			{
				OrbColorPacket orbColorPacket = new OrbColorPacket(_customOrbColorEnabled.Value, _myOrbColor["Red"].Value, _myOrbColor["Green"].Value, _myOrbColor["Blue"].Value, _myOrbColor["Alpha"].Value);
				CodeTalkerNetwork.SendNetworkPacket((PacketBase)(object)orbColorPacket);
			}
		}

		internal static void ReceiveOrbColorPacket(PacketHeader header, PacketBase packet)
		{
			//IL_00c9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00e2: Unknown result type (might be due to invalid IL or missing references)
			if (packet is OrbColorPacket orbColorPacket)
			{
				Logger.LogInfo((object)$"Packet Recieved | Plugin: {((PacketBase)orbColorPacket).PacketSourceGUID} | Steam ID: {header.SenderID} | PayLoad: {orbColorPacket.Enabled}, {orbColorPacket.Red}, {orbColorPacket.Green}, {orbColorPacket.Blue}, {orbColorPacket.Alpha}");
				Color item = default(Color);
				((Color)(ref item))..ctor(orbColorPacket.Red, orbColorPacket.Green, orbColorPacket.Blue, orbColorPacket.Alpha);
				string key = header.SenderID.ToString();
				if (header.SenderIsLobbyOwner)
				{
					key = "localhost";
				}
				if (!_playerOrbColors.TryAdd(key, (orbColorPacket.Enabled, item)))
				{
					_playerOrbColors[key] = (orbColorPacket.Enabled, item);
				}
			}
		}

		internal static void ReceivePlayerJoinPacket(PacketHeader header, PacketBase packet)
		{
			if (packet is PlayerJoinPacket && _customOrbColorEnabled.Value)
			{
				SendOrbColorPacket();
			}
		}
	}
	public class OrbColorPacket : PacketBase
	{
		public override string PacketSourceGUID => "OrbColors";

		[JsonProperty]
		public bool Enabled { get; set; }

		[JsonProperty]
		public float Red { get; set; }

		[JsonProperty]
		public float Green { get; set; }

		[JsonProperty]
		public float Blue { get; set; }

		[JsonProperty]
		public float Alpha { get; set; }

		public OrbColorPacket(bool enabled, float red, float green, float blue, float alpha)
		{
			Enabled = enabled;
			Red = red;
			Green = green;
			Blue = blue;
			Alpha = alpha;
			((PacketBase)this)..ctor();
		}
	}
	public class PlayerJoinPacket : PacketBase
	{
		public override string PacketSourceGUID => "OrbColors";
	}
	[HarmonyPatch(typeof(PlayerVisual), "Handle_BlockOrbEffects")]
	internal class PlayerVisualPatch
	{
		public static bool Prefix(PlayerVisual __instance)
		{
			//IL_0080: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a7: Unknown result type (might be due to invalid IL or missing references)
			//IL_00ee: Unknown result type (might be due to invalid IL or missing references)
			if (AtlyssNetworkManager._current._soloMode)
			{
				Color item = default(Color);
				((Color)(ref item))..ctor(Plugin._myOrbColor["Red"].Value, Plugin._myOrbColor["Green"].Value, Plugin._myOrbColor["Blue"].Value, Plugin._myOrbColor["Alpha"].Value);
				if (!Plugin._playerOrbColors.TryAdd(__instance._player._steamID, (Plugin._customOrbColorEnabled.Value, item)))
				{
					Plugin._playerOrbColors[__instance._player._steamID] = (Plugin._customOrbColorEnabled.Value, item);
				}
			}
			if (NetworkClient.active && Plugin._playerOrbColors.TryGetValue(__instance._player._steamID, out var value) && value.Item1)
			{
				((Renderer)__instance._blockOrbRender).material.SetColor("_EmissionColor", value.Item2);
				if (__instance._pCombat._inParryWindow && !__instance._parryWindowEffect.isEmitting)
				{
					__instance._parryWindowEffect.Play();
				}
				if (!__instance._pCombat._isBlocking || !__instance._pCombat._inParryWindow)
				{
					__instance._parryWindowEffect.Stop();
				}
				return false;
			}
			return true;
		}
	}
	[HarmonyPatch(typeof(Player), "OnStartAuthority")]
	internal class PlayerPatch
	{
		public static void Postfix()
		{
			if (NetworkClient.active)
			{
				CodeTalkerNetwork.SendNetworkPacket((PacketBase)(object)new PlayerJoinPacket());
			}
		}
	}
	[HarmonyPatch(typeof(ConfigFile), "Save")]
	internal class ConfigFilePatch
	{
		public static bool Prefix(ConfigFile __instance)
		{
			if (NetworkClient.active && __instance.ConfigFilePath.EndsWith("OrbColors.cfg"))
			{
				Plugin.SendOrbColorPacket();
			}
			return true;
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}