diff --git a/Modules/Utils.cs b/Modules/Utils.cs index 660efa1e9d..826d45300b 100644 --- a/Modules/Utils.cs +++ b/Modules/Utils.cs @@ -2,6 +2,7 @@ using AmongUs.GameOptions; using Hazel; using Il2CppInterop.Generator.Extensions; +using Il2CppInterop.Runtime.InteropTypes.Arrays; using InnerNet; using System; using System.Data; @@ -2716,7 +2717,7 @@ public static void FlashColor(Color color, float duration = 1f) }))); } - public static Dictionary CachedSprites = []; + private readonly static Dictionary CachedSprites = []; public static Sprite LoadSprite(string path, float pixelsPerUnit = 1f) { try @@ -2733,15 +2734,21 @@ public static Sprite LoadSprite(string path, float pixelsPerUnit = 1f) } return null; } - public static Texture2D LoadTextureFromResources(string path) + private static unsafe Texture2D LoadTextureFromResources(string path) { try { - var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(path); - var texture = new Texture2D(1, 1, TextureFormat.ARGB32, false); - using MemoryStream ms = new(); - stream.CopyTo(ms); - ImageConversion.LoadImage(texture, ms.ToArray(), false); + Texture2D texture = new(2, 2, TextureFormat.ARGB32, true); + Assembly assembly = Assembly.GetExecutingAssembly(); + Stream stream = assembly.GetManifestResourceStream(path); + var length = stream.Length; + var byteTexture = new Il2CppStructArray(length); + stream.Read(new Span(IntPtr.Add(byteTexture.Pointer, IntPtr.Size * 4).ToPointer(), (int)length)); + if (path.Contains("HorseHats")) + { + byteTexture = new Il2CppStructArray(byteTexture.Reverse().ToArray()); + } + ImageConversion.LoadImage(texture, byteTexture, false); return texture; } catch