mirror of
https://github.com/Gurge44/EndlessHostRoles.git
synced 2026-10-20 01:46:25 +00:00
mono port 🔥
This commit is contained in:
1 parent
79a0b23a65
commit
97aa6333fd
273 files changed
+2020
-1684
No files matched your search
@@ -1,7 +1,3 @@
|
||||
using System;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using Il2CppInterop.Runtime.InteropTypes;
|
||||
using UnityEngine;
|
||||
|
||||
namespace EHR;
|
||||
@@ -12,7 +8,7 @@ public static class ObjectHelper
|
||||
{
|
||||
if (!obj) return;
|
||||
|
||||
obj.ForEachChild((Il2CppSystem.Action<GameObject>)(x => x.DestroyTranslator()));
|
||||
obj.ForEachChild(x => x.DestroyTranslator());
|
||||
TextTranslatorTMP[] translator = obj.GetComponentsInChildren<TextTranslatorTMP>(true);
|
||||
translator?.Do(Object.Destroy);
|
||||
}
|
||||
@@ -43,52 +39,4 @@ public static class ObjectHelper
|
||||
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// The codes below I stole from TommyXL
|
||||
public static class Il2CppCastHelper
|
||||
{
|
||||
public static T CastFast<T>(this Il2CppObjectBase obj) where T : Il2CppObjectBase
|
||||
{
|
||||
if (obj is T casted) return casted;
|
||||
return OperatingSystem.IsAndroid() ? obj.Cast<T>() : obj.Pointer.CastFast<T>();
|
||||
}
|
||||
|
||||
private static T CastFast<T>(this IntPtr ptr) where T : Il2CppObjectBase
|
||||
{
|
||||
return CastHelper<T>.Cast(ptr);
|
||||
}
|
||||
|
||||
private static class CastHelper<T> where T : Il2CppObjectBase
|
||||
{
|
||||
public static readonly Func<IntPtr, T> Cast;
|
||||
|
||||
static CastHelper()
|
||||
{
|
||||
ConstructorInfo constructor = typeof(T).GetConstructor([typeof(IntPtr)]);
|
||||
ParameterExpression ptr = Expression.Parameter(typeof(IntPtr));
|
||||
NewExpression create = Expression.New(constructor!, ptr);
|
||||
Expression<Func<IntPtr, T>> lambda = Expression.Lambda<Func<IntPtr, T>>(create, ptr);
|
||||
Cast = lambda.Compile();
|
||||
}
|
||||
}
|
||||
|
||||
public static bool TryCastFast<T>(this Il2CppObjectBase obj, out T casted) where T : Il2CppObjectBase
|
||||
{
|
||||
switch (obj)
|
||||
{
|
||||
case T t:
|
||||
casted = t;
|
||||
return true;
|
||||
case null:
|
||||
casted = null;
|
||||
return false;
|
||||
default:
|
||||
casted = OperatingSystem.IsAndroid()
|
||||
? obj.Cast<T>()
|
||||
: obj.Pointer.CastFast<T>();
|
||||
|
||||
return casted != null;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user