It shows how to handle il2cpp exceptions.
#include <BNM/Exceptions.hpp>
#include <BNM/Method.hpp>
void (*old_Start)(void *);
void Start(void *instance) {
old_Start(instance);
int result;
result = DangerMethod[instance]();
auto className = exception.ClassName();
auto message = exception.Message();
BNM_LOG_WARN("DangerMethod returned exception (in try catch) [%s]: %s", className.c_str(), message.c_str());
result = -1;
result = DangerMethod[instance]();
});
if (exception.IsValid()) {
auto className = exception.ClassName();
auto message = exception.Message();
BNM_LOG_WARN("DangerMethod returned exception (in TryInvoke) [%s]: %s", className.c_str(), message.c_str());
result = -1;
}
if (result == -1) {}
}
void OnLoaded_Example_08() {
auto cls =
BNM::Class(BNM_OBFUSCATE(
"Example"), BNM_OBFUSCATE(
"Example"));
DangerMethod = cls.GetMethod(BNM_OBFUSCATE("DangerMethod"));
}
#define BNM_catch(ex)
Define block to handle exceptions.
Definition Exceptions.hpp:100
#define BNM_end_try
End BNM_try or BNM_try&BNM_catch blocks.
Definition Exceptions.hpp:108
#define BNM_try
Define danger code block.
Definition Exceptions.hpp:90
Exception TryInvoke(const std::function< void()> &func)
Helper function for catching il2cpp errors.
bool InvokeHook(const BNM::MethodBase &targetMethod, T_NEW newMet, T_OLD &oldMet)
Hook method by changing MethodInfo.
Definition MethodBase.hpp:172
Class for working with il2cpp classes.
Definition Class.hpp:29
Typed class for working with il2cpp methods.
Definition Method.hpp:20