コード例 #1
0
        public static bool GetAbility(uint id, out Il2CppSystem.Type ability)
        {
            try
            {
                if (ExploderConfigDictionary.ContainsKey(id))
                {
                    ability = Il2CppType.Of <ExploderAbility>();
                    return(true);
                }

                if (EMPConfigDictionary.ContainsKey(id))
                {
                    ability = Il2CppType.Of <EMPAbility>();
                    return(true);
                }

                if (ImmortalConfigDictionary.ContainsKey(id))
                {
                    ability = Il2CppType.Of <ImmortalAbility>();
                    return(true);
                }
            }
            catch
            {
                ability = null;
                return(false);
            }

            ability = null;
            return(false);
        }
        public static IntPtr GetNestedTypeViaReflection(IntPtr enclosingClass, string nestedTypeName)
        {
            var reflectionType = Type.internal_from_handle(IL2CPP.il2cpp_class_get_type(enclosingClass));
            var nestedType     = reflectionType.GetNestedType(nestedTypeName, BindingFlags.Public | BindingFlags.NonPublic);

            return(nestedType != null?IL2CPP.il2cpp_class_from_system_type(nestedType.Pointer) : IntPtr.Zero);
        }
コード例 #3
0
        public static Type GetMonoType(CppType cppType)
        {
            if (Il2CppToMonoType.ContainsKey(cppType))
            {
                return(Il2CppToMonoType[cppType]);
            }

            var getType = Type.GetType(cppType.AssemblyQualifiedName);

            if (getType != null)
            {
                Il2CppToMonoType.Add(cppType, getType);
                return(getType);
            }
            else
            {
                string baseName     = cppType.FullName;
                string baseAssembly = cppType.Assembly.GetName().name;

                Type unhollowedType = AppDomain.CurrentDomain.GetAssemblies().FirstOrDefault(a => a.GetName().Name == baseAssembly)?.GetTypes().FirstOrDefault(t =>
                                                                                                                                                               t.CustomAttributes.Any(ca =>
                                                                                                                                                                                      ca.AttributeType.Name == "ObfuscatedNameAttribute" && (string)ca.ConstructorArguments[0].Value == baseName));

                Il2CppToMonoType.Add(cppType, unhollowedType);
                return(unhollowedType);
            }
        }
コード例 #4
0
        internal ResourceLoadedParameters(string path, Il2CppSystem.Type type, ResourceLoadType loadType)
#endif
        {
            Path     = path;
            Type     = type;
            LoadType = loadType;
        }
コード例 #5
0
        public bool GetString(out string text, StringNames stringId, Il2CppReferenceArray <Il2CppSystem.Object> parts)
        {
            string key = Enum.GetName(typeof(StringNames), stringId);

            if (Strings.TryGetValue(key, out text))
            {
                if (parts.Length != 0)
                {
                    List <object> parameters = new List <object>();
                    foreach (Il2CppSystem.Object obj in parts)
                    {
                        Il2CppSystem.Type t = obj.GetIl2CppType();
                        //BetterLanguagesPlugin.log.LogInfo("hey :" + t.ToString());
                        if (Il2CppSystem.Type.IsIntegerType(t))
                        {
                            parameters.Add(obj.Unbox <System.Int32>());
                        }
                        else
                        {
                            parameters.Add(obj.ToString());
                        }
                    }
                    text = string.Format(text, parameters.ToArray());
                }
                return(true);
            }
            return(false);
        }
コード例 #6
0
        internal AssetLoadedParameters(string name, Il2CppSystem.Type type, AssetLoadType loadType)
#endif
        {
            Name     = name;
            Type     = type;
            LoadType = loadType;
        }
コード例 #7
0
        // ReSharper disable once InconsistentNaming
        // ReSharper disable once RedundantAssignment
        public static bool Prefix(ref Object __result, string path, Il2CppSystem.Type systemTypeInstance)
        {
            MelonDebug.Msg($"Resources::Load({path}, {systemTypeInstance.Name})");

            var exist = GoCache.TryGet(path, out __result);

            return(!exist);
        }
コード例 #8
0
 private static bool Prefix(Il2CppSystem.Type panelType, ref bool __result)
 {
     if (panelType == UnhollowerRuntimeLib.Il2CppType.Of <Panel_CustomXPSetup>())
     {
         __result = false;
         return(false);
     }
     return(true);
 }
コード例 #9
0
ファイル: Main.cs プロジェクト: christianacuna/proyecto-qa
 public AssetBundleCreateRequest LoadAssetWithSubAssetsAsync(string name, Il2CppSystem.Type type)
 {
     if (type == null)
     {
         throw new System.NullReferenceException("The input type cannot be null.");
     }
     System.IntPtr intptr = LoadAssetWithSubAssetsAsync(name, type.Pointer);
     return((intptr != System.IntPtr.Zero) ? new AssetBundleCreateRequest(intptr) : null);
 }
コード例 #10
0
ファイル: Main.cs プロジェクト: christianacuna/proyecto-qa
 public Il2CppReferenceArray <Object> LoadAssetWithSubAssets(string name, Il2CppSystem.Type type)
 {
     if (type == null)
     {
         throw new System.NullReferenceException("The input type cannot be null.");
     }
     System.IntPtr intptr = LoadAssetWithSubAssets(name, type.Pointer);
     return((intptr != System.IntPtr.Zero) ? new Il2CppReferenceArray <Object>(intptr) : null);
 }
コード例 #11
0
ファイル: Patches.cs プロジェクト: tavor-games/Reactor
            public static bool Prefix(Type t, int controlID, out Object __result)
            {
                if (!s_StateCache.TryGetValue(controlID, out __result) || __result.GetIl2CppType() != t)
                {
                    s_StateCache[controlID] = __result = t.GetConstructor(new Il2CppReferenceArray <Type>(0)).Invoke(null, new Il2CppReferenceArray <Object>(0));
                }

                return(false);
            }
        public Il2CppReferenceArray <Object> LoadAllAssets(Il2CppSystem.Type type)
        {
            if (type == null)
            {
                throw new NullReferenceException("The input type cannot be null.");
            }
            IntPtr intptr = LoadAllAssets(type.Pointer);

            return((intptr != IntPtr.Zero) ? new Il2CppReferenceArray <Object>(intptr) : null);
        }
        public Il2CppAssetBundleRequest LoadAssetAsync(string name, Il2CppSystem.Type type)
        {
            if (type == null)
            {
                throw new NullReferenceException("The input type cannot be null.");
            }
            IntPtr intptr = LoadAssetAsync(name, type.Pointer);

            return((intptr != IntPtr.Zero) ? new Il2CppAssetBundleRequest(intptr) : null);
        }
        public Object LoadAsset(string name, Il2CppSystem.Type type)
        {
            if (type == null)
            {
                throw new NullReferenceException("The input type cannot be null.");
            }
            IntPtr intptr = LoadAsset(name, type.Pointer);

            return((intptr != IntPtr.Zero) ? new Object(intptr) : null);
        }
コード例 #15
0
 public static bool InheritsFromMonobehaviour(Il2CppSystem.Type type)
 {
     if (type is null)
     {
         return(false);
     }
     else
     {
         return(type.IsSubclassOf(UnhollowerRuntimeLib.Il2CppType.Of <UnityEngine.MonoBehaviour>()));
     }
 }
コード例 #16
0
        public Il2CppReferenceArray <Object> LoadAssetWithSubAssets(string name, Il2CppSystem.Type type)
        {
            if (type == null)
            {
                throw new ArgumentNullException(nameof(type));
            }

            IntPtr ptr = LoadAssetWithSubAssets(name, type.Pointer);

            return(ptr != IntPtr.Zero ? new Il2CppReferenceArray <Object>(ptr) : null);
        }
コード例 #17
0
        public static Il2CppSystem.Object DynamicCast(this Il2CppSystem.Object obj, Il2CppSystem.Type type)
        {
            var mi = obj.GetIl2CppType().GetMethod("Cast");

            var genericArg = new Il2CppReferenceArray <Il2CppSystem.Type>(1);

            genericArg[0] = type;

            var fooRef = mi.MakeGenericMethod(genericArg);

            return(fooRef.Invoke(obj, null));
        }
コード例 #18
0
        public static Type GetMonoType(CppType cppType)
        {
            if (Il2CppToMonoType.ContainsKey(cppType))
            {
                return(Il2CppToMonoType[cppType]);
            }

            var getType = Type.GetType(cppType.AssemblyQualifiedName);

            Il2CppToMonoType.Add(cppType, getType);
            return(getType);
        }
コード例 #19
0
        public static bool DoesTextMeshProSupportRichText(object ui, Type clrType, Il2CppSystem.Type unityType)
#endif
        {
            if (UnityTypes.TMP_Text != null)
            {
                return(UnityTypes.TMP_Text.IsAssignableFrom(unityType) && Equals(clrType.CachedProperty(RichTextPropertyName)?.Get(ui), true));
            }
            else
            {
                return((UnityTypes.TextMeshPro?.IsAssignableFrom(unityType) == true && Equals(clrType.CachedProperty(RichTextPropertyName)?.Get(ui), true)) ||
                       (UnityTypes.TextMeshProUGUI?.IsAssignableFrom(unityType) == true && Equals(clrType.CachedProperty(RichTextPropertyName)?.Get(ui), true)));
            }
        }
コード例 #20
0
        public static bool IsKnownTextMeshProType(Il2CppSystem.Type type)
#endif
        {
            if (UnityTypes.TMP_Text != null)
            {
                return(UnityTypes.TMP_Text.IsAssignableFrom(type));
            }
            else
            {
                return(UnityTypes.TextMeshProUGUI?.IsAssignableFrom(type) == true ||
                       UnityTypes.TextMeshPro?.IsAssignableFrom(type) == true);
            }
        }
コード例 #21
0
        public unsafe static IntPtr GetBuiltinResource(Il2CppSystem.Type type, string path)
        {
            void **ptr = stackalloc void *[2];

            ptr[0] = (void *)UnityInternals.ObjectBaseToPtr(type);
            ptr[1] = (void *)UnityInternals.ManagedStringToInternal(path);
            IntPtr returnedException = default;

            MelonDebug.Msg("Calling runtime_invoke for GetBuiltinResource");
            IntPtr objectPointer = UnityInternals.runtime_invoke(m_GetBuiltinResource, IntPtr.Zero, ptr, ref returnedException);

            MelonDebug.Msg("returnedException: " + returnedException + ", objectPointer: " + objectPointer);
            Il2CppException.RaiseExceptionIfNecessary(returnedException);
            return(objectPointer);
        }
コード例 #22
0
ファイル: Internal.cs プロジェクト: CrackerCat/Explorer
        private static Il2CppSystem.Object GetStateObject(Il2CppSystem.Type type, int controlID)
        {
            Il2CppSystem.Object obj;
            if (StateCache.ContainsKey(controlID))
            {
                obj = StateCache[controlID];
            }
            else
            {
                obj = Il2CppSystem.Activator.CreateInstance(type);
                StateCache.Add(controlID, obj);
            }

            return(obj);
        }
コード例 #23
0
ファイル: ResourcesUnstrip.cs プロジェクト: enko7/Explorer
        public static UnityEngine.Object[] FindObjectsOfTypeAll(Il2CppSystem.Type type)
        {
            var arrayPtr = ICallHelper.GetICall <d_FindObjectsOfTypeAll>("UnityEngine.Resources::FindObjectsOfTypeAll")
                           .Invoke(type.Pointer);

            var array = new Il2CppReferenceArray <UnityEngine.Object>(arrayPtr);

            var ret = new UnityEngine.Object[array.Length];

            for (int i = 0; i < array.Length; i++)
            {
                ret[i] = array[i];
            }

            return(ret);
        }
コード例 #24
0
        public static Type GetUnhollowedType(CppType cppType)
        {
            var fullname = cppType.FullName;

            if (DeobfuscatedTypes.TryGetValue(fullname, out Type deob))
            {
                return(deob);
            }

            if (fullname.StartsWith("System."))
            {
                fullname = $"Il2Cpp{fullname}";
            }

            AllTypes.TryGetValue(fullname, out Type monoType);
            return(monoType);
        }
コード例 #25
0
 public static void CopyFieldsIl2Cpp <T>(T copyTo, T copyFrom) where T : Il2CppSystem.Object
 {
     Il2CppSystem.Type typeOfT = UnhollowerRuntimeLib.Il2CppType.Of <T>();
     Il2CppSystem.Reflection.FieldInfo[] fieldInfos = typeOfT.GetFields();
     foreach (Il2CppSystem.Reflection.FieldInfo fieldInfo in fieldInfos)
     {
         if (fieldInfo.IsInitOnly || fieldInfo.IsLiteral)
         {
             continue;
         }
         fieldInfo.SetValue(copyTo, fieldInfo.GetValue(copyFrom));
     }
     if (fieldInfos.Length == 0)
     {
         MelonLoader.MelonLogger.LogError("There were no fields to copy!");
     }
 }
コード例 #26
0
        public void Start()
        {
            try
            {
                Il2CppSystem.Type behaviourType = TypeResolver.ResolveIl2Cpp(BehaviourName, true);
                this.gameObject.AddComponent(behaviourType);
            }
            catch (System.Exception e)
            {
                Logger.LogError("Could not load behaviour '" + BehaviourName + "': " + e.Message);

                if (FailOnError)
                {
                    throw e;
                }
            }
        }
コード例 #27
0
        public override bool IsReflectionSupported(Type type)
        {
            try
            {
                var gArgs = type.GetGenericArguments();
                if (!gArgs.Any())
                {
                    return(true);
                }

                foreach (var gType in gArgs)
                {
                    if (!Supported(gType))
                    {
                        return(false);
                    }
                }

                return(true);

                bool Supported(Type t)
                {
                    if (!typeof(Il2CppSystem.Object).IsAssignableFrom(t))
                    {
                        return(true);
                    }

                    if (!Il2CppTypeNotNull(t, out IntPtr ptr))
                    {
                        return(false);
                    }

                    return(CppType.internal_from_handle(IL2CPP.il2cpp_class_get_type(ptr)) is CppType);
                }
            }
            catch
            {
                return(false);
            }
        }
コード例 #28
0
        /// <summary>
        /// Try to get the Mono (Unhollowed) Type representation of the provided <see cref="Il2CppSystem.Type"/>.
        /// </summary>
        /// <param name="cppType">The Cpp Type you want to convert to Mono.</param>
        /// <returns>The Mono Type if found, otherwise null.</returns>
        public static Type GetMonoType(CppType cppType)
        {
            string name = cppType.AssemblyQualifiedName;

            if (Il2CppToMonoType.ContainsKey(name))
            {
                return(Il2CppToMonoType[name]);
            }

            Type ret = Type.GetType(name);

            // Thanks to Slaynash for this deobfuscation snippet!
            if (ret == null)
            {
                string baseName     = cppType.FullName;
                string baseAssembly = cppType.Assembly.GetName().name;

                ret = AppDomain.CurrentDomain
                      .GetAssemblies()
                      .FirstOrDefault(a
                                      => a.GetName().Name == baseAssembly)?
                      .TryGetTypes()
                      .FirstOrDefault(t
                                      => t.CustomAttributes.Any(ca
                                                                => ca.AttributeType.Name == "ObfuscatedNameAttribute" &&
                                                                (string)ca.ConstructorArguments[0].Value == baseName));

                if (ret != null)
                {
                    // deobfuscated type was found, add to cache.
                    s_deobfuscatedTypeNames.Add(cppType.FullName, ret.FullName);
                }
            }

            Il2CppToMonoType.Add(name, ret);

            return(ret);
        }
コード例 #29
0
 public static Component GetFirstComponentInSelfOrAncestor(this GameObject go, Il2CppSystem.Type type)
コード例 #30
0
 public Il2CppReferenceArray <Object> LoadAll(Il2CppSystem.Type type) => LoadAllAssets(type);