Decompiled source of LGBTQ Hitscan v1.0.0

LGBTQ Hitscan/LGBTQHitscan.dll

Decompiled 14 hours ago
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.Versioning;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using LGBTQHitscan.Utils;
using Microsoft.CodeAnalysis;
using ThornClient.Core;
using ThornClient.Core.ConfigurableElements;
using ThornClient.Managers;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("LGBTQHitscan")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("LGBTQ Hitscan")]
[assembly: AssemblyTitle("LGBTQHitscan")]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.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.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]
	[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]
	[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;
		}
	}
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}
namespace LGBTQHitscan
{
	public enum FlagChoice
	{
		Random,
		Transgender,
		Pansexual,
		Nonbinary,
		Lesbian,
		Gay,
		Bisexual,
		Asexual,
		Agender
	}
	public class HitscanConfig : Module
	{
		private static Sprite icon;

		public override Sprite Icon => ((Object)(object)icon != (Object)null) ? icon : (icon = BundleLoader.LoadIcon("LGBTQHitscan.icon.png"));

		public HitscanConfig()
			: base("com.achelia.lgbtqhitscan", "LGBTQ Hitscan", "Pride flag hitscan beams", (ModuleCategory)1, (KeyCode)0, (KeyCode)0, false, true)
		{
			//IL_009e: Unknown result type (might be due to invalid IL or missing references)
			//IL_00a3: Unknown result type (might be due to invalid IL or missing references)
			//IL_00aa: Unknown result type (might be due to invalid IL or missing references)
			//IL_00bb: Expected O, but got Unknown
			((Configurable)this).IsEnabled = true;
			Plugin.FlagField = ((Configurable)this).CreateSetting<FlagChoice>("flag", "Beam Flag", "", FlagChoice.Random, (SettingGroup)null);
			Dictionary<string, string> dictionary = new Dictionary<string, string>();
			foreach (KeyValuePair<FlagChoice, string> flagLabel in Plugin.FlagLabels)
			{
				dictionary[flagLabel.Key.ToString()] = flagLabel.Value;
			}
			((Setting)Plugin.FlagField).Hints = new InterfaceHints
			{
				EnumSubstitutions = dictionary,
				EnumPreferButtonGroup = true
			};
		}
	}
	internal static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "com.achelia.lgbtqhitscan";

		public const string PLUGIN_NAME = "LGBTQ Hitscan";

		public const string PLUGIN_VERSION = "1.0.0";
	}
	[BepInPlugin("com.achelia.lgbtqhitscan", "LGBTQ Hitscan", "1.0.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		[HarmonyPatch(typeof(RevolverBeam), "Start")]
		private class RevolverBeamPatch
		{
			private static void Postfix(RevolverBeam __instance)
			{
				//IL_0031: Unknown result type (might be due to invalid IL or missing references)
				//IL_0037: Expected O, but got Unknown
				//IL_0040: Unknown result type (might be due to invalid IL or missing references)
				//IL_004a: Unknown result type (might be due to invalid IL or missing references)
				//IL_004f: Unknown result type (might be due to invalid IL or missing references)
				//IL_0056: Unknown result type (might be due to invalid IL or missing references)
				//IL_0060: Unknown result type (might be due to invalid IL or missing references)
				//IL_0065: Unknown result type (might be due to invalid IL or missing references)
				//IL_0083: Unknown result type (might be due to invalid IL or missing references)
				//IL_0088: Unknown result type (might be due to invalid IL or missing references)
				//IL_0099: Unknown result type (might be due to invalid IL or missing references)
				//IL_009e: Unknown result type (might be due to invalid IL or missing references)
				//IL_00b7: Unknown result type (might be due to invalid IL or missing references)
				//IL_00bd: Expected O, but got Unknown
				//IL_00dd: 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)
				//IL_0125: Unknown result type (might be due to invalid IL or missing references)
				//IL_0170: Unknown result type (might be due to invalid IL or missing references)
				string text = PickFlagKey();
				if (text == null)
				{
					return;
				}
				LineRenderer component = ((Component)__instance).GetComponent<LineRenderer>();
				if ((Object)(object)component == (Object)null)
				{
					return;
				}
				Gradient val = new Gradient();
				val.colorKeys = (GradientColorKey[])(object)new GradientColorKey[2]
				{
					new GradientColorKey(Color.white, 0f),
					new GradientColorKey(Color.white, 1f)
				};
				val.alphaKeys = (GradientAlphaKey[])(object)new GradientAlphaKey[2]
				{
					new GradientAlphaKey(1f, 0f),
					new GradientAlphaKey(1f, 1f)
				};
				component.colorGradient = val;
				Material val2 = new Material(((Renderer)component).material);
				val2.mainTexture = (Texture)(object)CachedTextures[text];
				((Renderer)component).material = val2;
				Color color = AverageColors[text];
				Sprite muzzleFlashSprite = MuzzleFlashSprite;
				SpriteRenderer[] componentsInChildren = ((Component)__instance).GetComponentsInChildren<SpriteRenderer>(true);
				SpriteRenderer[] array = componentsInChildren;
				foreach (SpriteRenderer val3 in array)
				{
					if (((Object)val3).name.ToLower().Contains("muzzle"))
					{
						val3.color = color;
						if ((Object)(object)muzzleFlashSprite != (Object)null)
						{
							val3.sprite = muzzleFlashSprite;
						}
					}
				}
				Light component2 = ((Component)__instance).GetComponent<Light>();
				if ((Object)(object)component2 != (Object)null)
				{
					component2.color = color;
				}
			}
		}

		public static readonly Dictionary<string, Texture2D> CachedTextures = new Dictionary<string, Texture2D>();

		public static readonly Dictionary<string, Color> AverageColors = new Dictionary<string, Color>();

		public static readonly List<string> FlagPool = new List<string>();

		public static readonly Dictionary<FlagChoice, string> FlagKeys = new Dictionary<FlagChoice, string>
		{
			{
				FlagChoice.Transgender,
				"tran"
			},
			{
				FlagChoice.Pansexual,
				"pan"
			},
			{
				FlagChoice.Nonbinary,
				"non"
			},
			{
				FlagChoice.Lesbian,
				"les"
			},
			{
				FlagChoice.Gay,
				"gay"
			},
			{
				FlagChoice.Bisexual,
				"bi"
			},
			{
				FlagChoice.Asexual,
				"ase"
			},
			{
				FlagChoice.Agender,
				"age"
			}
		};

		public static readonly Dictionary<FlagChoice, string> FlagLabels = new Dictionary<FlagChoice, string>
		{
			{
				FlagChoice.Random,
				"Random"
			},
			{
				FlagChoice.Transgender,
				"Transgender"
			},
			{
				FlagChoice.Pansexual,
				"Pansexual"
			},
			{
				FlagChoice.Nonbinary,
				"Nonbinary"
			},
			{
				FlagChoice.Lesbian,
				"Lesbian"
			},
			{
				FlagChoice.Gay,
				"Gay"
			},
			{
				FlagChoice.Bisexual,
				"Bisexual"
			},
			{
				FlagChoice.Asexual,
				"Asexual"
			},
			{
				FlagChoice.Agender,
				"Agender"
			}
		};

		private static readonly string[] FlagFiles = new string[9] { "tran.png", "pan.png", "non.png", "les.png", "gay.png", "bi.png", "ase.png", "age.png", "muzzleflashwhite1.png" };

		private const string AssetPath = "Assets/Custom/improudofyou/";

		private const string MuzzleFlashKey = "flash";

		internal static ManualLogSource Log;

		public static HitscanConfig ConfigModule;

		public static Setting<FlagChoice> FlagField;

		private static Sprite muzzleFlashSprite;

		private static Harmony harmony;

		private static Sprite MuzzleFlashSprite
		{
			get
			{
				//IL_004f: 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)
				if ((Object)(object)muzzleFlashSprite != (Object)null)
				{
					return muzzleFlashSprite;
				}
				if (!CachedTextures.TryGetValue("flash", out Texture2D value))
				{
					return null;
				}
				return muzzleFlashSprite = Sprite.Create(value, new Rect(0f, 0f, (float)((Texture)value).width, (float)((Texture)value).height), new Vector2(0.5f, 0.5f), 100f);
			}
		}

		private static bool Enabled => ConfigModule == null || ((Configurable)ConfigModule).IsEnabled;

		private static string PickFlagKey()
		{
			if (!Enabled)
			{
				return null;
			}
			FlagChoice flagChoice = ((FlagField != null) ? FlagField.Value : FlagChoice.Random);
			if (flagChoice != FlagChoice.Random && FlagKeys.TryGetValue(flagChoice, out string value) && CachedTextures.ContainsKey(value))
			{
				return value;
			}
			if (FlagPool.Count == 0)
			{
				return null;
			}
			return FlagPool[Random.Range(0, FlagPool.Count)];
		}

		private void Awake()
		{
			//IL_00a9: Unknown result type (might be due to invalid IL or missing references)
			//IL_00b3: Expected O, but got Unknown
			Log = ((BaseUnityPlugin)this).Logger;
			BundleLoader.Initialize();
			string[] flagFiles = FlagFiles;
			foreach (string file in flagFiles)
			{
				LoadTexture(file);
			}
			Log.LogInfo((object)("Loaded " + FlagPool.Count + " of " + (FlagFiles.Length - 1) + " flag textures."));
			ConfigModule = new HitscanConfig();
			RegisterConfig();
			ConfigManager.LoadConfig((Configurable)(object)ConfigModule);
			harmony = new Harmony("com.achelia.lgbtqhitscan");
			harmony.PatchAll();
			Log.LogInfo((object)"LGBTQ Hitscan 1.0.0 loaded.");
		}

		private static void RegisterConfig()
		{
			if (ConfigModule == null || ModuleManager.Items == null)
			{
				return;
			}
			ModuleManager.Items.RemoveAll((Module module) => module != null && ((Configurable)module).GUID == "com.achelia.lgbtqhitscan" && (object)module != ConfigModule);
			foreach (Module item in ModuleManager.Items)
			{
				if ((object)item == ConfigModule)
				{
					return;
				}
			}
			ModuleManager.Items.Add((Module)(object)ConfigModule);
		}

		private static void LoadTexture(string file)
		{
			//IL_0089: Unknown result type (might be due to invalid IL or missing references)
			if ((Object)(object)BundleLoader.Bundle == (Object)null)
			{
				return;
			}
			Texture2D val = BundleLoader.Bundle.LoadAsset<Texture2D>("Assets/Custom/improudofyou/" + file);
			if ((Object)(object)val == (Object)null)
			{
				Log.LogWarning((object)("Asset bundle does not contain " + file + "."));
				return;
			}
			string text = Path.GetFileNameWithoutExtension(file);
			if (text == "muzzleflashwhite1")
			{
				text = "flash";
			}
			CachedTextures[text] = val;
			AverageColors[text] = CalculateAverageColor(val);
			if (text != "flash" && !FlagPool.Contains(text))
			{
				FlagPool.Add(text);
			}
		}

		private static Color CalculateAverageColor(Texture2D texture)
		{
			//IL_0094: Unknown result type (might be due to invalid IL or missing references)
			//IL_0099: Unknown result type (might be due to invalid IL or missing references)
			//IL_009d: Unknown result type (might be due to invalid IL or missing references)
			Color[] pixels = texture.GetPixels();
			float num = 0f;
			float num2 = 0f;
			float num3 = 0f;
			float num4 = 0f;
			for (int i = 0; i < pixels.Length; i++)
			{
				num += pixels[i].r;
				num2 += pixels[i].g;
				num3 += pixels[i].b;
				num4 += pixels[i].a;
			}
			float num5 = pixels.Length;
			return new Color(num / num5, num2 / num5, num3 / num5, num4 / num5);
		}
	}
}
namespace LGBTQHitscan.Utils
{
	public static class BundleLoader
	{
		private const string BundleResourceName = "LGBTQHitscan.bundle";

		public static AssetBundle? Bundle;

		public static void Initialize()
		{
			if ((Object)(object)Bundle != (Object)null)
			{
				return;
			}
			Assembly assembly = typeof(BundleLoader).Assembly;
			using Stream stream = assembly.GetManifestResourceStream("LGBTQHitscan.bundle");
			if (stream == null)
			{
				Plugin.Log.LogError((object)"Embedded asset bundle 'LGBTQHitscan.bundle' was not found in the assembly.");
				return;
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			Bundle = AssetBundle.LoadFromMemory(memoryStream.ToArray());
			if ((Object)(object)Bundle == (Object)null)
			{
				Plugin.Log.LogError((object)"Failed to load the asset bundle from memory.");
			}
			else
			{
				Plugin.Log.LogInfo((object)"Asset bundle loaded.");
			}
		}

		public static Sprite? LoadIcon(string resourcePath)
		{
			//IL_0061: Unknown result type (might be due to invalid IL or missing references)
			//IL_0067: Expected O, but got Unknown
			//IL_00b1: Unknown result type (might be due to invalid IL or missing references)
			//IL_00c0: Unknown result type (might be due to invalid IL or missing references)
			try
			{
				using Stream stream = typeof(BundleLoader).Assembly.GetManifestResourceStream(resourcePath);
				if (stream == null)
				{
					Plugin.Log.LogWarning((object)("Embedded icon '" + resourcePath + "' was not found in the assembly."));
					return null;
				}
				byte[] array = new byte[stream.Length];
				stream.Read(array, 0, array.Length);
				Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
				if (!ImageConversion.LoadImage(val, array))
				{
					Plugin.Log.LogWarning((object)("Embedded icon '" + resourcePath + "' could not be decoded."));
					return null;
				}
				return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0.5f, 0.5f), 100f);
			}
			catch
			{
				return null;
			}
		}
	}
}