using System; using System.Collections.Generic; using System.Diagnostics; using System.IO; using System.Linq; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.Versioning; using System.Text; using System.Text.RegularExpressions; using System.Threading.Tasks; using BepInEx; using BepInEx.Logging; using Microsoft.CodeAnalysis; using NukeLib.Text; using UnityEngine; using UnityEngine.Networking; 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("NukeLib")] [assembly: AssemblyConfiguration("Release")] [assembly: AssemblyFileVersion("1.0.0.0")] [assembly: AssemblyInformationalVersion("1.0.0+957162b8aa087d5dea0f599cc14f3ff21fc63b2f")] [assembly: AssemblyProduct("NukeLib")] [assembly: AssemblyTitle("NukeLib")] [assembly: AssemblyVersion("1.0.0.0")] [module: RefSafetyRules(11)] namespace Microsoft.CodeAnalysis { [CompilerGenerated] [Embedded] internal sealed class EmbeddedAttribute : Attribute { } } namespace System.Runtime.CompilerServices { [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Property | AttributeTargets.Field | AttributeTargets.Event | AttributeTargets.Parameter | AttributeTargets.ReturnValue | AttributeTargets.GenericParameter, AllowMultiple = false, Inherited = false)] internal sealed class NullableAttribute : Attribute { public readonly byte[] NullableFlags; public NullableAttribute(byte P_0) { NullableFlags = new byte[1] { P_0 }; } public NullableAttribute(byte[] P_0) { NullableFlags = P_0; } } [CompilerGenerated] [Embedded] [AttributeUsage(AttributeTargets.Class | AttributeTargets.Struct | AttributeTargets.Method | AttributeTargets.Interface | AttributeTargets.Delegate, AllowMultiple = false, Inherited = false)] internal sealed class NullableContextAttribute : Attribute { public readonly byte Flag; public NullableContextAttribute(byte P_0) { Flag = P_0; } } [CompilerGenerated] [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 NukeLib { [BepInPlugin("com.github.end-4.nukeLib", "NukeLib", "0.5.0")] public class Plugin : BaseUnityPlugin { internal static ManualLogSource Log; public static string workingPath = Assembly.GetExecutingAssembly().Location; public static string workingDir = Path.GetDirectoryName(workingPath); public const string PluginGUID = "com.github.end-4.nukeLib"; public const string PluginName = "NukeLib"; public const string PluginVersion = "0.5.0"; private void Awake() { Log = ((BaseUnityPlugin)this).Logger; } } } namespace NukeLib.UI { public class EnemyIconController : MonoBehaviour { public enum IconStyle { Simple, Vanilla } private static bool iconsLoaded = false; private static bool vanillaIconsLoaded = false; private static readonly string BundlePath = Path.Combine(Plugin.workingDir, "assets", "nukelib_enemies.bundle"); private static string DEFAULT_ICON = "default"; public IconStyle style; private static string[] IconNames = new string[41] { "default", "big_johninator", "cancerous_rodent", "centaur_mortar", "centaur_orb", "centaur_rocket", "cerberus", "deathcatcher", "drone", "ferryman", "filth", "flesh_panopticon", "flesh_prison", "gabriel", "gabriel_second", "gutterman", "guttertank", "hideous_mass", "idol", "malicious_face", "mandalore", "mindflayer", "minos_prime", "minotaur", "mirror_reaper", "power", "providence", "puppet", "schism", "sisyphus", "sisyphus_prime", "soldier", "stalker", "stray", "mannequin", "streetcleaner", "swordsmachine", "turret", "v2", "very_cancerous_rodent", "virtue" }; private static Dictionary EnemyIcons = new Dictionary(); private static IEnumerable vanillaEnemies; public EnemyIdentifier enemyIdentifier; private static void LoadSimpleIcons() { AssetBundle val = AssetBundle.LoadFromFile(BundlePath); for (int i = 0; i < IconNames.Length; i++) { string text = IconNames[i]; Sprite value = val.LoadAsset(text); EnemyIcons.Add(text, value); } val.Unload(false); } private static void LoadVanillaIcons() { vanillaEnemies = Resources.FindObjectsOfTypeAll().SelectMany((SpawnableObjectsDatabase db) => db.enemies); } private void Awake() { if (style == IconStyle.Simple && !iconsLoaded) { LoadSimpleIcons(); iconsLoaded = true; } else if (style == IconStyle.Vanilla && !vanillaIconsLoaded) { LoadVanillaIcons(); vanillaIconsLoaded = vanillaEnemies.Count() > 0; } } private void Start() { SetEnemyIcon(enemyIdentifier); } private void SetEnemyIcon(EnemyIdentifier enemyIdentifier) { if (style == IconStyle.Vanilla) { ((Component)this).gameObject.GetComponent().sprite = vanillaEnemies.FirstOrDefault((Func)delegate(SpawnableObject spawnable) { EnemyIdentifier componentInChildren = spawnable.gameObject.GetComponentInChildren(true); return ((componentInChildren != null) ? componentInChildren.FullName : null) == enemyIdentifier.FullName; })?.gridIcon; return; } string? input = ((object)Unsafe.As(ref enemyIdentifier.enemyType)/*cast due to .constrained prefix*/).ToString(); string key = DEFAULT_ICON; string text = input.ToSnakeCase(); if (EnemyIcons.ContainsKey(text)) { key = text; } else { switch (enemyIdentifier.FullName.ToLower()) { case "earthmover mortar": text = "centaur_mortar"; break; case "earthmover rocket launcher": text = "centaur_rocket"; break; case "earthmover tower": text = "centaur_orb"; break; case "cancerous rodent": text = "cancerous_rodent"; break; case "very cancerous rodent": text = "very_cancerous_rodent"; break; case "big johninator": text = "big_johninator"; break; } if (EnemyIcons.ContainsKey(text)) { key = text; } } if (EnemyIcons.TryGetValue(key, out Sprite value)) { ((Component)this).gameObject.GetComponent().sprite = value; } } } public class SlideFadeToggleEffect : MonoBehaviour { private enum State { Idle, Entering, Exiting } private State currentState; private RectTransform rect; private CanvasGroup? canvasGroup; private float originalAlpha; private Vector2 originalPos; public float hiddenAlpha; public float speed = 18f; public Vector2 hiddenOffset = Vector2.zero; private float currentExitSpeed; private Vector2 hiddenPos => originalPos + hiddenOffset; public event Action OnExitComplete; private void Set2DLocalPosition(Vector2 newPos) { //IL_0006: 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_0018: Unknown result type (might be due to invalid IL or missing references) //IL_0022: Unknown result type (might be due to invalid IL or missing references) ((Transform)rect).localPosition = new Vector3(newPos.x, newPos.y, ((Transform)rect).localPosition.z); } private void Initialize() { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Expected O, but got Unknown //IL_0025: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0066: Unknown result type (might be due to invalid IL or missing references) //IL_006b: Unknown result type (might be due to invalid IL or missing references) if ((Object)rect == (Object)null) { rect = ((Component)this).GetComponent(); } if ((Object)canvasGroup == (Object)null) { canvasGroup = ((Component)this).GetComponent(); } CanvasGroup? obj = canvasGroup; originalAlpha = ((obj != null) ? obj.alpha : 1f); originalPos = Vector2.op_Implicit(((Transform)rect).localPosition); } private void OnEnable() { //IL_0002: Unknown result type (might be due to invalid IL or missing references) Set2DLocalPosition(hiddenPos); if ((Object)(object)canvasGroup != (Object)null) { canvasGroup.alpha = hiddenAlpha; } currentState = State.Entering; } public void StartExit() { currentState = State.Exiting; } private void Awake() { Initialize(); } private void Update() { //IL_001e: Unknown result type (might be due to invalid IL or missing references) //IL_0016: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_006e: Unknown result type (might be due to invalid IL or missing references) //IL_006f: Unknown result type (might be due to invalid IL or missing references) //IL_00d6: Unknown result type (might be due to invalid IL or missing references) //IL_00d7: Unknown result type (might be due to invalid IL or missing references) //IL_00da: 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) //IL_0116: Unknown result type (might be due to invalid IL or missing references) if (currentState == State.Idle) { return; } bool num = currentState == State.Entering; Vector2 val = (num ? originalPos : hiddenPos); float num2 = (num ? originalAlpha : hiddenAlpha); Vector2 val2 = Vector2.op_Implicit(((Transform)rect).localPosition); CanvasGroup? obj = canvasGroup; float num3 = ((obj != null) ? obj.alpha : 1f); float num5; float num6; if (num) { float num4 = Time.unscaledDeltaTime * speed; num5 = (Vector2.Distance(val2, val) + 0.1f) * num4; num6 = (Mathf.Abs(num2 - num3) + 0.1f) * num4; currentExitSpeed = 0f; } else { currentExitSpeed += speed * 7f * Time.unscaledDeltaTime; num5 = currentExitSpeed; num6 = currentExitSpeed * 0.01f; } Set2DLocalPosition(Vector2.MoveTowards(val2, val, num5)); if ((Object)(object)canvasGroup != (Object)null) { canvasGroup.alpha = Mathf.MoveTowards(num3, num2, num6); } if (Vector2.op_Implicit(((Transform)rect).localPosition) == val && ((Object)(object)canvasGroup == (Object)null || Mathf.Approximately(canvasGroup.alpha, num2))) { State num7 = currentState; currentState = State.Idle; currentExitSpeed = 0f; if (num7 == State.Exiting) { this.OnExitComplete?.Invoke(); } } } } public static class SlideFadeToggleEffectExtensions { public static void SetActiveAnimated(this GameObject gameObject, bool value, Vector2 hiddenOffset, float speed = 25f) { //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0030: Unknown result type (might be due to invalid IL or missing references) SlideFadeToggleEffect slideFadeToggleEffect = gameObject.GetComponent(); if ((Object)(object)slideFadeToggleEffect == (Object)null) { slideFadeToggleEffect = gameObject.AddComponent(); slideFadeToggleEffect.hiddenOffset = hiddenOffset; slideFadeToggleEffect.speed = speed; slideFadeToggleEffect.OnExitComplete += delegate { gameObject.SetActive(false); }; } if (!gameObject.activeSelf) { gameObject.SetActive(true); } else if ((Object)(object)slideFadeToggleEffect != (Object)null) { slideFadeToggleEffect.StartExit(); } else { gameObject.SetActive(false); } } } public static class UIUtils { public static GameObject FindRecursive(this GameObject baseObject, string path) { Transform val = baseObject.transform; string[] array = path.Split("/"); foreach (string text in array) { val = ((Component)val).transform.Find(text); if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)(text + " not found for object path " + ((Object)baseObject).name + "/" + path)); return null; } } return ((Component)val).gameObject; } public static GameObject FindRecursive(string path) { //IL_003c: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) int num = path.IndexOf('/'); string firstItem = ""; string path2 = ""; if (num != -1) { firstItem = path.Substring(0, num); path2 = path.Substring(num + 1); } Scene activeScene = SceneManager.GetActiveScene(); GameObject val = (from obj in ((Scene)(ref activeScene)).GetRootGameObjects() where ((Object)obj).name == firstItem select obj).FirstOrDefault(); if ((Object)(object)val == (Object)null) { Plugin.Log.LogWarning((object)("Root item not found for object path " + path)); return null; } return val.FindRecursive(path2); } public static void UnfuckLayoutHack(this GameObject uiObject) { //IL_0006: Unknown result type (might be due to invalid IL or missing references) //IL_0010: Expected O, but got Unknown LayoutRebuilder.ForceRebuildLayoutImmediate((RectTransform)uiObject.transform); } } } namespace NukeLib.Text { public static class TextUtils { public static string ToSnakeCase(this string input) { if (string.IsNullOrEmpty(input)) { return input; } return Regex.Replace(input, "(? lineLength) { if (stringBuilder2.Length == 0) { stringBuilder.AppendLine(text2); continue; } stringBuilder.AppendLine(stringBuilder2.ToString().TrimEnd()); stringBuilder2.Clear(); stringBuilder2.Append(text2).Append(" "); } else { stringBuilder2.Append(text2).Append(" "); } } if (stringBuilder2.Length > 0) { stringBuilder.Append(stringBuilder2.ToString().TrimEnd()); } return stringBuilder.ToString(); } } } namespace NukeLib.Reflection { public static class ReflectionUtils { public static T GetPrivate(this object obj, string fieldName) { Type type = obj.GetType(); BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic; FieldInfo? field = type.GetField(fieldName, bindingAttr); if (field == null) { throw new ArgumentException("Field '" + fieldName + "' doesn't exist in class " + type.Name); } return (T)field.GetValue(obj); } public static void SetPrivate(this object obj, string fieldName, T value) { Type type = obj.GetType(); BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic; FieldInfo? field = type.GetField(fieldName, bindingAttr); if (field == null) { throw new ArgumentException("Field '" + fieldName + "' doesn't exist in class " + type.Name); } field.SetValue(obj, value); } public static T InvokePrivate(this object obj, string methodName, params object[] parameters) { Type type = obj.GetType(); BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic; MethodInfo? method = type.GetMethod(methodName, bindingAttr); if (method == null) { throw new ArgumentException("Method '" + methodName + "' doesn't exist in class " + type.Name); } return (T)method.Invoke(obj, parameters); } public static void InvokePrivate(this object obj, string methodName, params object[] parameters) { Type type = obj.GetType(); BindingFlags bindingAttr = BindingFlags.Instance | BindingFlags.NonPublic; MethodInfo? method = type.GetMethod(methodName, bindingAttr); if (method == null) { throw new ArgumentException("Method '" + methodName + "' doesn't exist in class " + type.Name); } method.Invoke(obj, parameters); } } } namespace NukeLib.ImageUtils { public static class ColorUtils { public static float PerceivedLightness(this Color color) { //IL_0005: Unknown result type (might be due to invalid IL or missing references) //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_001e: Unknown result type (might be due to invalid IL or missing references) return 0.299f * color.r + 0.587f * color.g + 0.114f * color.b; } public static Color Transparentize(this Color color, float value = 1f) { //IL_0000: Unknown result type (might be due to invalid IL or missing references) //IL_0006: 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_0020: Unknown result type (might be due to invalid IL or missing references) return new Color(color.r, color.g, color.b, color.a * (1f - value)); } } public static class ImageUtils { private struct CacheItem { public string FilePath; public Color DominantColor; } private static readonly string[] SupportedExtensions = new string[3] { ".png", ".jpg", ".jpeg" }; private static int _maxCacheSize = 1000; private static readonly Dictionary> _cacheDict = new Dictionary>(); private static readonly LinkedList _lruList = new LinkedList(); public static int MaxCacheSize { get { return _maxCacheSize; } set { _maxCacheSize = Mathf.Max(0, value); TrimCache(); } } public static void ClearCache() { _cacheDict.Clear(); _lruList.Clear(); } private static void TrimCache() { while (_cacheDict.Count > _maxCacheSize) { LinkedListNode last = _lruList.Last; if (last != null) { _cacheDict.Remove(last.Value.FilePath); _lruList.RemoveLast(); } } } private static bool TryGetFromCache(string filePath, out Color color) { //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0046: Unknown result type (might be due to invalid IL or missing references) //IL_0034: Unknown result type (might be due to invalid IL or missing references) //IL_0039: Unknown result type (might be due to invalid IL or missing references) if (_maxCacheSize > 0 && _cacheDict.TryGetValue(filePath, out LinkedListNode value)) { _lruList.Remove(value); _lruList.AddFirst(value); color = value.Value.DominantColor; return true; } color = Color.black; return false; } private static void AddToCache(string filePath, Color color) { //IL_0060: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0042: Unknown result type (might be due to invalid IL or missing references) if (_maxCacheSize > 0) { if (_cacheDict.TryGetValue(filePath, out LinkedListNode value)) { _lruList.Remove(value); _lruList.AddFirst(value); value.Value = new CacheItem { FilePath = filePath, DominantColor = color }; } else { LinkedListNode linkedListNode = new LinkedListNode(new CacheItem { FilePath = filePath, DominantColor = color }); _lruList.AddFirst(linkedListNode); _cacheDict[filePath] = linkedListNode; TrimCache(); } } } public static Color GetDominantColor(Texture2D sourceTexture) { //IL_001b: Unknown result type (might be due to invalid IL or missing references) //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_0035: Unknown result type (might be due to invalid IL or missing references) //IL_0041: Unknown result type (might be due to invalid IL or missing references) //IL_0047: Unknown result type (might be due to invalid IL or missing references) //IL_004a: Unknown result type (might be due to invalid IL or missing references) //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0061: Expected O, but got Unknown //IL_0061: Unknown result type (might be due to invalid IL or missing references) RenderTexture temporary = RenderTexture.GetTemporary(1, 1, 0, (RenderTextureFormat)0); Graphics.Blit((Texture)(object)sourceTexture, temporary); RenderTexture.active = temporary; Texture2D val = new Texture2D(1, 1, (TextureFormat)4, false); val.ReadPixels(new Rect(0f, 0f, 1f, 1f), 0, 0); val.Apply(); Color pixel = val.GetPixel(0, 0); RenderTexture.active = null; RenderTexture.ReleaseTemporary(temporary); Object.Destroy((Object)val); return pixel; } public static Color GetDominantColor(string filePath) { //IL_000a: Unknown result type (might be due to invalid IL or missing references) //IL_0023: Unknown result type (might be due to invalid IL or missing references) //IL_0029: Expected O, but got Unknown //IL_0014: Unknown result type (might be due to invalid IL or missing references) //IL_003f: Unknown result type (might be due to invalid IL or missing references) //IL_0044: Unknown result type (might be due to invalid IL or missing references) //IL_004c: Unknown result type (might be due to invalid IL or missing references) //IL_0052: Unknown result type (might be due to invalid IL or missing references) //IL_0038: Unknown result type (might be due to invalid IL or missing references) if (TryGetFromCache(filePath, out var color)) { return color; } if (!File.Exists(filePath)) { return Color.black; } byte[] array = File.ReadAllBytes(filePath); Texture2D val = new Texture2D(2, 2); if (!ImageConversion.LoadImage(val, array)) { Object.Destroy((Object)(object)val); return Color.black; } Color dominantColor = GetDominantColor(val); Object.Destroy((Object)(object)val); AddToCache(filePath, dominantColor); return dominantColor; } public static string FindClosestColorImage(Color targetColor, string directoryPath) { //IL_004f: Unknown result type (might be due to invalid IL or missing references) //IL_0054: Unknown result type (might be due to invalid IL or missing references) //IL_0056: Unknown result type (might be due to invalid IL or missing references) //IL_005c: Unknown result type (might be due to invalid IL or missing references) //IL_0064: Unknown result type (might be due to invalid IL or missing references) //IL_006a: Unknown result type (might be due to invalid IL or missing references) //IL_0074: Unknown result type (might be due to invalid IL or missing references) //IL_007a: Unknown result type (might be due to invalid IL or missing references) if (!Directory.Exists(directoryPath)) { return string.Empty; } string[] files = Directory.GetFiles(directoryPath, "*.*", SearchOption.TopDirectoryOnly); string result = string.Empty; float num = float.MaxValue; string[] array = files; foreach (string text in array) { string value = Path.GetExtension(text).ToLower(); if (Array.IndexOf(SupportedExtensions, value) != -1) { Color dominantColor = GetDominantColor(text); float num2 = targetColor.r - dominantColor.r; float num3 = targetColor.g - dominantColor.g; float num4 = targetColor.b - dominantColor.b; float num5 = num2 * num2 + num3 * num3 + num4 * num4; if (num5 < num) { num = num5; result = text; } } } return result; } } } namespace NukeLib.Game.Scores { public static class LeaderboardHelper { public static void DisableLeaderboards() { AssistController instance = MonoSingleton.Instance; if (!((Object)(object)instance == (Object)null)) { instance.cheatsEnabled = true; } } } } namespace NukeLib.Game.Controls { public static class Pauser { public static void Pause(bool paused) { if ((Object)(object)MonoSingleton.Instance != (Object)null) { ((Behaviour)MonoSingleton.Instance).enabled = !paused; } if ((Object)(object)MonoSingleton.Instance != (Object)null) { MonoSingleton.Instance.activated = !paused; } if ((Object)(object)MonoSingleton.Instance != (Object)null) { ((Behaviour)MonoSingleton.Instance).enabled = !paused; } Time.timeScale = (paused ? 0f : 1f); } } } namespace NukeLib.Debug { public static class PrintUtils { public static string Stringify(this T[] array, string delimiter = ", ", string prefix = "[", string suffix = "]") { string text = prefix; for (int i = 0; i < array.Length; i++) { text += array[i].ToString(); if (i < array.Length - 1) { text += delimiter; } } return text + suffix; } } } namespace NukeLib.Assets { public static class FileAssetHelper { public static Sprite LoadNewSprite(string filePath, float pixelsPerUnit = 100f, SpriteMeshType spriteType = (SpriteMeshType)1) { //IL_0020: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) //IL_0036: Unknown result type (might be due to invalid IL or missing references) Texture2D val = LoadTexture(filePath); return Sprite.Create(val, new Rect(0f, 0f, (float)((Texture)val).width, (float)((Texture)val).height), new Vector2(0f, 0f), pixelsPerUnit, 0u, spriteType); } public static Sprite ConvertTextureToSprite(Texture2D texture, float pixelsPerUnit = 100f, SpriteMeshType spriteType = (SpriteMeshType)1) { //IL_0019: Unknown result type (might be due to invalid IL or missing references) //IL_0028: Unknown result type (might be due to invalid IL or missing references) //IL_002f: Unknown result type (might be due to invalid IL or missing references) return Sprite.Create(texture, new Rect(0f, 0f, (float)((Texture)texture).width, (float)((Texture)texture).height), new Vector2(0f, 0f), pixelsPerUnit, 0u, spriteType); } public static Texture2D LoadTexture(string FilePath) { //IL_0011: Unknown result type (might be due to invalid IL or missing references) //IL_0017: Expected O, but got Unknown if (File.Exists(FilePath)) { byte[] array = File.ReadAllBytes(FilePath); Texture2D val = new Texture2D(2, 2); if (ImageConversion.LoadImage(val, array)) { return val; } } return null; } public static async Task LoadTextureAsync(string filePath) { if (!File.Exists(filePath)) { return null; } string text = "file://" + filePath; UnityWebRequest uwr = UnityWebRequestTexture.GetTexture(text); try { UnityWebRequestAsyncOperation operation = uwr.SendWebRequest(); while (!((AsyncOperation)operation).isDone) { await Task.Yield(); } if ((int)uwr.result != 1) { return null; } return DownloadHandlerTexture.GetContent(uwr); } finally { ((IDisposable)uwr)?.Dispose(); } } } }