refactored icalls using icall helper

This commit is contained in:
sinaioutlander
2020-10-16 19:40:01 +11:00
parent bdf86a7448
commit bc0ad5eab6
27 changed files with 115 additions and 61 deletions

View File

@ -4,6 +4,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Explorer.Helpers;
namespace Explorer.Unstrip.IMGUI
{

View File

@ -6,6 +6,7 @@ using System.Text;
using UnhollowerBaseLib;
using UnityEngine;
using System.IO;
using Explorer.Helpers;
namespace Explorer.Unstrip.ImageConversion
{
@ -13,29 +14,27 @@ namespace Explorer.Unstrip.ImageConversion
{
// byte[] ImageConversion.EncodeToPNG(this Texture2D image);
internal delegate byte[] d_EncodeToPNG(IntPtr tex);
public static byte[] EncodeToPNG(this Texture2D tex)
{
return EncodeToPNG_iCall(tex.Pointer);
return ICallHelper.GetICall<d_EncodeToPNG>("UnityEngine.ImageConversion::EncodeToPNG")
.Invoke(tex.Pointer);
}
internal delegate byte[] EncodeToPNG_delegate(IntPtr tex);
internal static EncodeToPNG_delegate EncodeToPNG_iCall =
IL2CPP.ResolveICall<EncodeToPNG_delegate>("UnityEngine.ImageConversion::EncodeToPNG");
// bool ImageConversion.LoadImage(this Texture2D tex, byte[] data, bool markNonReadable);
internal delegate bool d_LoadImage(IntPtr tex, byte[] data, bool markNonReadable);
public static bool LoadImage(this Texture2D tex, byte[] data, bool markNonReadable)
{
return LoadImage_iCall(tex.Pointer, data, markNonReadable);
return ICallHelper.GetICall<d_LoadImage>("UnityEngine.ImageConversion::LoadImage")
.Invoke(tex.Pointer, data, markNonReadable);
}
internal delegate bool LoadImage_delegate(IntPtr tex, byte[] data, bool markNonReadable);
internal static LoadImage_delegate LoadImage_iCall =
IL2CPP.ResolveICall<LoadImage_delegate>("UnityEngine.ImageConversion::LoadImage");
// Helper for LoadImage from filepath
// Helper for LoadImage
public static bool LoadImage(this Texture2D tex, string filePath, bool markNonReadable)
public static bool LoadImage(Texture2D tex, string filePath, bool markNonReadable)
{
if (!File.Exists(filePath))
{

View File

@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Linq;
using System.Text;
using UnityEngine;
using Explorer.Helpers;
#if CPP
using UnhollowerBaseLib;
#endif
@ -13,20 +14,14 @@ namespace Explorer.Unstrip.LayerMasks
{
#if CPP
internal delegate IntPtr d_LayerToName(int layer);
internal static d_LayerToName LayerToName_iCall =
IL2CPP.ResolveICall<d_LayerToName>("UnityEngine.LayerMask::LayerToName");
public static string LayerToName(int layer)
{
var ptr = LayerToName_iCall(layer);
return IL2CPP.Il2CppStringToManaged(ptr);
var iCall = ICallHelper.GetICall<d_LayerToName>("UnityEngine.LayerMask::LayerToName");
return IL2CPP.Il2CppStringToManaged(iCall.Invoke(layer));
}
#else
public static string LayerToName(int layer)
{
return LayerMask.LayerToName(layer);
}
public static string LayerToName(int layer) => LayerMask.LayerToName(layer);
#endif
}
}

View File

@ -3,6 +3,7 @@ using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Explorer.Helpers;
using UnhollowerBaseLib;
using UnityEngine;
using UnityEngine.SceneManagement;
@ -12,28 +13,29 @@ namespace Explorer.Unstrip.Scenes
public class SceneUnstrip
{
//Scene.GetRootGameObjects();
internal delegate void d_GetRootGameObjects(int handle, IntPtr list);
public static GameObject[] GetRootGameObjects(Scene scene)
{
var list = new Il2CppSystem.Collections.Generic.List<GameObject>(GetRootCount_Internal(scene));
var list = new Il2CppSystem.Collections.Generic.List<GameObject>(GetRootCount(scene));
GetRootGameObjectsInternal_iCall(scene.handle, list.Pointer);
var iCall = ICallHelper.GetICall<d_GetRootGameObjects>("UnityEngine.SceneManagement.Scene::GetRootGameObjectsInternal");
iCall.Invoke(scene.handle, list.Pointer);
return list.ToArray();
}
internal delegate void GetRootGameObjectsInternal_delegate(int handle, IntPtr list);
internal static GetRootGameObjectsInternal_delegate GetRootGameObjectsInternal_iCall =
IL2CPP.ResolveICall<GetRootGameObjectsInternal_delegate>("UnityEngine.SceneManagement.Scene::GetRootGameObjectsInternal");
//Scene.rootCount;
public static int GetRootCount_Internal(Scene scene)
{
return GetRootCountInternal_iCall(scene.handle);
}
internal delegate int GetRootCountInternal_delegate(int handle);
internal static GetRootCountInternal_delegate GetRootCountInternal_iCall =
IL2CPP.ResolveICall<GetRootCountInternal_delegate>("UnityEngine.SceneManagement.Scene::GetRootCountInternal");
public static int GetRootCount(Scene scene)
{
var iCall = ICallHelper.GetICall<GetRootCountInternal_delegate>("UnityEngine.SceneManagement.Scene::GetRootCountInternal");
return iCall.Invoke(scene.handle);
}
}
}
#endif