diff --git a/shared/utils/il2cpp-utils.hpp b/shared/utils/il2cpp-utils.hpp index 1ad01fa2..9be1e73a 100644 --- a/shared/utils/il2cpp-utils.hpp +++ b/shared/utils/il2cpp-utils.hpp @@ -83,6 +83,13 @@ namespace il2cpp_utils { template Il2CppString* newcsstr(std::u16string_view inp) { il2cpp_functions::Init(); + + // if null string input, + // return an empty allocated il2cpp string + if (inp.data() == nullptr) { + return newcsstr(u""); + } + if constexpr (creationType == CreationType::Manual) { auto len = inp.length(); auto mallocSize = sizeof(Il2CppString) + sizeof(Il2CppChar) * (len + 1); @@ -108,6 +115,13 @@ namespace il2cpp_utils { template Il2CppString* newcsstr(std::string_view inp) { il2cpp_functions::Init(); + + // if null string input, + // return an empty allocated il2cpp string + if (inp.data() == nullptr) { + return newcsstr(""); + } + if constexpr (creationType == CreationType::Manual) { // TODO: Perhaps manually call createManual instead auto len = inp.length(); diff --git a/src/utils/typedefs-wrapper.cpp b/src/utils/typedefs-wrapper.cpp index 3ca1c56c..747d62b7 100644 --- a/src/utils/typedefs-wrapper.cpp +++ b/src/utils/typedefs-wrapper.cpp @@ -44,10 +44,19 @@ std::size_t convstr(char16_t const* inp, char* outp, int isz, int osz) { Il2CppString* alloc_str(std::string_view str) { il2cpp_functions::Init(); + + if (str.data() == nullptr) { + return il2cpp_functions::string_new_len("", 0); + } + return il2cpp_functions::string_new_len(str.data(), str.size()); } Il2CppString* alloc_str(std::u16string_view str) { il2cpp_functions::Init(); + if (str.data() == nullptr) { + return il2cpp_functions::string_new_len("", 0); + } + return il2cpp_functions::string_new_utf16((Il2CppChar const*)str.data(), str.size()); }