Skip to content

Conversation

@yukieiji
Copy link
Contributor

Update mod to 2025.4.15(v16)+
Fixed unity object cast

@yukieiji yukieiji changed the title Update AmongUs v16 Update AmongUs v17(2025.9.9) Sep 15, 2025
@yukieiji
Copy link
Contributor Author

The target version has been changed to v17.
Additionally, the changes discussed in #65 have been included.

chagh-dev

This comment was marked as outdated.

@yukieiji
Copy link
Contributor Author

I tried writing a patch like the one below, but applying it failed.

    [HarmonyPatch]
    public static class InvalidOptionsPatches
    {
        [HarmonyTargetMethods]
        public static IEnumerable<System.Reflection.MethodBase> TargetMethod()
        {
            var allType = AccessTools.AllTypes();
            var optionType = allType
                .Where(x => 
                    GetBaseTypes(x)
                    .Any(x => x.Name.Contains(nameof(IGameOptions)))
                );
            return optionType
                .Select(x => AccessTools.Method(x, "AreInvalid"))
                .Where(x => x != null);
        }

        [HarmonyPrefix]
        public static bool IsOptionValid(IGameOptions __instance, [HarmonyArgument(0)] int maxExpectedPlayers)
            => __instance.MaxPlayers > maxExpectedPlayers ||
            __instance.NumImpostors< 1 ||
            __instance.NumImpostors + 1 > maxExpectedPlayers / 2 ||
            __instance.GetInt(Int32OptionNames.KillDistance) is < 0 or > 2 ||
            __instance.GetFloat(FloatOptionNames.PlayerSpeedMod) is <= 0f or > 3f;

        private static IEnumerable<System.Type> GetBaseTypes(System.Type self)
        {
            for (var baseType = self.BaseType; null != baseType; baseType = baseType.BaseType)
            {
                yield return baseType;
            }
        }
    }

I think it's difficult to merge these patches, because the type of __instance is different

@yukieiji yukieiji requested a review from chagh-dev September 16, 2025 16:24
@XtraCube
Copy link

XtraCube commented Oct 6, 2025

@yukieiji i think the instance being IGameOptions __instance should probably work, but if it doesnt, you can try using Il2CppObjectBase __instance, then use __instance.Cast<IGameOptions>(). Also i think theres a better way to check the types, instead of manually checking the base types of every type, just check type.IsSubclassOf(typeof(IGameOptions))

@yukieiji
Copy link
Contributor Author

yukieiji commented Oct 9, 2025

@XtraCube don't work

  • code
[HarmonyPatch]
public static class InvalidOptionsPatches
{
    [HarmonyTargetMethods]
    public static IEnumerable<System.Reflection.MethodBase> TargetMethod()
    {
        var allType = AccessTools.AllTypes();
        var optionType = allType
            .Where(x => x.IsSubclassOf(typeof(IGameOptions)));
        return optionType
            .Select(x => AccessTools.Method(x, "AreInvalid"))
            .Where(x => x != null);
    }

    [HarmonyPrefix]
    public static bool IsOptionValid(Il2CppObjectBase __instance, [HarmonyArgument(0)] int maxExpectedPlayers)
    {
        var option = __instance.Cast<IGameOptions>();
        return
            option.MaxPlayers > maxExpectedPlayers ||
            option.NumImpostors < 1 ||
            option.NumImpostors + 1 > maxExpectedPlayers / 2 ||
            option.GetInt(Int32OptionNames.KillDistance) is < 0 or > 2 ||
            option.GetFloat(FloatOptionNames.PlayerSpeedMod) is <= 0f or > 3f;
    }
}
  • log
[Warning:  HarmonyX] AccessTools.GetTypesFromAssembly: assembly Il2Cppmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null => System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Type 'Il2CppSystem.Runtime.InteropServices.ComTypes.IMoniker' from assembly 'Il2Cppmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' cannot extend from any other type.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at HarmonyLib.AccessTools.GetTypesFromAssembly(Assembly assembly)
System.TypeLoadException: Type 'Il2CppSystem.Runtime.InteropServices.ComTypes.IMoniker' from assembly 'Il2Cppmscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' cannot extend from any other type.
[Warning:  HarmonyX] AccessTools.GetTypesFromAssembly: assembly UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null => System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'LightProbesQueryDisposeJob' from assembly 'UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at HarmonyLib.AccessTools.GetTypesFromAssembly(Assembly assembly)
System.TypeLoadException: Could not load type 'LightProbesQueryDisposeJob' from assembly 'UnityEngine.CoreModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
[Warning:  HarmonyX] AccessTools.GetTypesFromAssembly: assembly Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null => System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'DiscordConnect.EventData' from assembly 'Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at HarmonyLib.AccessTools.GetTypesFromAssembly(Assembly assembly)
System.TypeLoadException: Could not load type 'DiscordConnect.EventData' from assembly 'Assembly-CSharp-firstpass, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
[Warning:  HarmonyX] AccessTools.GetTypesFromAssembly: assembly Il2CppSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null => System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Type 'Il2CppSystem.Runtime.InteropServices.ComTypes.IAdviseSink' from assembly 'Il2CppSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' cannot extend from any other type.
Type 'Il2CppSystem.Runtime.InteropServices.ComTypes.IDataObject' from assembly 'Il2CppSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' cannot extend from any other type.
Type 'Il2CppSystem.Runtime.InteropServices.ComTypes.IEnumFORMATETC' from assembly 'Il2CppSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' cannot extend from any other type.
Type 'Il2CppSystem.Runtime.InteropServices.ComTypes.IEnumSTATDATA' from assembly 'Il2CppSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' cannot extend from any other type.
Could not load type 'Win32_IN6_ADDR' from assembly 'Il2CppSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at HarmonyLib.AccessTools.GetTypesFromAssembly(Assembly assembly)
System.TypeLoadException: Type 'Il2CppSystem.Runtime.InteropServices.ComTypes.IAdviseSink' from assembly 'Il2CppSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' cannot extend from any other type.
System.TypeLoadException: Type 'Il2CppSystem.Runtime.InteropServices.ComTypes.IDataObject' from assembly 'Il2CppSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' cannot extend from any other type.
System.TypeLoadException: Type 'Il2CppSystem.Runtime.InteropServices.ComTypes.IEnumFORMATETC' from assembly 'Il2CppSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' cannot extend from any other type.
System.TypeLoadException: Type 'Il2CppSystem.Runtime.InteropServices.ComTypes.IEnumSTATDATA' from assembly 'Il2CppSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' cannot extend from any other type.
System.TypeLoadException: Could not load type 'Win32_IN6_ADDR' from assembly 'Il2CppSystem, Version=4.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
[Warning:  HarmonyX] AccessTools.GetTypesFromAssembly: assembly Sentry.System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null => System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'ByteArrayUnion' from assembly 'Sentry.System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at HarmonyLib.AccessTools.GetTypesFromAssembly(Assembly assembly)
System.TypeLoadException: Could not load type 'ByteArrayUnion' from assembly 'Sentry.System.Reflection.Metadata, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
[Warning:  HarmonyX] AccessTools.GetTypesFromAssembly: assembly UnityEngine.PropertiesModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null => System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'EnumeratorType' from assembly 'UnityEngine.PropertiesModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
Could not load type 'ConverterKeyComparer' from assembly 'UnityEngine.PropertiesModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at HarmonyLib.AccessTools.GetTypesFromAssembly(Assembly assembly)
System.TypeLoadException: Could not load type 'EnumeratorType' from assembly 'UnityEngine.PropertiesModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
System.TypeLoadException: Could not load type 'ConverterKeyComparer' from assembly 'UnityEngine.PropertiesModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
[Warning:  HarmonyX] AccessTools.GetTypesFromAssembly: assembly UnityEngine.DSPGraphModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null => System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'Node' from assembly 'UnityEngine.DSPGraphModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at HarmonyLib.AccessTools.GetTypesFromAssembly(Assembly assembly)
System.TypeLoadException: Could not load type 'Node' from assembly 'UnityEngine.DSPGraphModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
[Warning:  HarmonyX] AccessTools.GetTypesFromAssembly: assembly UnityEngine.UIElementsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null => System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'PageStatistics' from assembly 'UnityEngine.UIElementsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at HarmonyLib.AccessTools.GetTypesFromAssembly(Assembly assembly)
System.TypeLoadException: Could not load type 'PageStatistics' from assembly 'UnityEngine.UIElementsModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null' because the format is invalid.
[Warning:  HarmonyX] AccessTools.GetTypesFromAssembly: assembly UnityEngine.VirtualTexturingModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null => System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Could not load type 'TextureStackBase`1' from assembly 'UnityEngine.VirtualTexturingModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
Could not load type 'TextureStackBase`1' from assembly 'UnityEngine.VirtualTexturingModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at HarmonyLib.AccessTools.GetTypesFromAssembly(Assembly assembly)
System.TypeLoadException: Could not load type 'TextureStackBase`1' from assembly 'UnityEngine.VirtualTexturingModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
System.TypeLoadException: Could not load type 'TextureStackBase`1' from assembly 'UnityEngine.VirtualTexturingModule, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'.
[Warning:  HarmonyX] AccessTools.GetTypesFromAssembly: assembly __Generated, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null => System.Reflection.ReflectionTypeLoadException: Unable to load one or more of the requested types.
Failure has occurred while loading a type.
   at System.Reflection.RuntimeModule.GetTypes(RuntimeModule module)
   at System.Reflection.Assembly.GetTypes()
   at HarmonyLib.AccessTools.GetTypesFromAssembly(Assembly assembly)
System.TypeLoadException: Failure has occurred while loading a type.
[Error  :   BepInEx] Error loading [CrowdedMod 2.10.0+572d41657fb8ae12456d5fa495e8da1b9cec69ba]: HarmonyLib.HarmonyException: Patching exception in method null
 ---> System.ArgumentException: Undefined target method for patch method static bool CrowdedMod.Patches.GenericPatches+InvalidOptionsPatches::IsOptionValid(Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase __instance, int maxExpectedPlayers)
   at HarmonyLib.PatchClassProcessor.PatchWithAttributes(MethodBase& lastOriginal)
   at HarmonyLib.PatchClassProcessor.Patch()
   --- End of inner exception stack trace ---
   at HarmonyLib.PatchClassProcessor.ReportException(Exception exception, MethodBase original)
   at HarmonyLib.PatchClassProcessor.Patch()
   at HarmonyLib.Harmony.<PatchAll>b__11_0(Type type)
   at HarmonyLib.CollectionExtensions.Do[T](IEnumerable`1 sequence, Action`1 action)
   at HarmonyLib.Harmony.PatchAll(Assembly assembly)
   at HarmonyLib.Harmony.PatchAll()
   at CrowdedMod.CrowdedModPlugin.Load() in F:\Documents\VisualStudioProject\AmongUs\CrowdedMod\src\CrowdedMod\CrowdedModPlugin.cs:line 32
   at BepInEx.Unity.IL2CPP.IL2CPPChainloader.LoadPlugin(PluginInfo pluginInfo, Assembly pluginAssembly) in /home/runner/work/BepInEx/BepInEx/Runtimes/Unity/BepInEx.Unity.IL2CPP/IL2CPPChainloader.cs:line 136
   at BepInEx.Bootstrap.BaseChainloader`1.LoadPlugins(IList`1 plugins) in /home/runner/work/BepInEx/BepInEx/BepInEx.Core/Bootstrap/BaseChainloader.cs:line 411

@XtraCube
Copy link

XtraCube commented Oct 9, 2025

Woah that does not look like a normal log, I'll see if I have time later today to look at it.

@XtraCube
Copy link

XtraCube commented Oct 9, 2025

Actually, dont use AccessTools.AllTypes(). Just use typeof(IGameOptions).Assembly.GetTypes()

@yukieiji
Copy link
Contributor Author

yukieiji commented Oct 10, 2025

@XtraCube don't work

  • code
[HarmonyPatch]
public static class InvalidOptionsPatches
{
    [HarmonyTargetMethods]
    public static IEnumerable<System.Reflection.MethodBase> TargetMethod()
    {
        var allType = typeof(IGameOptions).Assembly.GetTypes();
        var optionType = allType
            .Where(x => x.IsSubclassOf(typeof(IGameOptions)));
        return optionType
            .Select(x => AccessTools.Method(x, "AreInvalid"))
            .Where(x => x != null);
    }

    [HarmonyPrefix]
    public static bool IsOptionValid(Il2CppObjectBase __instance, [HarmonyArgument(0)] int maxExpectedPlayers)
    {
        var option = __instance.Cast<IGameOptions>();
        return
            option.MaxPlayers > maxExpectedPlayers ||
            option.NumImpostors < 1 ||
            option.NumImpostors + 1 > maxExpectedPlayers / 2 ||
            option.GetInt(Int32OptionNames.KillDistance) is < 0 or > 2 ||
            option.GetFloat(FloatOptionNames.PlayerSpeedMod) is <= 0f or > 3f;
    }
}
  • log
[Error  :   BepInEx] Error loading [CrowdedMod 2.9.4+7396883043a8e73da6c2bff2c158566d124e4277]: HarmonyLib.HarmonyException: Patching exception in method null
 ---> System.ArgumentException: Undefined target method for patch method static bool CrowdedMod.Patches.GenericPatches+InvalidOptionsPatches::IsOptionValid(Il2CppInterop.Runtime.InteropTypes.Il2CppObjectBase __instance, int maxExpectedPlayers)
   at HarmonyLib.PatchClassProcessor.PatchWithAttributes(MethodBase& lastOriginal)
   at HarmonyLib.PatchClassProcessor.Patch()
   --- End of inner exception stack trace ---
   at HarmonyLib.PatchClassProcessor.ReportException(Exception exception, MethodBase original)
   at HarmonyLib.PatchClassProcessor.Patch()
   at HarmonyLib.Harmony.<PatchAll>b__11_0(Type type)
   at HarmonyLib.CollectionExtensions.Do[T](IEnumerable`1 sequence, Action`1 action)
   at HarmonyLib.Harmony.PatchAll(Assembly assembly)
   at HarmonyLib.Harmony.PatchAll()
   at CrowdedMod.CrowdedModPlugin.Load() in F:\Documents\VisualStudioProject\AmongUs\CrowdedMod\src\CrowdedMod\CrowdedModPlugin.cs:line 34
   at BepInEx.Unity.IL2CPP.IL2CPPChainloader.LoadPlugin(PluginInfo pluginInfo, Assembly pluginAssembly) in /home/runner/work/BepInEx/BepInEx/Runtimes/Unity/BepInEx.Unity.IL2CPP/IL2CPPChainloader.cs:line 136
   at BepInEx.Bootstrap.BaseChainloader`1.LoadPlugins(IList`1 plugins) in /home/runner/work/BepInEx/BepInEx/BepInEx.Core/Bootstrap/BaseChainloader.cs:line 411

@XtraCube
Copy link

I figured out the issue, interfaces don't show up in inheritance. we have to use a different approach

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants