Decompiled source of OstrichMods v0.1.0

plugins/TaxadFaces/TaxadFaces.dll

Decompiled 3 weeks ago
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
using TMPro;
using UnityEngine;
using UnityEngine.SceneManagement;
using UnityEngine.TextCore;
using UnityEngine.UI;

[assembly: CompilationRelaxations(8)]
[assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)]
[assembly: AssemblyVersion("0.0.0.0")]
[BepInPlugin("local.taxadfaces", "Taxad Faces", "0.1.6")]
public sealed class TaxadFaces : BaseUnityPlugin
{
	private static TaxadFaces instance;

	private Harmony harmony;

	private Texture2D faces;

	private Texture2D hands;

	private Texture2D boxHands;

	private Texture2D creepyFace;

	private ConfigEntry<bool> enabledSetting;

	private ConfigEntry<bool> featuresSetting;

	private ConfigEntry<bool> handsSetting;

	private readonly Dictionary<int, TMP_SpriteAsset> clones = new Dictionary<int, TMP_SpriteAsset>();

	private readonly List<Object> owned = new List<Object>();

	private readonly Dictionary<TMP_Text, TMP_SpriteAsset> originals = new Dictionary<TMP_Text, TMP_SpriteAsset>();

	private readonly Dictionary<Renderer, Material[]> originalRendererMaterials = new Dictionary<Renderer, Material[]>();

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

	private readonly Dictionary<Type, FieldInfo[]> displayFields = new Dictionary<Type, FieldInfo[]>();

	private static readonly Dictionary<string, int> HandCells = new Dictionary<string, int>(StringComparer.Ordinal)
	{
		{ "thumbsup", 0 },
		{ "thumbsup2", 1 },
		{ "thumbsdown", 2 },
		{ "thumbsdown2", 3 },
		{ "pointright", 4 },
		{ "pointleft", 5 },
		{ "point", 6 },
		{ "fist", 7 },
		{ "wave", 8 },
		{ "finger_wag", 9 },
		{ "pray", 10 },
		{ "deal", 11 },
		{ "give_left", 12 },
		{ "give_right", 13 },
		{ "box_left", 14 },
		{ "box_right", 15 }
	};

	private static readonly Dictionary<string, int> FaceCells = new Dictionary<string, int>(StringComparer.Ordinal)
	{
		{ ":P", 0 },
		{ ":D", 1 },
		{ ":O", 2 },
		{ "angry", 3 },
		{ ":|", 4 },
		{ ":)", 5 },
		{ ":/", 6 },
		{ "blush", 7 },
		{ ";)", 8 },
		{ ":'(", 9 },
		{ "hush", 10 },
		{ "dead", 11 },
		{ "hearteyes", 12 },
		{ "think", 13 },
		{ "cryinglaughing", 14 },
		{ "creepycrying", 15 },
		{ "sleep", 16 },
		{ "yawn", 17 },
		{ "nap", 18 },
		{ "speechless", 19 },
		{ "shades", 20 },
		{ "fedup", 21 },
		{ "horror", 22 },
		{ ":(", 23 },
		{ "mellow", 24 },
		{ "poopeyes", 25 },
		{ "moneyeyes", 26 },
		{ "pleading", 27 },
		{ "blush_smile", 28 },
		{ "dry", 29 },
		{ "smh", 30 },
		{ "disappointed", 31 },
		{ "kiss", 32 },
		{ "weary", 33 },
		{ "clown", 34 },
		{ "disappointed2", 35 },
		{ "evil_smile", 36 },
		{ "dead_clown", 37 },
		{ "scared", 38 },
		{ "slight_smile", 39 },
		{ "void", 40 },
		{ "ghost", 46 },
		{ "skull", 47 },
		{ "deathhead", 47 },
		{ "headman", 47 },
		{ "headman2", 47 },
		{ "dorment", 18 },
		{ "empty", 19 }
	};

	private static readonly Dictionary<string, int> EyeCells = new Dictionary<string, int>(StringComparer.Ordinal)
	{
		{ "eyesright", 41 },
		{ "eyesleft", 41 },
		{ "eye", 42 },
		{ "eyecry", 9 },
		{ "eyeblank", 48 },
		{ "eyesmall", 48 },
		{ "eyeheart", 12 },
		{ "eyeclosed", 16 },
		{ "eyedead", 11 },
		{ "realistic_eye", 41 },
		{ "void_eye", 40 },
		{ "weird_eye", 42 }
	};

	private static readonly Dictionary<string, int> MouthCells = new Dictionary<string, int>(StringComparer.Ordinal)
	{
		{ "mouthsmile", 5 },
		{ "mouthhappy", 1 },
		{ "mouthsad", 23 },
		{ "mouthsurprised", 2 },
		{ "mouth", 4 },
		{ "nasty_lips", 43 },
		{ "evil_mouth", 44 },
		{ "weird_mouth", 45 }
	};

	private void Awake()
	{
		//IL_0097: Unknown result type (might be due to invalid IL or missing references)
		//IL_00a1: Expected O, but got Unknown
		//IL_019b: Unknown result type (might be due to invalid IL or missing references)
		//IL_01a5: Expected O, but got Unknown
		//IL_00e6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f0: Expected O, but got Unknown
		//IL_0140: Unknown result type (might be due to invalid IL or missing references)
		//IL_014a: Expected O, but got Unknown
		//IL_0298: Unknown result type (might be due to invalid IL or missing references)
		//IL_02a5: Expected O, but got Unknown
		instance = this;
		enabledSetting = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "Enabled", true, "Enable the cosmetic replacements. Restart after changing.");
		featuresSetting = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ReplaceFaceParts", true, "Also replace the individual eyes and mouths in Taxman's composite faces. Restart after changing.");
		handsSetting = ((BaseUnityPlugin)this).Config.Bind<bool>("General", "ReplaceHandSigns", true, "Use hand gestures matching Taxad's skin tone on supported displays. Restart after changing.");
		if (!enabledSetting.Value)
		{
			return;
		}
		string path = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "taxad-expressions.png");
		faces = new Texture2D(2, 2, (TextureFormat)4, false);
		try
		{
			if (!ImageConversion.LoadImage(faces, File.ReadAllBytes(path), false))
			{
				throw new InvalidDataException("Invalid face PNG");
			}
			owned.Add((Object)(object)faces);
			if (handsSetting.Value)
			{
				hands = new Texture2D(2, 2, (TextureFormat)4, false);
				owned.Add((Object)(object)hands);
				string path2 = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "taxad-hands.png");
				if (!ImageConversion.LoadImage(hands, File.ReadAllBytes(path2), false))
				{
					throw new InvalidDataException("Invalid hands PNG");
				}
				boxHands = new Texture2D(2, 2, (TextureFormat)4, false);
				owned.Add((Object)(object)boxHands);
				string path3 = Path.Combine(Path.GetDirectoryName(((BaseUnityPlugin)this).Info.Location), "taxad-box-hands.png");
				if (!ImageConversion.LoadImage(boxHands, File.ReadAllBytes(path3), false))
				{
					throw new InvalidDataException("Invalid box hands PNG");
				}
			}
			harmony = new Harmony("local.taxadfaces");
			int num = 0;
			DisplayTarget[] all = DisplayTargets.All;
			foreach (DisplayTarget displayTarget in all)
			{
				string typeName = displayTarget.TypeName;
				Type type = AccessTools.TypeByName(typeName);
				if (type == null)
				{
					((BaseUnityPlugin)this).Logger.LogWarning((object)("Game type missing: " + typeName));
					continue;
				}
				List<FieldInfo> list = new List<FieldInfo>();
				string[] members = displayTarget.Members;
				foreach (string name in members)
				{
					FieldInfo field = type.GetField(name, BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic);
					if (field != null)
					{
						list.Add(field);
					}
				}
				displayFields.Add(type, list.ToArray());
				string[] hooks = displayTarget.Hooks;
				foreach (string text in hooks)
				{
					MethodInfo methodInfo = AccessTools.DeclaredMethod(type, text, (Type[])null, (Type[])null);
					if (!(methodInfo == null))
					{
						harmony.Patch((MethodBase)methodInfo, (HarmonyMethod)null, new HarmonyMethod(typeof(TaxadFaces), "AfterContext", (Type[])null), (HarmonyMethod)null, (HarmonyMethod)null, (HarmonyMethod)null);
						num++;
					}
				}
			}
			SceneManager.sceneUnloaded += OnSceneUnloaded;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Taxad Faces loaded; " + num + " hooks. Generated satirical artwork."));
		}
		catch (Exception ex)
		{
			((BaseUnityPlugin)this).Logger.LogError((object)("Taxad Faces could not initialize: " + ex));
			enabledSetting.Value = false;
		}
	}

	private static void AfterContext(Component __instance)
	{
		if ((Object)(object)instance != (Object)null)
		{
			instance.BindContext(__instance);
		}
	}

	private void OnSceneUnloaded(Scene scene)
	{
		List<TMP_Text> list = new List<TMP_Text>();
		foreach (KeyValuePair<TMP_Text, TMP_SpriteAsset> original in originals)
		{
			if ((Object)(object)original.Key == (Object)null)
			{
				list.Add(original.Key);
			}
		}
		foreach (TMP_Text item in list)
		{
			originals.Remove(item);
		}
		List<Renderer> list2 = new List<Renderer>();
		foreach (KeyValuePair<Renderer, Material[]> originalRendererMaterial in originalRendererMaterials)
		{
			if ((Object)(object)originalRendererMaterial.Key == (Object)null)
			{
				list2.Add(originalRendererMaterial.Key);
			}
		}
		foreach (Renderer item2 in list2)
		{
			originalRendererMaterials.Remove(item2);
		}
	}

	private void BindContext(Component context)
	{
		//IL_00b5: Unknown result type (might be due to invalid IL or missing references)
		if (!enabledSetting.Value || (Object)(object)faces == (Object)null)
		{
			return;
		}
		Type type = ((object)context).GetType();
		string name = type.Name;
		if (name == "CosmeticShopMachine")
		{
			BindCosmeticIcon(context);
		}
		if (!displayFields.TryGetValue(type, out var value))
		{
			return;
		}
		FieldInfo[] array = value;
		foreach (FieldInfo fieldInfo in array)
		{
			object value2 = fieldInfo.GetValue(context);
			TMP_Text val = (TMP_Text)((value2 is TMP_Text) ? value2 : null);
			if ((Object)(object)val != (Object)null)
			{
				BindText(val, name);
			}
			else if (name == "ExtractionPoint" && fieldInfo.Name == "grossUp" && value2 is GameObject)
			{
				BindPortraitRenderer((Renderer)(object)((GameObject)value2).GetComponent<MeshRenderer>(), "Taxman Grossup Material", "ExtractionPoint/grossUp");
			}
			else
			{
				if (!(value2 is IEnumerable))
				{
					continue;
				}
				foreach (object item in (IEnumerable)value2)
				{
					BindText((TMP_Text)((item is TMP_Text) ? item : null), name);
				}
			}
		}
	}

	private void BindCosmeticIcon(Component context)
	{
		Transform val = context.transform.Find("Screen/Base Icon/Icon");
		if (!((Object)(object)val == (Object)null))
		{
			Renderer component = (Renderer)(object)((Component)val).GetComponent<MeshRenderer>();
			BindPortraitRenderer(component, "Cosmetic Shop Machine - Screen Icon - Taxman", "CosmeticShopMachine/Screen/Base Icon/Icon");
		}
	}

	private void BindPortraitRenderer(Renderer renderer, string materialPrefix, string contextName)
	{
		//IL_00ec: Unknown result type (might be due to invalid IL or missing references)
		//IL_00f3: Expected O, but got Unknown
		//IL_0127: Unknown result type (might be due to invalid IL or missing references)
		//IL_0133: Unknown result type (might be due to invalid IL or missing references)
		//IL_0077: Unknown result type (might be due to invalid IL or missing references)
		//IL_0081: Expected O, but got Unknown
		if ((Object)(object)renderer == (Object)null || originalRendererMaterials.ContainsKey(renderer))
		{
			return;
		}
		Material[] sharedMaterials = renderer.sharedMaterials;
		Material[] array = (Material[])sharedMaterials.Clone();
		bool flag = false;
		for (int i = 0; i < sharedMaterials.Length; i++)
		{
			Material val = sharedMaterials[i];
			if (!((Object)(object)val == (Object)null) && ((Object)val).name.StartsWith(materialPrefix, StringComparison.Ordinal))
			{
				if ((Object)(object)creepyFace == (Object)null)
				{
					creepyFace = new Texture2D(256, 256, (TextureFormat)4, false);
					owned.Add((Object)(object)creepyFace);
					((Object)creepyFace).name = "TaxadFaces_CreepyPortrait";
					((Texture)creepyFace).wrapMode = (TextureWrapMode)1;
					((Texture)creepyFace).filterMode = (FilterMode)1;
					WriteTile(creepyFace, 0, 0, 256, FaceCells["creepycrying"], 0);
					creepyFace.Apply(false, true);
				}
				Material val2 = new Material(val);
				owned.Add((Object)(object)val2);
				((Object)val2).name = "TaxadFaces_" + ((Object)val).name;
				val2.mainTexture = (Texture)(object)creepyFace;
				val2.mainTextureScale = Vector2.one;
				val2.mainTextureOffset = Vector2.zero;
				array[i] = val2;
				flag = true;
			}
		}
		if (flag)
		{
			originalRendererMaterials.Add(renderer, sharedMaterials);
			renderer.sharedMaterials = array;
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Attached Taxad creepycrying portrait to " + contextName + "."));
		}
	}

	private void BindText(TMP_Text text, string contextName)
	{
		if ((Object)(object)text == (Object)null)
		{
			return;
		}
		TMP_SpriteAsset spriteAsset = text.spriteAsset;
		TMP_SpriteAsset val = (((Object)(object)spriteAsset != (Object)null) ? spriteAsset : TMP_Settings.defaultSpriteAsset);
		if ((Object)(object)val == (Object)null || ((Object)val).name.StartsWith("TaxadFaces_", StringComparison.Ordinal))
		{
			return;
		}
		int instanceID = ((Object)val).GetInstanceID();
		if (failures.Contains(instanceID))
		{
			return;
		}
		if (!clones.TryGetValue(instanceID, out var value))
		{
			try
			{
				value = BuildAtlas(val);
				clones.Add(instanceID, value);
			}
			catch (Exception ex)
			{
				failures.Add(instanceID);
				((BaseUnityPlugin)this).Logger.LogError((object)("Cannot replace sprite asset " + ((Object)val).name + ": " + ex));
				return;
			}
		}
		if (!((Object)(object)value == (Object)(object)val))
		{
			if (!originals.ContainsKey(text))
			{
				originals.Add(text, spriteAsset);
			}
			text.spriteAsset = value;
			((Graphic)text).SetAllDirty();
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Attached replacement to " + contextName + "/" + ((Object)text).name + " using " + ((Object)val).name + "."));
		}
	}

	private TMP_SpriteAsset BuildAtlas(TMP_SpriteAsset source)
	{
		//IL_00b6: Unknown result type (might be due to invalid IL or missing references)
		//IL_00bd: Expected O, but got Unknown
		//IL_0147: Unknown result type (might be due to invalid IL or missing references)
		//IL_01bb: Unknown result type (might be due to invalid IL or missing references)
		//IL_01c5: Expected O, but got Unknown
		//IL_03c8: Unknown result type (might be due to invalid IL or missing references)
		//IL_03cf: Expected O, but got Unknown
		//IL_036b: Unknown result type (might be due to invalid IL or missing references)
		//IL_0372: Expected O, but got Unknown
		//IL_0510: Unknown result type (might be due to invalid IL or missing references)
		if ((Object)(object)source.spriteSheet == (Object)null)
		{
			return source;
		}
		int num = 0;
		foreach (TMP_SpriteCharacter item in source.spriteCharacterTable)
		{
			if (FaceCells.ContainsKey(item.name))
			{
				num++;
			}
		}
		if (num < 5)
		{
			return source;
		}
		Texture spriteSheet = source.spriteSheet;
		int num2 = Mathf.NextPowerOfTwo(spriteSheet.width + 896);
		int num3 = Mathf.NextPowerOfTwo(Mathf.Max(spriteSheet.height, 1280));
		if (num2 > SystemInfo.maxTextureSize || num3 > SystemInfo.maxTextureSize)
		{
			throw new InvalidOperationException("Atlas exceeds GPU texture limit");
		}
		Texture2D val = new Texture2D(num2, num3, (TextureFormat)4, false);
		owned.Add((Object)(object)val);
		((Object)val).name = "TaxadFaces_" + ((Object)source).name;
		((Texture)val).filterMode = (FilterMode)1;
		((Texture)val).wrapMode = (TextureWrapMode)1;
		val.SetPixels32((Color32[])(object)new Color32[num2 * num3]);
		RenderTexture active = RenderTexture.active;
		RenderTexture temporary = RenderTexture.GetTemporary(spriteSheet.width, spriteSheet.height, 0, (RenderTextureFormat)0, (RenderTextureReadWrite)0);
		try
		{
			Graphics.Blit(spriteSheet, temporary);
			RenderTexture.active = temporary;
			val.ReadPixels(new Rect(0f, 0f, (float)spriteSheet.width, (float)spriteSheet.height), 0, 0, false);
		}
		finally
		{
			RenderTexture.active = active;
			RenderTexture.ReleaseTemporary(temporary);
		}
		TMP_SpriteAsset clone = Object.Instantiate<TMP_SpriteAsset>(source);
		owned.Add((Object)(object)clone);
		((Object)clone).name = "TaxadFaces_" + ((Object)source).name;
		clone.spriteSheet = (Texture)(object)val;
		((TMP_Asset)clone).material = new Material(((TMP_Asset)source).material);
		owned.Add((Object)(object)((TMP_Asset)clone).material);
		int num4 = AtlasTextureSlots.Rebind(((TMP_Asset)clone).material.GetTexturePropertyNames(), (string property) => ((TMP_Asset)clone).material.GetTexture(property), spriteSheet, (Texture)(object)val, delegate(string property, Texture texture)
		{
			((TMP_Asset)clone).material.SetTexture(property, texture);
		});
		if (num4 == 0)
		{
			throw new InvalidOperationException("No shader texture property references the sprite sheet: " + ((Object)source).name);
		}
		if (((TMP_Asset)clone).material.HasProperty("_TextureWidth"))
		{
			((TMP_Asset)clone).material.SetFloat("_TextureWidth", (float)num2);
		}
		if (((TMP_Asset)clone).material.HasProperty("_TextureHeight"))
		{
			((TMP_Asset)clone).material.SetFloat("_TextureHeight", (float)num3);
		}
		List<TMP_SpriteGlyph> copies;
		int duplicates;
		Dictionary<uint, TMP_SpriteGlyph> dictionary = GlyphIndex.CopyFirst<TMP_SpriteGlyph>(source.spriteGlyphTable, (TMP_SpriteGlyph g) => ((Glyph)g).index, (TMP_SpriteGlyph g) => new TMP_SpriteGlyph(((Glyph)g).index, ((Glyph)g).metrics, ((Glyph)g).glyphRect, ((Glyph)g).scale, ((Glyph)g).atlasIndex), out copies, out duplicates);
		if (duplicates > 0)
		{
			((BaseUnityPlugin)this).Logger.LogInfo((object)("Preserved " + duplicates + " duplicate glyph IDs in " + ((Object)source).name + "; first entry wins, matching TextMeshPro."));
		}
		List<TMP_SpriteCharacter> list = new List<TMP_SpriteCharacter>();
		int num5 = 0;
		HashSet<uint> hashSet = new HashSet<uint>();
		foreach (TMP_SpriteCharacter item2 in source.spriteCharacterTable)
		{
			if (item2 == null)
			{
				continue;
			}
			if (!dictionary.TryGetValue(((TMP_TextElement)item2).glyphIndex, out var value))
			{
				TMP_SpriteCharacter val2 = new TMP_SpriteCharacter();
				((TMP_TextElement)val2).unicode = ((TMP_TextElement)item2).unicode;
				((TMP_TextElement)val2).glyphIndex = ((TMP_TextElement)item2).glyphIndex;
				val2.name = item2.name;
				((TMP_TextElement)val2).scale = ((TMP_TextElement)item2).scale;
				list.Add(val2);
				continue;
			}
			TMP_SpriteCharacter val3 = new TMP_SpriteCharacter(((TMP_TextElement)item2).unicode, clone, value);
			val3.name = item2.name;
			((TMP_TextElement)val3).scale = ((TMP_TextElement)item2).scale;
			list.Add(val3);
			int part = 0;
			int value2;
			bool flag = FaceCells.TryGetValue(item2.name, out value2);
			if (!flag && featuresSetting.Value)
			{
				flag = EyeCells.TryGetValue(item2.name, out value2);
				if (flag)
				{
					part = 1;
				}
			}
			if (!flag && featuresSetting.Value)
			{
				flag = MouthCells.TryGetValue(item2.name, out value2);
				if (flag)
				{
					part = 2;
				}
			}
			if (!flag && handsSetting.Value && (Object)(object)hands != (Object)null)
			{
				flag = HandCells.TryGetValue(item2.name, out value2);
				if (flag)
				{
					part = 3;
				}
			}
			if (flag && hashSet.Add(((Glyph)value).index))
			{
				int num6 = spriteSheet.width + num5 % 7 * 128;
				int num7 = num5 / 7 * 128;
				if (num7 + 128 > num3)
				{
					throw new InvalidOperationException("Too many replacement glyphs");
				}
				WriteTile(val, num6, num7, 128, value2, part);
				((Glyph)value).glyphRect = new GlyphRect(num6, num7, 128, 128);
				num5++;
			}
		}
		FieldInfo fieldInfo = AccessTools.Field(typeof(TMP_SpriteAsset), "m_GlyphTable") ?? AccessTools.Field(typeof(TMP_SpriteAsset), "m_SpriteGlyphTable");
		if (fieldInfo == null)
		{
			throw new MissingFieldException("TMP sprite glyph table");
		}
		fieldInfo.SetValue(clone, copies);
		AccessTools.Field(typeof(TMP_SpriteAsset), "m_SpriteCharacterTable").SetValue(clone, list);
		clone.UpdateLookupTables();
		val.Apply(false, true);
		((BaseUnityPlugin)this).Logger.LogInfo((object)("Patched " + num5 + " face/feature/hand sprites in " + ((Object)source).name + "; rebound " + num4 + " atlas texture properties."));
		return clone;
	}

	private void WriteTile(Texture2D atlas, int x, int y, int size, int cell, int part)
	{
		//IL_00bb: 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)
		//IL_00a0: Unknown result type (might be due to invalid IL or missing references)
		//IL_0085: Unknown result type (might be due to invalid IL or missing references)
		//IL_012d: Unknown result type (might be due to invalid IL or missing references)
		//IL_0132: Unknown result type (might be due to invalid IL or missing references)
		//IL_0197: Unknown result type (might be due to invalid IL or missing references)
		//IL_0199: Unknown result type (might be due to invalid IL or missing references)
		bool flag = part == 3 && cell >= 14;
		int num = (flag ? 2 : ((part == 3) ? 4 : 7));
		int num2 = (flag ? 1 : num);
		Texture2D val = ((part == 3) ? hands : faces);
		if (flag)
		{
			val = boxHands;
			cell -= 14;
		}
		float num3 = (float)(cell % num) / (float)num;
		float num4 = (float)(num2 - 1 - cell / num) / (float)num2;
		Rect val2 = (Rect)(part switch
		{
			2 => new Rect(0.28f, 0.09f, 0.47f, 0.28f), 
			1 => new Rect(0.23f, 0.43f, 0.29f, 0.25f), 
			_ => new Rect(0f, 0f, 1f, 1f), 
		});
		Color[] array = (Color[])(object)new Color[size * size];
		for (int i = 0; i < size; i++)
		{
			for (int j = 0; j < size; j++)
			{
				float num5 = ((float)j + 0.5f) / (float)size;
				float num6 = ((float)i + 0.5f) / (float)size;
				Color pixelBilinear = val.GetPixelBilinear(num3 + (((Rect)(ref val2)).x + num5 * ((Rect)(ref val2)).width) / (float)num, num4 + (((Rect)(ref val2)).y + num6 * ((Rect)(ref val2)).height) / (float)num2);
				if (part == 1 || part == 2)
				{
					float num7 = (num5 - 0.5f) * 2f;
					float num8 = (num6 - 0.5f) * 2f;
					pixelBilinear.a *= Mathf.Clamp01((1f - num7 * num7 - num8 * num8) * 10f);
				}
				array[i * size + j] = pixelBilinear;
			}
		}
		atlas.SetPixels(x, y, size, size, array);
	}

	private void OnDestroy()
	{
		SceneManager.sceneUnloaded -= OnSceneUnloaded;
		if (harmony != null)
		{
			harmony.UnpatchSelf();
		}
		foreach (KeyValuePair<TMP_Text, TMP_SpriteAsset> original in originals)
		{
			if ((Object)(object)original.Key != (Object)null)
			{
				original.Key.spriteAsset = original.Value;
				((Graphic)original.Key).SetAllDirty();
			}
		}
		foreach (KeyValuePair<Renderer, Material[]> originalRendererMaterial in originalRendererMaterials)
		{
			if ((Object)(object)originalRendererMaterial.Key != (Object)null)
			{
				originalRendererMaterial.Key.sharedMaterials = originalRendererMaterial.Value;
			}
		}
		for (int num = owned.Count - 1; num >= 0; num--)
		{
			if (owned[num] != (Object)null)
			{
				Object.Destroy(owned[num]);
			}
		}
		if ((Object)(object)instance == (Object)(object)this)
		{
			instance = null;
		}
	}
}
internal static class GlyphIndex
{
	internal static Dictionary<uint, T> CopyFirst<T>(IEnumerable<T> source, Func<T, uint> getIndex, Func<T, T> copyGlyph, out List<T> copies, out int duplicates)
	{
		copies = new List<T>();
		Dictionary<uint, T> dictionary = new Dictionary<uint, T>();
		duplicates = 0;
		foreach (T item in source)
		{
			T val = copyGlyph(item);
			copies.Add(val);
			uint key = getIndex(val);
			if (dictionary.ContainsKey(key))
			{
				duplicates++;
			}
			else
			{
				dictionary.Add(key, val);
			}
		}
		return dictionary;
	}
}
internal sealed class DisplayTarget
{
	internal readonly string TypeName;

	internal readonly string[] Hooks;

	internal readonly string[] Members;

	internal DisplayTarget(string typeName, string[] hooks, params string[] members)
	{
		TypeName = typeName;
		Hooks = hooks;
		Members = members;
	}
}
internal static class DisplayTargets
{
	internal static readonly DisplayTarget[] All = new DisplayTarget[5]
	{
		new DisplayTarget("TruckScreenText", new string[2] { "Awake", "Start" }, "chatMessage", "textMesh"),
		new DisplayTarget("ShopKeeper", new string[3] { "Awake", "Start", "DisplayEmoji" }, "textMesh"),
		new DisplayTarget("ExtractionPoint", new string[2] { "Start", "SetEmojiScreen" }, "emojiScreen", "grossUp"),
		new DisplayTarget("CosmeticShopMachine", new string[1] { "Awake" }, "screenBaseIconTransform", "screenCosmeticTexts", "screenCosmeticTextsNew"),
		new DisplayTarget("CosmeticShopMachineAnimator", new string[1] { "Awake" })
	};
}
internal static class AtlasTextureSlots
{
	internal static int Rebind<T>(IEnumerable<string> properties, Func<string, T> get, T original, T replacement, Action<string, T> set) where T : class
	{
		int num = 0;
		foreach (string property in properties)
		{
			if (EqualityComparer<T>.Default.Equals(get(property), original))
			{
				set(property, replacement);
				num++;
			}
		}
		return num;
	}
}