Reflection cleanup, fix il2cpp struct and enum boxing

And temp removing il2cpp IDictionary / IEnumerable helpers, will see what is necessary after knah's rewrite.
This commit is contained in:
Sinai
2021-05-07 01:22:55 +10:00
parent 1ee10c2507
commit 8534c08f49
18 changed files with 716 additions and 960 deletions

View File

@ -21,7 +21,7 @@ namespace UnityExplorer.Core.Runtime.Mono
public override void Initialize()
{
ExplorerCore.Context = RuntimeContext.Mono;
Reflection = new MonoReflection();
//Reflection = new MonoReflection();
TextureUtil = new MonoTextureUtil();
}

View File

@ -1,47 +0,0 @@
#if MONO
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace UnityExplorer.Core.Runtime.Mono
{
public class MonoReflection : ReflectionProvider
{
// Mono doesn't need to explicitly cast things.
public override object Cast(object obj, Type castTo)
=> obj;
public override T TryCast<T>(object obj)
{
try
{
return (T)obj;
}
catch
{
return default;
}
}
// Vanilla GetType is fine for mono
public override Type GetActualType(object obj)
=> obj.GetType();
public override bool IsAssignableFrom(Type toAssignTo, Type toAssignFrom)
=> toAssignTo.IsAssignableFrom(toAssignFrom);
public override bool LoadModule(string module)
=> true;
public override string ProcessTypeFullNameInString(Type type, string theString, ref string typeName)
=> theString;
public override Type GetDeobfuscatedType(Type type) => type;
// not necessary
public override void BoxStringToType(ref object _string, Type castTo) { }
}
}
#endif

View File

@ -52,9 +52,9 @@ namespace UnityExplorer.Core.Runtime.Mono
private static MethodInfo GetEncodeToPNGMethod()
{
if (ReflectionUtility.GetTypeByName("UnityEngine.ImageConversion") is Type imageConversion)
return m_encodeToPNGMethod = imageConversion.GetMethod("EncodeToPNG", ReflectionUtility.AllFlags);
return m_encodeToPNGMethod = imageConversion.GetMethod("EncodeToPNG", ReflectionUtility.FLAGS);
var method = typeof(Texture2D).GetMethod("EncodeToPNG", ReflectionUtility.AllFlags);
var method = typeof(Texture2D).GetMethod("EncodeToPNG", ReflectionUtility.FLAGS);
if (method != null)
return m_encodeToPNGMethod = method;