Skip to content

Commit

Permalink
[unity]将ArrayBuffer.Count和ArrayBuffer.Bytes的FieldInfo初始化放到ArrayBuffer…
Browse files Browse the repository at this point in the history
…设置那初始化
  • Loading branch information
chexiongsheng committed Jan 14, 2025
1 parent 18db08e commit cb1a206
Showing 1 changed file with 6 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ static void PApiFree(struct pesapi_ffi* api, void* ptr, void* class_data, void*

static Il2CppClass *g_typeofPersistentObjectInfo;
static Il2CppClass *g_typeofArrayBuffer;
static FieldInfo* g_arrayBufferCountField = nullptr;
static FieldInfo* g_arrayBufferBytesField = nullptr;
static Il2CppClass *g_typeofTypedValue;

static MethodInfoHelper<Il2CppArray*(Il2CppString*)> g_ExtensionMethodGetHelper;
Expand Down Expand Up @@ -535,6 +537,8 @@ void SetGlobalType_ArrayBuffer(Il2CppReflectionType *type)
Exception::Raise(Exception::GetInvalidOperationException("type of ArrayBuffer is null"));
}
g_typeofArrayBuffer = il2cpp_codegen_class_from_type(type->type);
g_arrayBufferCountField = il2cpp_class_get_field_from_name(g_typeofArrayBuffer, "Count");
g_arrayBufferBytesField = il2cpp_class_get_field_from_name(g_typeofArrayBuffer, "Bytes");
}

void SetGlobalType_JSObject(Il2CppReflectionType *type)
Expand Down Expand Up @@ -879,8 +883,6 @@ static void* DelegateCtorCallback(struct pesapi_ffi* apis, pesapi_callback_info
return FunctionToDelegate(apis, env, jsval, classInfo);
}

static FieldInfo* ArrayBufferCountField = nullptr;
static FieldInfo* ArrayBufferBytesField = nullptr;
pesapi_value TryTranslateBuiltin(struct pesapi_ffi* apis, pesapi_env env, Il2CppObject* obj)
{
if (obj)
Expand All @@ -892,16 +894,11 @@ pesapi_value TryTranslateBuiltin(struct pesapi_ffi* apis, pesapi_env env, Il2Cpp
}
if (obj->klass == g_typeofArrayBuffer)
{
if (ArrayBufferBytesField == nullptr || ArrayBufferCountField == nullptr) {
ArrayBufferCountField = il2cpp_class_get_field_from_name(g_typeofArrayBuffer, "Count");
ArrayBufferBytesField = il2cpp_class_get_field_from_name(g_typeofArrayBuffer, "Bytes");
}

int32_t length = 0;
il2cpp_field_get_value(obj, ArrayBufferCountField, &length);
il2cpp_field_get_value(obj, g_arrayBufferCountField, &length);

Il2CppArray* buffer;
il2cpp_field_get_value(obj, ArrayBufferBytesField, &buffer);
il2cpp_field_get_value(obj, g_arrayBufferBytesField, &buffer);

return apis->create_binary(env, Array::GetFirstElementAddress(buffer), (size_t)length);
}
Expand Down

0 comments on commit cb1a206

Please sign in to comment.