Decompiled source of Minos with PANTS v1.0.5

plugins/TextureReplacer.dll

Decompiled a day ago
using System;
using System.Collections;
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 BepInEx;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.Default | DebuggableAttribute.DebuggingModes.DisableOptimizations | DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints | DebuggableAttribute.DebuggingModes.EnableEditAndContinue)]
[assembly: AssemblyTitle("TextureReplacer")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("TextureReplacer")]
[assembly: AssemblyCopyright("Copyright ©  2026")]
[assembly: AssemblyTrademark("")]
[assembly: ComVisible(false)]
[assembly: Guid("50bda214-2a8f-44ab-8988-2c76f590ea54")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: TargetFramework(".NETFramework,Version=v4.7.2", FrameworkDisplayName = ".NET Framework 4.7.2")]
[assembly: AssemblyVersion("1.0.0.0")]
[BepInPlugin("ultrakill.texturereplacer", "Texture Replacer", "1.0.0")]
public class MultiTextureMod : BaseUnityPlugin
{
	[HarmonyPatch(typeof(MinosPrime), "Start")]
	private static class SceneLoadedPatch
	{
		private static void Postfix()
		{
			//IL_0029: Unknown result type (might be due to invalid IL or missing references)
			//IL_0033: Expected O, but got Unknown
			if (replacements.Count != 0)
			{
				if ((Object)(object)coroutineHost == (Object)null)
				{
					coroutineHost = new GameObject("TextureReplacerMod_CoroutineHost");
					Object.DontDestroyOnLoad((Object)(object)coroutineHost);
					coroutineHost.AddComponent<Dummy>();
				}
				((MonoBehaviour)coroutineHost.GetComponent<Dummy>()).StartCoroutine(ReplaceRoutine());
			}
		}
	}

	private class Dummy : MonoBehaviour
	{
	}

	[CompilerGenerated]
	private sealed class <ReplaceRoutine>d__7 : IEnumerator<object>, IDisposable, IEnumerator
	{
		private int <>1__state;

		private object <>2__current;

		private int <replaced>5__1;

		private Renderer[] <>s__2;

		private int <>s__3;

		private Renderer <rend>5__4;

		private Material[] <>s__5;

		private int <>s__6;

		private Material <mat>5__7;

		private string[] <>s__8;

		private int <>s__9;

		private string <prop>5__10;

		private Texture <tex>5__11;

		private Texture2D <newTex>5__12;

		private RawImage[] <>s__13;

		private int <>s__14;

		private RawImage <raw>5__15;

		private Texture2D <newTex>5__16;

		object IEnumerator<object>.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		object IEnumerator.Current
		{
			[DebuggerHidden]
			get
			{
				return <>2__current;
			}
		}

		[DebuggerHidden]
		public <ReplaceRoutine>d__7(int <>1__state)
		{
			this.<>1__state = <>1__state;
		}

		[DebuggerHidden]
		void IDisposable.Dispose()
		{
			<>s__2 = null;
			<rend>5__4 = null;
			<>s__5 = null;
			<mat>5__7 = null;
			<>s__8 = null;
			<prop>5__10 = null;
			<tex>5__11 = null;
			<newTex>5__12 = null;
			<>s__13 = null;
			<raw>5__15 = null;
			<newTex>5__16 = null;
			<>1__state = -2;
		}

		private bool MoveNext()
		{
			//IL_0026: Unknown result type (might be due to invalid IL or missing references)
			//IL_0030: Expected O, but got Unknown
			switch (<>1__state)
			{
			default:
				return false;
			case 0:
				<>1__state = -1;
				<>2__current = (object)new WaitForSeconds(0.6f);
				<>1__state = 1;
				return true;
			case 1:
				<>1__state = -1;
				<replaced>5__1 = 0;
				<>s__2 = Object.FindObjectsOfType<Renderer>(true);
				for (<>s__3 = 0; <>s__3 < <>s__2.Length; <>s__3++)
				{
					<rend>5__4 = <>s__2[<>s__3];
					if (!((Object)(object)<rend>5__4 == (Object)null) && <rend>5__4.sharedMaterials != null)
					{
						<>s__5 = <rend>5__4.sharedMaterials;
						for (<>s__6 = 0; <>s__6 < <>s__5.Length; <>s__6++)
						{
							<mat>5__7 = <>s__5[<>s__6];
							if (!((Object)(object)<mat>5__7 == (Object)null))
							{
								<>s__8 = TextureProps;
								for (<>s__9 = 0; <>s__9 < <>s__8.Length; <>s__9++)
								{
									<prop>5__10 = <>s__8[<>s__9];
									if (<mat>5__7.HasProperty(<prop>5__10))
									{
										<tex>5__11 = <mat>5__7.GetTexture(<prop>5__10);
										if (!((Object)(object)<tex>5__11 == (Object)null))
										{
											if (replacements.TryGetValue(((Object)<tex>5__11).name.ToLower(), out <newTex>5__12))
											{
												<mat>5__7.SetTexture(<prop>5__10, (Texture)(object)<newTex>5__12);
												<replaced>5__1++;
											}
											<tex>5__11 = null;
											<newTex>5__12 = null;
											<prop>5__10 = null;
										}
									}
								}
								<>s__8 = null;
								<mat>5__7 = null;
							}
						}
						<>s__5 = null;
						<rend>5__4 = null;
					}
				}
				<>s__2 = null;
				<>s__13 = Object.FindObjectsOfType<RawImage>(true);
				for (<>s__14 = 0; <>s__14 < <>s__13.Length; <>s__14++)
				{
					<raw>5__15 = <>s__13[<>s__14];
					if (!((Object)(object)<raw>5__15.texture == (Object)null))
					{
						if (replacements.TryGetValue(((Object)<raw>5__15.texture).name.ToLower(), out <newTex>5__16))
						{
							<raw>5__15.texture = (Texture)(object)<newTex>5__16;
							<replaced>5__1++;
						}
						<newTex>5__16 = null;
						<raw>5__15 = null;
					}
				}
				<>s__13 = null;
				Debug.Log((object)$"[TextureReplacerMod] Replaced: {<replaced>5__1}");
				return false;
			}
		}

		bool IEnumerator.MoveNext()
		{
			//ILSpy generated this explicit interface implementation from .override directive in MoveNext
			return this.MoveNext();
		}

		[DebuggerHidden]
		void IEnumerator.Reset()
		{
			throw new NotSupportedException();
		}
	}

	private static readonly Dictionary<string, string> TextureMap = new Dictionary<string, string> { { "MinosPrime 1", "MinosPrime1.png" } };

	private static readonly Dictionary<string, Texture2D> replacements = new Dictionary<string, Texture2D>();

	private static GameObject coroutineHost;

	private static readonly string[] TextureProps = new string[3] { "_MainTex", "_BaseMap", "_EmissiveTex" };

	private void Awake()
	{
		//IL_000d: Unknown result type (might be due to invalid IL or missing references)
		LoadReplacementTextures();
		new Harmony("ultrakill.texturereplacer").PatchAll();
		((BaseUnityPlugin)this).Logger.LogInfo((object)"MultiTextureMod loaded");
	}

	private void LoadReplacementTextures()
	{
		//IL_0089: Unknown result type (might be due to invalid IL or missing references)
		//IL_0090: Expected O, but got Unknown
		string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "textures");
		foreach (KeyValuePair<string, string> item in TextureMap)
		{
			string key = item.Key;
			string value = item.Value;
			string text = Path.Combine(path, value);
			if (!File.Exists(text))
			{
				((BaseUnityPlugin)this).Logger.LogWarning((object)("Missing texture file: " + text));
				continue;
			}
			byte[] array = File.ReadAllBytes(text);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false);
			ImageConversion.LoadImage(val, array);
			((Object)val).name = key;
			replacements[key.ToLower()] = val;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Loaded texture: " + key));
		}
	}

	[IteratorStateMachine(typeof(<ReplaceRoutine>d__7))]
	private static IEnumerator ReplaceRoutine()
	{
		//yield-return decompiler failed: Unexpected instruction in Iterator.Dispose()
		return new <ReplaceRoutine>d__7(0);
	}
}