Decompiled source of CustomProvidence v1.1.0

CustomProvidence/CustomProvidence.dll

Decompiled 2 months 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 Configgy;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using UnityEngine;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: IgnoresAccessChecksTo("Assembly-CSharp")]
[assembly: AssemblyCompany("CustomProvidence")]
[assembly: AssemblyConfiguration("Debug")]
[assembly: AssemblyDescription("Lets you customize the eye of providence.")]
[assembly: AssemblyFileVersion("1.1.0.0")]
[assembly: AssemblyInformationalVersion("1.1.0+567ec3374be063793cc131f831330644526bce3f")]
[assembly: AssemblyProduct("CustomProvidence")]
[assembly: AssemblyTitle("CustomProvidence")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.1.0.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.Module, AllowMultiple = false, Inherited = false)]
	internal sealed class RefSafetyRulesAttribute : Attribute
	{
		public readonly int Version;

		public RefSafetyRulesAttribute(int P_0)
		{
			Version = P_0;
		}
	}
}
namespace CustomProvidence
{
	[BepInPlugin("com.earthlingOnFire.CustomProvidence", "CustomProvidence", "1.1.0")]
	[BepInDependency(/*Could not decode attribute arguments.*/)]
	public class Plugin : BaseUnityPlugin
	{
		public const string PLUGIN_GUID = "com.earthlingOnFire.CustomProvidence";

		public const string PLUGIN_NAME = "CustomProvidence";

		public const string PLUGIN_VERSION = "1.1.0";

		public static ManualLogSource logger;

		public static ConfigBuilder config;

		public static Random rand = new Random();

		public static string modAppdata;

		public static string textureFolder;

		public static string rareTextureFolder;

		public static string modDir;

		public static List<string> FileExtensions = new List<string> { ".jpeg", ".jpg", ".png", ".bmp" };

		public static Texture2D[] textures;

		[Configgable("", "Enabled", 0, null)]
		public static ConfigToggle EnabledToggle = new ConfigToggle(true);

		[Configgable("", "Reload Textures", 0, null)]
		public static ConfigButton ReloadTexturesButton = new ConfigButton((Action)delegate
		{
			TextureManager.ReloadTextures();
		}, (string)null);

		[Configgable("", "Open Textures Folder", 0, null)]
		public static ConfigButton OpenTexturesFolderButton = new ConfigButton((Action)delegate
		{
			Application.OpenURL(modAppdata);
		}, (string)null);

		[Configgable("", "Rare Texture Chance", 0, "Chance to use a texture from 'rare textures' folder.")]
		public static IntegerSlider RareTextureChanceSlider = new IntegerSlider(0, 0, 100);

		private void Awake()
		{
			((Object)((Component)this).gameObject).hideFlags = (HideFlags)61;
			logger = ((BaseUnityPlugin)this).Logger;
		}

		private void Start()
		{
			//IL_0072: Unknown result type (might be due to invalid IL or missing references)
			//IL_0082: Unknown result type (might be due to invalid IL or missing references)
			string path = Assembly.GetExecutingAssembly().Location.ToString();
			modDir = Path.GetDirectoryName(path);
			string folderPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
			modAppdata = Path.Combine(folderPath, "CustomProvidence");
			textureFolder = Path.Combine(modAppdata, "textures");
			rareTextureFolder = Path.Combine(modAppdata, "rare textures");
			CreateFolders();
			TextureManager.ReloadTextures();
			new ConfigBuilder("com.earthlingOnFire.CustomProvidence", "CustomProvidence").BuildAll();
			new Harmony("com.earthlingOnFire.CustomProvidence").PatchAll();
			logger.LogInfo((object)"Plugin com.earthlingOnFire.CustomProvidence is loaded!");
		}

		public static void CreateFolders()
		{
			if (!Directory.Exists(modAppdata))
			{
				Directory.CreateDirectory(modAppdata);
			}
			if (!Directory.Exists(textureFolder))
			{
				Directory.CreateDirectory(textureFolder);
				File.Copy(Path.Combine(modDir, "shittyprovidence.png"), Path.Combine(textureFolder, "shittyprovidence.png"));
			}
			if (!Directory.Exists(rareTextureFolder))
			{
				Directory.CreateDirectory(rareTextureFolder);
				File.Copy(Path.Combine(modDir, "rareshittyprovidence.png"), Path.Combine(rareTextureFolder, "rareshittyprovidence.png"));
			}
		}
	}
	[HarmonyPatch]
	public static class Patches
	{
		[HarmonyPostfix]
		[HarmonyPatch(typeof(EnemyIdentifier), "Start")]
		public static void ChangeEye(EnemyIdentifier __instance)
		{
			//IL_000e: Unknown result type (might be due to invalid IL or missing references)
			//IL_0015: Invalid comparison between Unknown and I4
			//IL_0069: Unknown result type (might be due to invalid IL or missing references)
			//IL_006f: Expected O, but got Unknown
			if (((ConfigValueElement<bool>)(object)Plugin.EnabledToggle).Value && (int)__instance.enemyType == 38 && !__instance.puppet)
			{
				Texture2D randomTexture = TextureManager.GetRandomTexture();
				if (!((Object)(object)randomTexture == (Object)null))
				{
					Transform val = ((Component)__instance).gameObject.transform.Find("Providence/Eye");
					Object.Destroy((Object)(object)((Component)val).GetComponent<AnimatedTexture>());
					Object.Destroy((Object)(object)((Component)val).GetComponent<BlinkAnimTex>());
					MaterialPropertyBlock val2 = new MaterialPropertyBlock();
					val2.SetTexture("_MainTex", (Texture)(object)randomTexture);
					((Renderer)((Component)val).GetComponent<SkinnedMeshRenderer>()).SetPropertyBlock(val2);
				}
			}
		}
	}
	public static class TextureManager
	{
		public static Texture2D[] textures = (Texture2D[])(object)new Texture2D[0];

		public static Texture2D[] rareTextures = (Texture2D[])(object)new Texture2D[0];

		public static List<string> FileExtensions = new List<string> { ".jpeg", ".jpg", ".png", ".bmp" };

		public static Random rand = new Random();

		public static void ReloadTextures()
		{
			string[] imagePaths = GetImagePaths(Plugin.textureFolder);
			textures = (Texture2D[])(object)new Texture2D[imagePaths.Length];
			for (int i = 0; i < imagePaths.Length; i++)
			{
				textures[i] = LoadTextureFromFile(imagePaths[i]);
			}
			string[] imagePaths2 = GetImagePaths(Plugin.rareTextureFolder);
			rareTextures = (Texture2D[])(object)new Texture2D[imagePaths2.Length];
			for (int j = 0; j < imagePaths2.Length; j++)
			{
				rareTextures[j] = LoadTextureFromFile(imagePaths2[j]);
			}
		}

		public static Texture2D GetRandomTexture()
		{
			if (rand.Next(0, 100) < ((ConfigValueElement<int>)(object)Plugin.RareTextureChanceSlider).Value)
			{
				int num = rand.Next(0, rareTextures.Length);
				return rareTextures[num];
			}
			int num2 = rand.Next(0, textures.Length);
			return textures[num2];
		}

		public static string[] GetImagePaths(string dirPath)
		{
			string[] files = Directory.GetFiles(dirPath);
			return Array.FindAll(files, (string x) => IsImage(x));
		}

		public static bool IsImage(string filePath)
		{
			foreach (string fileExtension in Plugin.FileExtensions)
			{
				if (filePath.EndsWith(fileExtension))
				{
					return true;
				}
			}
			return false;
		}

		public static Texture2D LoadTextureFromFile(string filePath)
		{
			//IL_000a: Unknown result type (might be due to invalid IL or missing references)
			//IL_0010: Expected O, but got Unknown
			byte[] array = File.ReadAllBytes(filePath);
			Texture2D val = new Texture2D(2, 2);
			ImageConversion.LoadImage(val, array);
			return val;
		}
	}
	public static class PluginInfo
	{
		public const string PLUGIN_GUID = "CustomProvidence";

		public const string PLUGIN_NAME = "CustomProvidence";

		public const string PLUGIN_VERSION = "1.1.0";
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		internal IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}