Files
UnityExplorer_Fix/src/Unstrip/ImageConversionUnstrip.cs

56 lines
1.6 KiB
C#
Raw Normal View History

#if CPP
using System;
using System.IO;
using UnityExplorer.Helpers;
using UnhollowerBaseLib;
using UnityEngine;
2020-11-09 16:43:19 +11:00
namespace UnityExplorer.Unstrip
{
public static class ImageConversionUnstrip
{
// byte[] ImageConversion.EncodeToPNG(this Texture2D image);
2020-11-09 16:43:19 +11:00
internal delegate IntPtr d_EncodeToPNG(IntPtr tex);
2020-10-16 19:40:01 +11:00
public static byte[] EncodeToPNG(this Texture2D tex)
{
2020-11-09 16:43:19 +11:00
IntPtr ptr = ICallHelper.GetICall<d_EncodeToPNG>("UnityEngine.ImageConversion::EncodeToPNG")
2020-10-16 19:40:01 +11:00
.Invoke(tex.Pointer);
2020-10-18 04:39:50 +11:00
2020-11-09 16:43:19 +11:00
return new Il2CppStructArray<byte>(ptr);
}
// bool ImageConversion.LoadImage(this Texture2D tex, byte[] data, bool markNonReadable);
2020-10-18 04:39:50 +11:00
internal delegate bool d_LoadImage(IntPtr tex, IntPtr data, bool markNonReadable);
2020-10-16 19:40:01 +11:00
public static bool LoadImage(this Texture2D tex, byte[] data, bool markNonReadable)
{
Il2CppStructArray<byte> il2cppArray = new Il2CppStructArray<byte>(data.Length);
for (int i = 0; i < data.Length; i++)
il2cppArray[i] = data[i];
2020-10-18 04:39:50 +11:00
bool ret = ICallHelper.GetICall<d_LoadImage>("UnityEngine.ImageConversion::LoadImage")
.Invoke(tex.Pointer, il2cppArray.Pointer, markNonReadable);
2020-10-18 04:39:50 +11:00
return ret;
}
2020-10-16 19:40:01 +11:00
// Helper for LoadImage from filepath
2020-10-16 19:40:01 +11:00
public static bool LoadImage(Texture2D tex, string filePath, bool markNonReadable)
{
if (!File.Exists(filePath))
{
return false;
}
byte[] data = File.ReadAllBytes(filePath);
return tex.LoadImage(data, markNonReadable);
}
}
}
2020-11-14 02:49:14 +11:00
#endif