From f8cb6da218c821fafc9e3ea1d4c04e788b60455e Mon Sep 17 00:00:00 2001 From: Timo Schwarzer Date: Tue, 3 Sep 2024 12:27:06 +0200 Subject: [PATCH] Add API to attach native threads to the il2cpp domain --- projects/Modloader/il2cpp_helpers.cpp | 4 ++++ projects/Modloader/il2cpp_helpers.h | 2 ++ 2 files changed, 6 insertions(+) diff --git a/projects/Modloader/il2cpp_helpers.cpp b/projects/Modloader/il2cpp_helpers.cpp index 40754a9700..832e9665f5 100644 --- a/projects/Modloader/il2cpp_helpers.cpp +++ b/projects/Modloader/il2cpp_helpers.cpp @@ -929,6 +929,10 @@ namespace il2cpp { std::string get_class_namespace(Il2CppClass* klass) { return {il2cpp_class_get_namespace(klass)}; } + void attach_thread() { + il2cpp_thread_attach(il2cpp_domain_get()); + } + /** * Converts a C# string to std::string by truncating characters. * May lose special characters. diff --git a/projects/Modloader/il2cpp_helpers.h b/projects/Modloader/il2cpp_helpers.h index dd271fa944..7ff9ade459 100644 --- a/projects/Modloader/il2cpp_helpers.h +++ b/projects/Modloader/il2cpp_helpers.h @@ -188,6 +188,8 @@ namespace il2cpp { IL2CPP_MODLOADER_DLLEXPORT std::string get_class_namespace(Il2CppClass* klass); + IL2CPP_MODLOADER_DLLEXPORT void attach_thread(); + template Return* get_class(std::string_view namezpace, std::string_view name) { return reinterpret_cast(untyped::get_class(namezpace, name));