Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void HookPurgeNOSAddon(Il2CppSystem.Type purgeNOSAddonType)
- {
- try
- {
- //Il2CppSystem.Type purgeNOSAddonType = null;
- // Iterate through all assemblies
- foreach (var assembly in Il2CppSystem.AppDomain.CurrentDomain.GetAssemblies())
- {
- try
- {
- // Iterate through all types in the assembly
- foreach (var type in assembly.GetTypes())
- {
- // Check if the type contains a property named "enabled" (or part of it)
- if (type.GetProperties((Il2CppSystem.Reflection.BindingFlags)(BindingFlags.Public | BindingFlags.Instance)).Any(p => p.Name.Contains("enabled")))
- {
- purgeNOSAddonType = type;
- MelonLogger.Msg($"Found matching type: {type.FullName} in assembly {assembly.FullName}");
- break;
- }
- }
- }
- catch (ReflectionTypeLoadException ex)
- {
- MelonLogger.Error($"ReflectionTypeLoadException for assembly {assembly.FullName}: {ex.Message}");
- foreach (System.Exception loaderException in ex.LoaderExceptions)
- {
- MelonLogger.Error("LoaderException: " + loaderException.Message);
- }
- }
- catch (System.Exception ex)
- {
- MelonLogger.Error($"Exception for assembly {assembly.FullName}: {ex.Message}");
- }
- if (purgeNOSAddonType != null)
- {
- break;
- }
- }
- if (purgeNOSAddonType == null)
- {
- MelonLogger.Error("PurgeNOSAddon type not found.");
- return;
- }
- // Register the type with IL2CPP
- //ClassInjector.RegisterTypeInIl2Cpp(purgeNOSAddonType);
- // Get Il2CppSystem.Type from System.Type
- Il2CppSystem.Type il2cppPurgeNOSAddonType = Il2CppSystem.Type.GetType(purgeNOSAddonType.AssemblyQualifiedName);
- // Find all instances of the base type
- var allComponents = Resources.FindObjectsOfTypeAll(Il2CppType.Of<Component>());
- Component purgeNOSAddonInstance = null;
- foreach (var component in allComponents)
- {
- if (component.GetIl2CppType().FullName == il2cppPurgeNOSAddonType.FullName)
- {
- purgeNOSAddonInstance = (Component)component;
- break;
- }
- }
- if (purgeNOSAddonInstance == null)
- {
- MelonLogger.Error("Instance of PurgeNOSAddon not found in the scene.");
- return;
- }
- // Get the 'enabled' property using reflection
- var enabledProperty = purgeNOSAddonType.GetProperty("enabled", (Il2CppSystem.Reflection.BindingFlags)(BindingFlags.Public | BindingFlags.Instance));
- if (enabledProperty == null)
- {
- MelonLogger.Error("'enabled' property not found on PurgeNOSAddon.");
- return;
- }
- // Set the 'enabled' property to true
- enabledProperty.SetValue(purgeNOSAddonInstance, true);
- MelonLogger.Msg("PurgeNOSAddon.enabled set to true.");
- }
- catch (ReflectionTypeLoadException ex)
- {
- MelonLogger.Error("ReflectionTypeLoadException: " + ex.Message);
- foreach (System.Exception loaderException in ex.LoaderExceptions)
- {
- MelonLogger.Error("LoaderException: " + loaderException.Message);
- }
- }
- catch (System.Exception ex)
- {
- MelonLogger.Error("An error occurred while hooking PurgeNOSAddon: " + ex.Message);
- }
- }
- //WORKING FUNCTION
- private void HookPurgeNOSAddon2()
- {
- try
- {
- Type purgeNOSAddonType = null;
- // Iterate through all assemblies
- foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies())
- {
- try
- {
- // Iterate through all types in the assembly
- foreach (var type in assembly.GetTypes())
- {
- // Check if the type contains a property named "enabled" (or part of it)
- if (type.GetProperties(BindingFlags.Public | BindingFlags.Instance).Any(p => p.Name.Contains("enabled")))
- {
- purgeNOSAddonType = type;
- MelonLogger.Msg($"Found matching type: {type.FullName} in assembly {assembly.FullName}");
- break;
- }
- }
- }
- catch (ReflectionTypeLoadException ex)
- {
- MelonLogger.Error($"ReflectionTypeLoadException for assembly {assembly.FullName}: {ex.Message}");
- foreach (Exception loaderException in ex.LoaderExceptions)
- {
- MelonLogger.Error("LoaderException: " + loaderException.Message);
- }
- }
- catch (Exception ex)
- {
- MelonLogger.Error($"Exception for assembly {assembly.FullName}: {ex.Message}");
- }
- if (purgeNOSAddonType != null)
- {
- break;
- }
- }
- if (purgeNOSAddonType == null)
- {
- MelonLogger.Error("PurgeNOSAddon type not found.");
- return;
- }
- // Register the type with IL2CPP
- ClassInjector.RegisterTypeInIl2Cpp(purgeNOSAddonType);
- // Get Il2CppSystem.Type from System.Type
- Il2CppSystem.Type il2cppPurgeNOSAddonType = Il2CppSystem.Type.GetType(purgeNOSAddonType.AssemblyQualifiedName);
- // Use Il2CppObjectBase to find the instance
- //var purgeNOSAddonInstance = Il2CppObjectBase.FindObjectOfType(il2cppPurgeNOSAddonType);
- var purgeNOSAddonInstance = UnityEngine.Object.FindObjectOfType(il2cppPurgeNOSAddonType);
- if (purgeNOSAddonInstance == null)
- {
- MelonLogger.Error("Instance of PurgeNOSAddon not found in the scene.");
- return;
- }
- // Get the 'enabled' property using reflection
- var enabledProperty = purgeNOSAddonType.GetProperty("enabled", BindingFlags.Public | BindingFlags.Instance);
- if (enabledProperty == null)
- {
- MelonLogger.Error("'enabled' property not found on PurgeNOSAddon.");
- return;
- }
- // Set the 'enabled' property to true
- enabledProperty.SetValue(purgeNOSAddonInstance, true);
- MelonLogger.Msg("PurgeNOSAddon.enabled set to true.");
- }
- catch (ReflectionTypeLoadException ex)
- {
- MelonLogger.Error("ReflectionTypeLoadException: " + ex.Message);
- foreach (Exception loaderException in ex.LoaderExceptions)
- {
- MelonLogger.Error("LoaderException: " + loaderException.Message);
- }
- }
- catch (Exception ex)
- {
- MelonLogger.Error("An error occurred while hooking PurgeNOSAddon: " + ex.Message);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment