Decompiled source of TextureReplacer v1.0.3

texreplacemaybe.dll

Decompiled 2 weeks ago
using System;
using System.Diagnostics;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Security;
using System.Security.Permissions;
using BepInEx;
using BepInEx.Configuration;
using Microsoft.CodeAnalysis;
using UnityEngine;
using UnityEngine.SceneManagement;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: IgnoresAccessChecksTo("")]
[assembly: AssemblyCompany("texreplacemaybe")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("My first plugin")]
[assembly: AssemblyTitle("texreplacemaybe")]
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
[assembly: AssemblyVersion("1.0.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 texreplacemaybe
{
	public static class MyPluginInfo
	{
		public const string PLUGIN_GUID = "texreplacemaybe";

		public const string PLUGIN_NAME = "My first plugin";

		public const string PLUGIN_VERSION = "1.0.0";
	}
}
namespace TextureReplacer
{
	[BepInPlugin("com.doug.texturereplacer", "Texture Replacer", "1.0.0")]
	public class TextureReplacer : BaseUnityPlugin
	{
		private ConfigEntry<string> texturePath;

		private void Awake()
		{
			texturePath = ((BaseUnityPlugin)this).Config.Bind<string>("General", "Texture path", "put your path here", "put your file path there");
			Loadtexture(texturePath.Value);
			((BaseUnityPlugin)this).Logger.LogInfo((object)"TextureReplacer loaded");
		}

		private void Start()
		{
			SceneManager.activeSceneChanged += SceneManager_activeSceneChanged;
			Applytexture(Loadtexture(texturePath.Value));
		}

		private Texture2D Loadtexture(string path)
		{
			//IL_0013: Unknown result type (might be due to invalid IL or missing references)
			//IL_0019: Expected O, but got Unknown
			if (!File.Exists(path))
			{
				return null;
			}
			byte[] array = File.ReadAllBytes(path);
			Texture2D val = new Texture2D(2, 2);
			if (ImageConversion.LoadImage(val, array))
			{
				return val;
			}
			return null;
		}

		private void Applytexture(Texture2D tex)
		{
			Renderer[] array = Object.FindObjectsOfType<Renderer>();
			for (int i = 0; i < array.Length; i++)
			{
				Material[] sharedMaterials = array[i].sharedMaterials;
				foreach (Material val in sharedMaterials)
				{
					if (Object.op_Implicit((Object)(object)val) && val.HasProperty("_MainTex"))
					{
						val.SetTexture("_MainTex", (Texture)(object)tex);
					}
				}
			}
		}

		private void SceneManager_activeSceneChanged(Scene arg0, Scene arg1)
		{
			Applytexture(Loadtexture(texturePath.Value));
		}
	}
}
namespace System.Runtime.CompilerServices
{
	[AttributeUsage(AttributeTargets.Assembly, AllowMultiple = true)]
	internal sealed class IgnoresAccessChecksToAttribute : Attribute
	{
		public IgnoresAccessChecksToAttribute(string assemblyName)
		{
		}
	}
}