Decompiled source of White Monster Energy Zero Ultra v1.0.0

BepInEx/plugins/White Monster Energy Zero Ultra/WhiteMonsterEnergyZeroUltra.dll

Decompiled a week 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.Versioning;
using BepInEx;
using BepInEx.Logging;
using HarmonyLib;
using Microsoft.CodeAnalysis;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: Debuggable(DebuggableAttribute.DebuggingModes.IgnoreSymbolStoreSequencePoints)]
[assembly: TargetFramework(".NETStandard,Version=v2.1", FrameworkDisplayName = ".NET Standard 2.1")]
[assembly: AssemblyCompany("PeakEnergyDrinkReskin")]
[assembly: AssemblyConfiguration("Release")]
[assembly: AssemblyFileVersion("1.0.0.0")]
[assembly: AssemblyInformationalVersion("1.0.0")]
[assembly: AssemblyProduct("PeakEnergyDrinkReskin")]
[assembly: AssemblyTitle("PeakEnergyDrinkReskin")]
[assembly: AssemblyVersion("1.0.0.0")]
[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 PeakEnergyDrinkReskin
{
	[BepInPlugin("tom.peak.energydrink.reskin", "PeakEnergyDrinkReskin", "1.6.0")]
	public class Plugin : BaseUnityPlugin
	{
		private static ManualLogSource LogS;

		private const string CAN_WRAP_RESOURCE = "PeakEnergyDrinkReskin.assets.monster_white.png";

		private const string ICON_RESOURCE = "PeakEnergyDrinkReskin.assets.monster_icon.png";

		internal static Texture2D BaseTex;

		internal static Texture2D IconTex;

		internal static Texture2D NeutralGray;

		private readonly HashSet<int> _processedMatIds = new HashSet<int>();

		internal static void TryReskinObject(Object obj)
		{
			if (obj == (Object)null)
			{
				return;
			}
			GameObject val = (GameObject)(object)((obj is GameObject) ? obj : null);
			if ((Object)(object)val == (Object)null)
			{
				Component val2 = (Component)(object)((obj is Component) ? obj : null);
				if (val2 != null)
				{
					val = val2.gameObject;
				}
			}
			if (!((Object)(object)val == (Object)null))
			{
				Renderer[] componentsInChildren = val.GetComponentsInChildren<Renderer>(true);
				for (int i = 0; i < componentsInChildren.Length; i++)
				{
					TryReskinRenderer(componentsInChildren[i], null);
				}
			}
		}

		private void Awake()
		{
			//IL_0016: Unknown result type (might be due to invalid IL or missing references)
			LogS = ((BaseUnityPlugin)this).Logger;
			LoadTextures();
			new Harmony("tom.peak.energydrink.reskin").PatchAll();
			SceneManager.sceneLoaded += delegate
			{
				((MonoBehaviour)this).StartCoroutine(ReskinSoon());
			};
		}

		private IEnumerator ReskinSoon()
		{
			yield return null;
			yield return (object)new WaitForSeconds(0.1f);
			ReskinWorldOnce();
		}

		private void LoadTextures()
		{
			//IL_003e: Unknown result type (might be due to invalid IL or missing references)
			BaseTex = LoadEmbeddedTexture("PeakEnergyDrinkReskin.assets.monster_white.png", "can wrap");
			IconTex = LoadEmbeddedTexture("PeakEnergyDrinkReskin.assets.monster_icon.png", "HUD icon");
			NeutralGray = SolidTex(new Color(0.5f, 0.5f, 0.5f, 1f));
		}

		private Texture2D LoadEmbeddedTexture(string resourceName, string label)
		{
			//IL_0039: Unknown result type (might be due to invalid IL or missing references)
			//IL_003f: Expected O, but got Unknown
			using Stream stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resourceName);
			if (stream == null)
			{
				LogS.LogWarning((object)("Embedded resource not found: " + resourceName));
				return null;
			}
			using MemoryStream memoryStream = new MemoryStream();
			stream.CopyTo(memoryStream);
			Texture2D val = new Texture2D(2, 2, (TextureFormat)4, true);
			ImageConversion.LoadImage(val, memoryStream.ToArray());
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)1;
			LogS.LogInfo((object)$"Loaded embedded {label}: {((Texture)val).width}x{((Texture)val).height}");
			return val;
		}

		private static Texture2D SolidTex(Color c)
		{
			//IL_0004: Unknown result type (might be due to invalid IL or missing references)
			//IL_0009: Unknown result type (might be due to invalid IL or missing references)
			//IL_000c: Unknown result type (might be due to invalid IL or missing references)
			//IL_0012: Unknown result type (might be due to invalid IL or missing references)
			//IL_0018: Unknown result type (might be due to invalid IL or missing references)
			//IL_001f: Unknown result type (might be due to invalid IL or missing references)
			//IL_0027: Expected O, but got Unknown
			Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false);
			val.SetPixel(0, 0, c);
			val.Apply();
			((Texture)val).wrapMode = (TextureWrapMode)1;
			((Texture)val).filterMode = (FilterMode)1;
			return val;
		}

		private void ReskinWorldOnce()
		{
			if (!((Object)(object)BaseTex == (Object)null))
			{
				Renderer[] array = Resources.FindObjectsOfTypeAll<Renderer>();
				for (int i = 0; i < array.Length; i++)
				{
					TryReskinRenderer(array[i], LogS, _processedMatIds);
				}
			}
		}

		internal static void TryReskinRenderer(Renderer r, ManualLogSource log, HashSet<int> cache = null)
		{
			if ((Object)(object)r == (Object)null || (Object)(object)BaseTex == (Object)null)
			{
				return;
			}
			Material[] sharedMaterials = r.sharedMaterials;
			foreach (Material val in sharedMaterials)
			{
				if ((Object)(object)val == (Object)null || !((Object)val).name.StartsWith("M_EnergyDrink", StringComparison.Ordinal))
				{
					continue;
				}
				int instanceID = ((Object)val).GetInstanceID();
				if (cache != null && cache.Contains(instanceID))
				{
					continue;
				}
				if (val.HasProperty("_BaseTexture"))
				{
					val.SetTexture("_BaseTexture", (Texture)(object)BaseTex);
					if (log != null)
					{
						log.LogInfo((object)("Set _BaseTexture on " + ((Object)val).name));
					}
				}
				cache?.Add(instanceID);
			}
		}
	}
	[HarmonyPatch(typeof(TMP_Text), "set_text")]
	internal static class Patch_TMP_set_text
	{
		private static void Prefix(ref string __0)
		{
			if (!string.IsNullOrWhiteSpace(__0) && __0.Trim().Equals("ENERGY DRINK", StringComparison.OrdinalIgnoreCase))
			{
				__0 = "MONSTER ENERGY";
			}
		}
	}
	[HarmonyPatch(typeof(TMP_Text), "SetText", new Type[] { typeof(string) })]
	internal static class Patch_TMP_SetText_1
	{
		private static void Prefix(ref string __0)
		{
			if (!string.IsNullOrWhiteSpace(__0) && __0.Trim().Equals("ENERGY DRINK", StringComparison.OrdinalIgnoreCase))
			{
				__0 = "MONSTER ENERGY";
			}
		}
	}
	[HarmonyPatch(typeof(TMP_Text), "SetText", new Type[]
	{
		typeof(string),
		typeof(bool)
	})]
	internal static class Patch_TMP_SetText_2
	{
		private static void Prefix(ref string __0)
		{
			if (!string.IsNullOrWhiteSpace(__0) && __0.Trim().Equals("ENERGY DRINK", StringComparison.OrdinalIgnoreCase))
			{
				__0 = "MONSTER ENERGY";
			}
		}
	}
	[HarmonyPatch(typeof(Text), "set_text")]
	internal static class Patch_UIText_set_text
	{
		private static void Prefix(ref string __0)
		{
			if (!string.IsNullOrWhiteSpace(__0) && __0.Trim().Equals("ENERGY DRINK", StringComparison.OrdinalIgnoreCase))
			{
				__0 = "MONSTER ENERGY";
			}
		}
	}
	[HarmonyPatch(typeof(RawImage), "set_texture")]
	internal static class Patch_RawImage_set_texture
	{
		private static void Prefix(ref Texture __0)
		{
			if ((Object)(object)__0 != (Object)null && ((Object)__0).name == "Energy Drink" && (Object)(object)Plugin.IconTex != (Object)null)
			{
				__0 = (Texture)(object)Plugin.IconTex;
			}
		}
	}
	[HarmonyPatch(typeof(Image), "set_sprite")]
	internal static class Patch_Image_set_sprite
	{
		private static void Prefix(ref Sprite __0)
		{
			//IL_006e: Unknown result type (might be due to invalid IL or missing references)
			//IL_007d: Unknown result type (might be due to invalid IL or missing references)
			if (!((Object)(object)__0 == (Object)null) && !(((Object)__0).name != "Energy Drink") && !((Object)(object)Plugin.IconTex == (Object)null))
			{
				float num = ((__0.pixelsPerUnit > 0f) ? __0.pixelsPerUnit : 100f);
				__0 = Sprite.Create(Plugin.IconTex, new Rect(0f, 0f, (float)((Texture)Plugin.IconTex).width, (float)((Texture)Plugin.IconTex).height), new Vector2(0.5f, 0.5f), num);
			}
		}
	}
	[HarmonyPatch(typeof(Object), "Instantiate", new Type[] { typeof(Object) })]
	internal static class Patch_Instantiate_1
	{
		private static void Postfix(Object __result)
		{
			Plugin.TryReskinObject(__result);
		}
	}
	[HarmonyPatch(typeof(Object), "Instantiate", new Type[]
	{
		typeof(Object),
		typeof(Transform),
		typeof(bool)
	})]
	internal static class Patch_Instantiate_2
	{
		private static void Postfix(Object __result)
		{
			Plugin.TryReskinObject(__result);
		}
	}
	[HarmonyPatch(typeof(Object), "Instantiate", new Type[]
	{
		typeof(Object),
		typeof(Vector3),
		typeof(Quaternion)
	})]
	internal static class Patch_Instantiate_3
	{
		private static void Postfix(Object __result)
		{
			Plugin.TryReskinObject(__result);
		}
	}
	[HarmonyPatch(typeof(Object), "Instantiate", new Type[]
	{
		typeof(Object),
		typeof(Vector3),
		typeof(Quaternion),
		typeof(Transform)
	})]
	internal static class Patch_Instantiate_4
	{
		private static void Postfix(Object __result)
		{
			Plugin.TryReskinObject(__result);
		}
	}
	[HarmonyPatch(typeof(Renderer), "set_material")]
	internal static class Patch_Renderer_set_material
	{
		private static void Postfix(Renderer __instance)
		{
			Plugin.TryReskinRenderer(__instance, null);
		}
	}
	[HarmonyPatch(typeof(Renderer), "set_sharedMaterial")]
	internal static class Patch_Renderer_set_sharedMaterial
	{
		private static void Postfix(Renderer __instance)
		{
			Plugin.TryReskinRenderer(__instance, null);
		}
	}
	[HarmonyPatch(typeof(Renderer), "set_materials")]
	internal static class Patch_Renderer_set_materials
	{
		private static void Postfix(Renderer __instance)
		{
			Plugin.TryReskinRenderer(__instance, null);
		}
	}
	[HarmonyPatch(typeof(Renderer), "set_sharedMaterials")]
	internal static class Patch_Renderer_set_sharedMaterials
	{
		private static void Postfix(Renderer __instance)
		{
			Plugin.TryReskinRenderer(__instance, null);
		}
	}
}