C++: Fix "fields is not a member of app::String" for some IL2CPP projects

This commit is contained in:
Katy Coe
2021-01-04 04:53:48 +01:00
parent b76d14b113
commit 567b6e1d21

View File

@@ -185,7 +185,7 @@ void il2cppi_new_console() {
freopen_s((FILE**) stdout, "CONOUT$", "w", stdout); freopen_s((FILE**) stdout, "CONOUT$", "w", stdout);
} }
#if _MSC_VER >= 1920 #if _MSC_VER >= 1920
// Helper function to convert Il2CppString to std::string // Helper function to convert Il2CppString to std::string
std::string il2cppi_to_string(Il2CppString* str) { std::string il2cppi_to_string(Il2CppString* str) {
std::u16string u16(reinterpret_cast<const char16_t*>(str->chars)); std::u16string u16(reinterpret_cast<const char16_t*>(str->chars));
@@ -194,8 +194,7 @@ std::string il2cppi_to_string(Il2CppString* str) {
// Helper function to convert System.String to std::string // Helper function to convert System.String to std::string
std::string il2cppi_to_string(app::String* str) { std::string il2cppi_to_string(app::String* str) {
std::u16string u16(reinterpret_cast<const char16_t*>(&str->fields.m_firstChar)); return il2cppi_to_string(reinterpret_cast<Il2CppString*>(str));
return std::wstring_convert<std::codecvt_utf8_utf16<char16_t>, char16_t>{}.to_bytes(u16);
} }
#endif</value> #endif</value>
</data> </data>
@@ -220,7 +219,7 @@ void il2cppi_log_write(std::string text);
// Helper function to open a new console window and redirect stdout there // Helper function to open a new console window and redirect stdout there
void il2cppi_new_console(); void il2cppi_new_console();
#if _MSC_VER >= 1920 #if _MSC_VER &gt;= 1920
// Helper function to convert Il2CppString to std::string // Helper function to convert Il2CppString to std::string
std::string il2cppi_to_string(Il2CppString* str); std::string il2cppi_to_string(Il2CppString* str);