少年修仙传客户端基础资源
hch
2024-04-01 d01413b00ef631ac20347716b23818b0b811f65f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
#include "il2cpp-config.h"
#include "il2cpp-class-internals.h"
#include "icalls/mscorlib/System.Runtime.InteropServices/GCHandle.h"
#include "gc/GCHandle.h"
#include "vm/Class.h"
#include "vm/Exception.h"
#include "vm/GenericClass.h"
#include "vm/Type.h"
 
namespace il2cpp
{
namespace icalls
{
namespace mscorlib
{
namespace System
{
namespace Runtime
{
namespace InteropServices
{
    bool GCHandle::CheckCurrentDomain(int32_t handle)
    {
        return true; // il2cpp doesn't support multiple domains
    }
 
    void GCHandle::FreeHandle(int32_t handle)
    {
        gc::GCHandle::Free(handle);
    }
 
// Returns -2 if gchandle is not pinned
    intptr_t GCHandle::GetAddrOfPinnedObject(int32_t handle)
    {
        gc::GCHandleType type = gc::GCHandle::GetHandleType(handle);
 
        if (type != gc::HANDLE_PINNED)
            return reinterpret_cast<intptr_t>(reinterpret_cast<uint8_t*>(-2)); // mscorlib on managed land expects us to return "-2" as IntPtr if this condition occurs
 
        Il2CppObject* obj = gc::GCHandle::GetTarget(handle);
        if (obj == NULL)
            return 0;
 
        ptrdiff_t offset;
 
        if (obj->klass->rank > 0)
        {
            // Pointer to first array element
            offset = kIl2CppSizeOfArray;
        }
        else if (obj->klass->byval_arg.type == IL2CPP_TYPE_STRING)
        {
            // Pointer to first character
            offset = offsetof(Il2CppString, chars);
        }
        else
        {
            // Pointer to struct in boxed object
            offset = sizeof(Il2CppObject);
        }
 
        return reinterpret_cast<intptr_t>((reinterpret_cast<uint8_t*>(obj) + offset));
    }
 
    Il2CppObject* GCHandle::GetTarget(int32_t handle)
    {
        return gc::GCHandle::GetTarget(handle);
    }
 
    static bool IsTypePinnable(Il2CppClass* klass)
    {
        const Il2CppType* il2cppType = vm::Class::GetType(klass);
        if (il2cppType->type == IL2CPP_TYPE_ARRAY || il2cppType->type == IL2CPP_TYPE_SZARRAY)
        {
            Il2CppClass* elementClass = klass->element_class;
            if (elementClass->byval_arg.type == IL2CPP_TYPE_STRING ||
                elementClass->byval_arg.type == IL2CPP_TYPE_ARRAY ||
                elementClass->byval_arg.type == IL2CPP_TYPE_SZARRAY)
            {
                return false;
            }
 
            return IsTypePinnable(elementClass); // Note the recursive call here
        }
 
        if (il2cppType->type == IL2CPP_TYPE_CHAR  || il2cppType->type == IL2CPP_TYPE_BOOLEAN || il2cppType->type == IL2CPP_TYPE_STRING)
            return true;
 
        return klass->is_blittable;
    }
 
    static inline bool IsObjectPinnable(Il2CppObject* obj)
    {
        if (obj == NULL)
            return true;
 
        return IsTypePinnable(obj->klass);
    }
 
    int32_t GCHandle::GetTargetHandle(Il2CppObject* obj, int32_t handle, int32_t type)
    {
        if (type == gc::HANDLE_PINNED && !IsObjectPinnable(obj))
        {
            Il2CppException* ex = vm::Exception::GetArgumentException(NULL, "Object contains non-primitive or non-blittable data.");
            vm::Exception::Raise(ex);
        }
 
        return gc::GCHandle::GetTargetHandle(obj, handle, type);
    }
} /* namespace InteropServices */
} /* namespace Runtime */
} /* namespace System */
} /* namespace mscorlib */
} /* namespace icalls */
} /* namespace il2cpp */