Skip to content

BNM Initialization error (and how I fixed it) #177

@Pubert-CS

Description

@Pubert-CS

When initializing BNM, this line crashes for me:

auto UnityEngineCoreModule = Image(BNM_OBFUSCATE_TMP("UnityEngine.CoreModule.dll"));

The crash happens inside Loading.cpp during initialization.

After looking into it, the issue seems to come from Internal::TryGetImage when it calls Assembly$$GetAllAssemblies().

Normally this works fine, as I haven't had this issue on earlier unity versions, but in this game, that seems to break early during startup and causes the crash before anything else can continue.

I wasn't getting any crash logs about this, so I don't really have anything to show (sorry about that)

As a test, I replaced Assembly$$GetAllAssemblies() with this version:

inline std::vector<IL2CPP::Il2CppAssembly*>* Assembly$$GetAllAssemblies() {
    auto domain = il2cpp_domain_get();

    auto il2cpp_domain_get_assemblies_fn =
        (IL2CPP::Il2CppAssembly**(*)(IL2CPP::Il2CppDomain*, size_t*))
        dlsym(Internal::il2cppLibraryHandle, BNM_IL2CPP_API_il2cpp_domain_get_assemblies);

    size_t count = 0;
    auto assemblies = il2cpp_domain_get_assemblies_fn(domain, &count);

    if (!assemblies || count == 0) {
        return {};
    }

    return new std::vector<IL2CPP::Il2CppAssembly*>(assemblies, assemblies + count);
}

With this change, BNM starts correctly and Image() no longer crashes.

I know this isn’t the safest fix, but it works consistently for this game's version (6000.2.6f2).

I actually saw another issue that seemed to be erroring at the same time, too
#176

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions