BNM Initialization error (and how I fixed it)
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 https://github.com/ByNameModding/BNM-Android/issues/176
I actually had a very similar issue (#175), which I had crash logs. This looks like it would probably fix it, so later I'll probably use this. Thank you!
do you know if this works on games newer then 6000.2.6f2?
I've only had issues with BNM/ByNameModding with most of it, the issue being when BNM tries to access structs on il2cppclass and whatever, it tends to crash and I have debugged quite a lot and it does seem to crash when accessing structures.
And of course when I use il2cpp_ functions, it actually doesn't crash at the Assembly$$GetAllAssemblies() after fixing that, but happens later in the loading.
(might not be relevant to this conversation just talking about other stuff)
Now of course this could just be a skill issue for me, but it only gets farther when I switch to using il2cpp functions/methods.
Now of course this could just be a skill issue for me, but it only gets farther when I switch to using il2cpp functions/methods.
yes, same for me
I've only had issues with BNM/ByNameModding with most of it, the issue being when BNM tries to access structs on il2cppclass and whatever, it tends to crash and I have debugged quite a lot and it does seem to crash when accessing structures.
And of course when I use il2cpp_ functions, it actually doesn't crash at the Assembly$$GetAllAssemblies() after fixing that, but happens later in the loading.
(might not be relevant to this conversation just talking about other stuff)
I've had multiple issues with these things, and I have ruled out fixes, but do not remember what I did. I had this with specific games, but fixed it later on (it seemed to be parts of class creation have null parts resolving me into having a crash). I had to add specific checks to multiple places or just purposely remove them to prevent these crashes.