Skip to content

[BUG] saveable discovery calls can crash the first save load (0x80131506) #369

Open

Description

@DooDesch

On IL2CPP, the first save load of a session can end the game with Fatal error. Internal CLR error. (0x80131506) and no managed exception. Crash dumps show it inside S1API's saveable discovery:

System.Reflection.RuntimeModule.GetTypes()
System.Reflection.Assembly.GetTypes()
S1API.Saveables.SaveableAutoRegistry.DiscoverSaveableTypes()
S1API.Saveables.SaveableAutoRegistry.GetRegisteredSaveables()
S1API.Internal.Patches.GenericSaveablesPatches.BeforeBaseLoaders(Il2CppScheduleOne.Persistence.LoadRequest)

Which assembly. DiscoverSaveableTypes runs unoptimised, so its loop index is still on the stack. In every dump, mapped against the loaded-assembly list, it points at MelonLoader\Il2CppAssemblies\Assembly-CSharp.dll, the generated interop assembly. The method filters assemblies by FullName prefix (System, Unity, mscorlib, netstandard, Microsoft, Il2Cpp, MelonLoader, 0Harmony). Assembly-CSharp and Assembly-CSharp-firstpass match none of them, so both are enumerated on every IL2CPP game.

How often. Whether a given mod set dies there varies from run to run. On one 0.4.7f12 setup with S1API 3.2.1, hosting a lobby and loading a save died in 13 of 16 runs. Removing other mods only changed the rate; every dump still pointed at Assembly-CSharp.dll. This matches the 0x80131506 in #289, which bounded the NPC discovery paths through ReflectionUtils.GetDerivedClasses but did not touch this one.

Same pattern elsewhere. ProductEffectPatches.GetNpcWrapperTypeById walks every loaded assembly with no filter.

Suggested fix. Route both through ReflectionUtils.GetDerivedClasses<T>(). A direct Saveable subclass and an NPC wrapper both have to reference S1API, so the results do not change.

Activity

  1. LoganaterGames commented on Oct 16, 2026

    @LoganaterGames

    Additional reproduction case: Fatal CLR error after selling cocaine to a vanilla NPC

    Game: Schedule I 0.4.7f12
    Unity: 2022.3.62f2
    Mod loader: MelonLoader 0.7.3 Open-Beta
    S1API: Forked v3.2.1

    I encountered this fatal crash while selling normal cocaine to a vanilla NPC.

    Steps to reproduce:

    1. Interact with a vanilla NPC and open the normal product-selling menu.
    2. Provide the cocaine the NPC requested.
    3. Click Sell.
    4. The menu closes normally, as expected.
    5. Shortly afterward, the game freezes and terminates with a fatal CLR error.

    Fatal error:
    Fatal error. Internal CLR error. (0x80131506)

    The stack trace in the console screenshot contains the following calls:

    • System.Reflection.RuntimeModule.GetTypes(System.Reflection.RuntimeModule)
    • System.Reflection.Assembly.GetTypes()
    • S1API.Internal.Patches.ProductEffectPatches.GetNpcWrapperTypeById()
    • S1API.Internal.Patches.ProductEffectPatches.ResolveApiNpc(...)
    • S1API.Internal.Patches.ProductEffectPatches.ProductEffects_Prefix(...)
    • ProductItemInstance.ApplyEffectsToNPC(...)

    This suggests the crash occurs during product-effect processing after a successful sale, when S1API attempts to discover an NPC wrapper type.

    The affected NPC was a vanilla NPC, and the product was ordinary cocaine. I was not interacting with a Drug Runners employee (from the Drug Runners mod) or using a custom product.

    The attached console screenshot shows the fatal error and stack trace. The accompanying log is my Latest.log generated by MelonLoader.

    Image

    Latest.log

    This may provide an additional reproduction path for the unsafe assembly scanning described in this issue and addressed by pull request #370.

  2. changed the title [-]IL2CPP: saveable discovery calls GetTypes() on Assembly-CSharp and can crash the first save load (0x80131506)[/-] [+][BUG] saveable discovery calls can crash the first save load (0x80131506)[/+] on Oct 16, 2026
  3. added
    bugSomething isn't working
    saveablesNative game save system
    MediumEdge case bugs, etc
    on Oct 16, 2026
  4. ifBars commented on Oct 16, 2026

    @ifBars
    Owner

    Thanks for the extra repro. I tested a vanilla cocaine sale to Kyle Cooley on 0.4.7f12 IL2CPP. On S1API 3.2.1, the sale reached the Assembly-CSharp scan all three times, but the game kept running. PR #370 completed the sale twice without scanning those assemblies.

    I’m leaving this open since I can’t reproduce the fatal CLR error locally. We’d need a reproducible mod setup, or a smaller Polyfill repro, to figure out what makes that scan crash before calling it fixed.

  5. LoganaterGames commented on Oct 16, 2026

    @LoganaterGames

    I'm going to check to see if it was just the one NPC to whom I sold it that could be the issue, or if I can reproduce the crash by selling to other customers. If it doesn't crash for other NPCs, I'll comment the name of the one NPC for whom it did. I don't know how helpful that will be, but I'll also throw in the latest log generated from that with that comment!

  6. LoganaterGames commented on Oct 17, 2026

    @LoganaterGames

    In the first log that I've shared, I made the cocaine deal with Herbert Bleuball, and then the fatal error occurred. In this one, I sold to Fiona Hancock, and the same error happened in the same way I described with Herbert. Here are my logs for what happened with Fiona:

    Image

    Latest.log

    I hope these help in some way; I feel like I can't sell to anyone personally unless it's through my dealers. Your mods are amazing, ifBars!!

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    MediumEdge case bugs, etcbugSomething isn't workingnon-reproducibleUnable to reproducesaveablesNative game save system

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions