Please disclose if any significant portion of your mod was created using AI tools by adding the 'AI Generated' category. Failing to do so may result in the mod being removed from Thunderstore.
Decompiled source of SteamGlyphs v1.1.0
plugins/DeckGlyphs.dll
Decompiled a month agousing System; using System.Collections; using System.Collections.Generic; using System.IO; using System.Reflection; using System.Runtime.CompilerServices; using BepInEx; using BepInEx.Logging; using TMPro; using UnityEngine; using UnityEngine.TextCore; [assembly: RuntimeCompatibility(WrapNonExceptionThrows = true)] [assembly: AssemblyVersion("0.0.0.0")] namespace DeckGlyphs; [BepInPlugin("com.FluxSquido.deckglyphs", "SteamGlyphs", "1.1.0")] public class DeckGlyphsPlugin : BaseUnityPlugin { public const string GUID = "com.FluxSquido.deckglyphs"; public const string NAME = "SteamGlyphs"; public const string VERSION = "1.1.0"; private const string TargetSpriteAsset = "tmpsprXboxOneGlyphs"; private static readonly Dictionary<string, float> BumperRotation = new Dictionary<string, float>(StringComparer.OrdinalIgnoreCase) { { "texXBoxOneGlyphs_2", -20.4f }, { "texXBoxOneGlyphs_6", 20.4f } }; internal static ManualLogSource Log; private readonly Dictionary<string, Texture2D> _deckByGlyphName = new Dictionary<string, Texture2D>(StringComparer.OrdinalIgnoreCase); private bool _patched; private bool _uprightBumpers; private void Awake() { Log = ((BaseUnityPlugin)this).Logger; _uprightBumpers = ((BaseUnityPlugin)this).Config.Bind<bool>("Tweaks", "Upright Bumpers", false, "Rotate both R1 and L1 to be more upright").Value; LoadDeckTextures(); if (_deckByGlyphName.Count == 0) { Log.LogError((object)"No Deck glyphs loaded; check the glyphs/ folder and glyph_map.json."); } else { ((MonoBehaviour)this).StartCoroutine(PatchWhenReady()); } } private void LoadDeckTextures() { //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c9: Expected O, but got Unknown string directoryName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location); string text = Path.Combine(directoryName, "glyphs"); string path = Path.Combine(directoryName, "glyph_map.json"); if (!Directory.Exists(text) || !File.Exists(path)) { Log.LogError((object)"Missing glyphs/ folder or glyph_map.json next to the DLL."); return; } foreach (KeyValuePair<string, string> item in ReadFlatJson(File.ReadAllText(path))) { if (!item.Key.StartsWith("_")) { string text2 = Path.Combine(text, item.Value); if (!File.Exists(text2)) { Log.LogWarning((object)("Glyph png not found: " + text2)); continue; } Texture2D val = new Texture2D(2, 2, (TextureFormat)4, false); ImageConversion.LoadImage(val, File.ReadAllBytes(text2)); ((Texture)val).wrapMode = (TextureWrapMode)1; _deckByGlyphName[item.Key] = val; } } Log.LogInfo((object)("Loaded " + _deckByGlyphName.Count + " Deck glyph textures.")); } private IEnumerator PatchWhenReady() { float deadline = Time.realtimeSinceStartup + 120f; while (!_patched && Time.realtimeSinceStartup < deadline) { if (TryPatch()) { yield break; } yield return (object)new WaitForSeconds(0.5f); } if (!_patched) { Log.LogWarning((object)"Gave up: 'tmpsprXboxOneGlyphs' sprite asset never appeared."); } } private bool TryPatch() { bool flag = false; TMP_SpriteAsset[] array = Resources.FindObjectsOfTypeAll<TMP_SpriteAsset>(); foreach (TMP_SpriteAsset val in array) { if (!((Object)(object)val == (Object)null) && !(((Object)val).name != "tmpsprXboxOneGlyphs")) { try { RepaintAtlas(val); flag = true; } catch (Exception ex) { Log.LogError((object)("Failed to repaint " + ((Object)val).name + ": " + ex)); } } } if (flag) { _patched = true; Log.LogInfo((object)"Deck glyphs applied."); } return flag; } private void RepaintAtlas(TMP_SpriteAsset sa) { //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_0051: Expected O, but got Unknown //IL_00fd: Unknown result type (might be due to invalid IL or missing references) //IL_00eb: Unknown result type (might be due to invalid IL or missing references) //IL_0102: Unknown result type (might be due to invalid IL or missing references) Texture spriteSheet = sa.spriteSheet; Texture2D val = (Texture2D)(object)((spriteSheet is Texture2D) ? spriteSheet : null); int num = ((!((Object)(object)val != (Object)null)) ? 1024 : ((Texture)val).width); int num2 = ((!((Object)(object)val != (Object)null)) ? 1024 : ((Texture)val).height); Texture2D val2 = new Texture2D(num, num2, (TextureFormat)4, false); ((Texture)val2).wrapMode = (TextureWrapMode)1; ((Texture)val2).filterMode = (FilterMode)1; Texture2D val3 = val2; val3.SetPixels32((Color32[])(object)new Color32[num * num2]); int num3 = 0; List<TMP_SpriteCharacter> spriteCharacterTable = sa.spriteCharacterTable; for (int i = 0; i < spriteCharacterTable.Count; i++) { TMP_SpriteCharacter val4 = spriteCharacterTable[i]; if (val4 == null || string.IsNullOrEmpty(val4.name) || !_deckByGlyphName.TryGetValue(val4.name, out var value) || (Object)(object)value == (Object)null) { continue; } GlyphRect val5 = ((((TMP_TextElement)val4).glyph == null) ? FindRect(sa, ((TMP_TextElement)val4).glyphIndex) : ((TMP_TextElement)val4).glyph.glyphRect); if (((GlyphRect)(ref val5)).width > 0 && ((GlyphRect)(ref val5)).height > 0 && ((GlyphRect)(ref val5)).x >= 0 && ((GlyphRect)(ref val5)).y >= 0 && ((GlyphRect)(ref val5)).x + ((GlyphRect)(ref val5)).width <= num && ((GlyphRect)(ref val5)).y + ((GlyphRect)(ref val5)).height <= num2) { Color[] sp = value.GetPixels(); if (_uprightBumpers && BumperRotation.TryGetValue(val4.name, out var value2)) { sp = Rotate(sp, ((Texture)value).width, ((Texture)value).height, value2); } val3.SetPixels32(((GlyphRect)(ref val5)).x, ((GlyphRect)(ref val5)).y, ((GlyphRect)(ref val5)).width, ((GlyphRect)(ref val5)).height, Resample(sp, ((Texture)value).width, ((Texture)value).height, ((GlyphRect)(ref val5)).width, ((GlyphRect)(ref val5)).height)); num3++; } } val3.Apply(false, false); sa.spriteSheet = (Texture)(object)val3; Material material = ((TMP_Asset)sa).material; if ((Object)(object)material != (Object)null) { material.mainTexture = (Texture)(object)val3; if (material.HasProperty("_MainTex")) { material.SetTexture("_MainTex", (Texture)(object)val3); } } Log.LogInfo((object)("Repainted " + num3 + " glyphs on " + ((Object)sa).name + " (" + num + "x" + num2 + ").")); } private static GlyphRect FindRect(TMP_SpriteAsset sa, uint glyphIndex) { //IL_004d: Unknown result type (might be due to invalid IL or missing references) //IL_0033: Unknown result type (might be due to invalid IL or missing references) List<TMP_SpriteGlyph> spriteGlyphTable = sa.spriteGlyphTable; for (int i = 0; i < spriteGlyphTable.Count; i++) { if (spriteGlyphTable[i] != null && ((Glyph)spriteGlyphTable[i]).index == glyphIndex) { return ((Glyph)spriteGlyphTable[i]).glyphRect; } } return new GlyphRect(0, 0, 0, 0); } private static Color[] Rotate(Color[] sp, int w, int h, float deg) { //IL_00c2: Unknown result type (might be due to invalid IL or missing references) //IL_00c7: Unknown result type (might be due to invalid IL or missing references) //IL_0114: Unknown result type (might be due to invalid IL or missing references) //IL_0126: 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_0141: Unknown result type (might be due to invalid IL or missing references) //IL_0153: Unknown result type (might be due to invalid IL or missing references) //IL_015a: Unknown result type (might be due to invalid IL or missing references) //IL_015f: Unknown result type (might be due to invalid IL or missing references) //IL_016e: Unknown result type (might be due to invalid IL or missing references) //IL_0170: Unknown result type (might be due to invalid IL or missing references) //IL_0174: Unknown result type (might be due to invalid IL or missing references) //IL_0179: Unknown result type (might be due to invalid IL or missing references) Color[] array = (Color[])(object)new Color[w * h]; float num = deg * ((float)Math.PI / 180f); float num2 = Mathf.Cos(num); float num3 = Mathf.Sin(num); float num4 = (float)(w - 1) * 0.5f; float num5 = (float)(h - 1) * 0.5f; for (int i = 0; i < h; i++) { float num6 = (float)i - num5; for (int j = 0; j < w; j++) { float num7 = (float)j - num4; float num8 = num4 + num2 * num7 + num3 * num6; float num9 = num5 - num3 * num7 + num2 * num6; if (num8 < 0f || num8 > (float)(w - 1) || num9 < 0f || num9 > (float)(h - 1)) { ref Color reference = ref array[i * w + j]; reference = new Color(0f, 0f, 0f, 0f); continue; } int num10 = (int)num8; int num11 = (int)num9; int num12 = Mathf.Min(num10 + 1, w - 1); int num13 = Mathf.Min(num11 + 1, h - 1); float num14 = num8 - (float)num10; float num15 = num9 - (float)num11; Color val = Color.Lerp(sp[num11 * w + num10], sp[num11 * w + num12], num14); Color val2 = Color.Lerp(sp[num13 * w + num10], sp[num13 * w + num12], num14); ref Color reference2 = ref array[i * w + j]; reference2 = Color.Lerp(val, val2, num15); } } return array; } private static Color32[] Resample(Color[] sp, int sw, int sh, int w, int h) { //IL_00a9: Unknown result type (might be due to invalid IL or missing references) //IL_00ba: Unknown result type (might be due to invalid IL or missing references) //IL_00c1: Unknown result type (might be due to invalid IL or missing references) //IL_00c6: Unknown result type (might be due to invalid IL or missing references) //IL_00d5: Unknown result type (might be due to invalid IL or missing references) //IL_00e7: Unknown result type (might be due to invalid IL or missing references) //IL_00ee: Unknown result type (might be due to invalid IL or missing references) //IL_00f3: Unknown result type (might be due to invalid IL or missing references) //IL_0101: Unknown result type (might be due to invalid IL or missing references) //IL_0103: Unknown result type (might be due to invalid IL or missing references) //IL_0107: Unknown result type (might be due to invalid IL or missing references) //IL_010c: Unknown result type (might be due to invalid IL or missing references) //IL_0111: Unknown result type (might be due to invalid IL or missing references) Color32[] array = (Color32[])(object)new Color32[w * h]; for (int i = 0; i < h; i++) { float num = ((float)i + 0.5f) * (float)sh / (float)h - 0.5f; int num2 = Mathf.Clamp(Mathf.FloorToInt(num), 0, sh - 1); int num3 = Mathf.Clamp(num2 + 1, 0, sh - 1); float num4 = Mathf.Clamp01(num - (float)num2); for (int j = 0; j < w; j++) { float num5 = ((float)j + 0.5f) * (float)sw / (float)w - 0.5f; int num6 = Mathf.Clamp(Mathf.FloorToInt(num5), 0, sw - 1); int num7 = Mathf.Clamp(num6 + 1, 0, sw - 1); float num8 = Mathf.Clamp01(num5 - (float)num6); Color val = Color.Lerp(sp[num2 * sw + num6], sp[num2 * sw + num7], num8); Color val2 = Color.Lerp(sp[num3 * sw + num6], sp[num3 * sw + num7], num8); ref Color32 reference = ref array[i * w + j]; reference = Color32.op_Implicit(Color.Lerp(val, val2, num4)); } } return array; } private static IEnumerable<KeyValuePair<string, string>> ReadFlatJson(string json) { List<KeyValuePair<string, string>> list = new List<KeyValuePair<string, string>>(); int startIndex = 0; while (true) { int num = json.IndexOf('"', startIndex); if (num < 0) { break; } int num2 = json.IndexOf('"', num + 1); if (num2 < 0) { break; } string key = json.Substring(num + 1, num2 - num - 1); int num3 = json.IndexOf(':', num2); if (num3 < 0) { break; } int num4 = json.IndexOf('\n', num2); int num5 = json.IndexOf('"', num3); if (num5 < 0) { break; } if (num4 >= 0 && num5 > num4) { startIndex = num2 + 1; continue; } int num6 = json.IndexOf('"', num5 + 1); if (num6 < 0) { break; } list.Add(new KeyValuePair<string, string>(key, json.Substring(num5 + 1, num6 - num5 - 1))); startIndex = num6 + 1; } return list; } }