少年修仙传客户端基础资源
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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
#pragma once
 
#include "InterpreterImage.h"
#include "AOTHomologousImage.h"
#include "Assembly.h"
 
namespace hybridclr
{
 
namespace metadata
{
    struct ReversePInvokeInfo
    {
        int32_t index;
        Il2CppMethodPointer methodPointer;
        const MethodInfo* methodInfo;
    };
 
    class MetadataModule
    {
    public:
 
        static void Initialize();
 
        static InterpreterImage* GetImage(uint32_t imageIndex)
        {
            return InterpreterImage::GetImage(imageIndex);
        }
 
        static InterpreterImage* GetImage(const Il2CppImage* image)
        {
            return GetImage(DecodeImageIndex(image->token));
        }
 
        static InterpreterImage* GetImage(const Il2CppClass* klass)
        {
            return GetImage(klass->image);
        }
 
        static InterpreterImage* GetImage(const Il2CppTypeDefinition* typeDef)
        {
            return GetImage(DecodeImageIndex(typeDef->byvalTypeIndex));
        }
 
        static InterpreterImage* GetImage(const Il2CppMethodDefinition* method)
        {
            return GetImage(DecodeImageIndex(method->nameIndex));
        }
 
        static InterpreterImage* GetImage(const MethodInfo* method)
        {
            return GetImage(method->klass->image);
        }
 
        static InterpreterImage* GetImageByEncodedIndex(uint32_t encodedIndex)
        {
            return GetImage(DecodeImageIndex(encodedIndex));
        }
 
        static const char* GetStringFromEncodeIndex(StringIndex index)
        {
            uint32_t imageIndex = DecodeImageIndex(index);
            return GetImage(imageIndex)->GetStringFromRawIndex(DecodeMetadataIndex(index));
        }
 
        static uint32_t GetTypeEncodeIndex(const Il2CppTypeDefinition* typeDef)
        {
            InterpreterImage* image = GetImage(typeDef);
            return hybridclr::metadata::EncodeImageAndMetadataIndex(image->GetIndex(), image->GetTypeRawIndex(typeDef));
        }
 
        static Il2CppMetadataTypeHandle GetAssemblyTypeHandleFromRawIndex(const Il2CppImage* image, AssemblyTypeIndex index)
        {
            return GetImage(image)->GetAssemblyTypeHandleFromRawIndex(index);
        }
 
        static Il2CppMetadataTypeHandle GetAssemblyTypeHandleFromEncodeIndex(AssemblyTypeIndex index)
        {
            uint32_t imageIndex = DecodeImageIndex(index);
            return GetImage(imageIndex)->GetAssemblyTypeHandleFromRawIndex(DecodeMetadataIndex(index));
        }
 
        static Il2CppMetadataTypeHandle GetAssemblyExportedTypeHandleFromEncodeIndex(AssemblyTypeIndex index)
        {
            uint32_t imageIndex = DecodeImageIndex(index);
            return GetImage(imageIndex)->GetAssemblyExportedTypeHandleFromRawIndex(DecodeMetadataIndex(index));
        }
 
        static const Il2CppTypeDefinitionSizes* GetTypeDefinitionSizesFromEncodeIndex(TypeDefinitionIndex index)
        {
            uint32_t imageIndex = DecodeImageIndex(index);
            return GetImage(imageIndex)->GetTypeDefinitionSizesFromRawIndex(DecodeMetadataIndex(index));
        }
 
        static const Il2CppType* GetIl2CppTypeFromEncodeIndex(uint32_t index)
        {
            uint32_t imageIndex = DecodeImageIndex(index);
            IL2CPP_ASSERT(imageIndex > 0);
 
            uint32_t rawIndex = DecodeMetadataIndex(index);
            return GetImage(imageIndex)->GetIl2CppTypeFromRawIndex(rawIndex);
        }
 
        static Il2CppClass* GetTypeInfoFromTypeDefinitionEncodeIndex(TypeDefinitionIndex index)
        {
            uint32_t imageIndex = DecodeImageIndex(index);
            IL2CPP_ASSERT(imageIndex > 0);
 
            uint32_t rawIndex = DecodeMetadataIndex(index);
            return GetImage(imageIndex)->GetTypeInfoFromTypeDefinitionRawIndex(rawIndex);
        }
 
        static const Il2CppFieldDefinition* GetFieldDefinitionFromEncodeIndex(uint32_t index)
        {
            uint32_t imageIndex = DecodeImageIndex(index);
            return GetImage(imageIndex)->GetFieldDefinitionFromRawIndex(DecodeMetadataIndex(index));
        }
 
        static const Il2CppMethodDefinition* GetMethodDefinitionFromIndex(MethodIndex index)
        {
            uint32_t imageIndex = DecodeImageIndex(index);
            return GetImage(imageIndex)->GetMethodDefinitionFromRawIndex(DecodeMetadataIndex(index));
        }
 
        static uint32_t GetFieldOffset(const Il2CppClass* klass, int32_t fieldIndexInType, FieldInfo* field)
        {
            return GetImage(klass)->GetFieldOffset(klass, fieldIndexInType);
        }
 
        static const MethodInfo* GetMethodInfoFromMethodDefinitionIndex(uint32_t index)
        {
            uint32_t imageIndex = DecodeImageIndex(index);
            return GetImage(imageIndex)->GetMethodInfoFromMethodDefinitionRawIndex(DecodeMetadataIndex(index));
        }
 
        static const MethodInfo* GetMethodInfoFromMethodDefinition(const Il2CppMethodDefinition* methodDef)
        {
            uint32_t imageIndex = DecodeImageIndex(methodDef->nameIndex);
            return GetImage(imageIndex)->GetMethodInfoFromMethodDefinition(methodDef);
        }
 
        static const MethodInfo* GetMethodInfoFromVTableSlot(const Il2CppClass* klass, int32_t vTableSlot)
        {
            return GetImage(klass)->GetMethodInfoFromVTableSlot(klass, vTableSlot);
        }
 
        static const Il2CppMethodDefinition* GetMethodDefinitionFromVTableSlot(const Il2CppTypeDefinition* typeDefine, int32_t vTableSlot)
        {
            return GetImage(typeDefine)->GetMethodDefinitionFromVTableSlot(typeDefine, vTableSlot);
        }
 
        static Il2CppMethodPointer GetAdjustorThunk(const Il2CppImage* image, uint32_t token)
        {
            uint32_t imageIndex = DecodeImageIndex(image->token);
            return GetImage(imageIndex)->GetAdjustorThunk(token);
        }
 
        static Il2CppMethodPointer GetMethodPointer(const Il2CppImage* image, uint32_t token)
        {
            uint32_t imageIndex = DecodeImageIndex(image->token);
            return GetImage(imageIndex)->GetMethodPointer(token);
        }
 
        static InvokerMethod GetMethodInvoker(const Il2CppImage* image, uint32_t token)
        {
            uint32_t imageIndex = DecodeImageIndex(image->token);
            return GetImage(imageIndex)->GetMethodInvoker(token);
        }
 
        static const Il2CppParameterDefinition* GetParameterDefinitionFromIndex(const Il2CppImage* image, ParameterIndex index)
        {
            uint32_t imageIndex = DecodeImageIndex(image->token);
            return GetImage(imageIndex)->GetParameterDefinitionFromIndex(index);
        }
 
        static const Il2CppType* GetInterfaceFromIndex(const Il2CppClass* klass, TypeInterfaceIndex index)
        {
            return GetImage(klass)->GetInterfaceFromIndex(klass, index);
        }
 
        static const Il2CppType* GetInterfaceFromOffset(const Il2CppClass* klass, TypeInterfaceIndex offset)
        {
            return GetImage(klass)->GetInterfaceFromOffset(klass, offset);
        }
 
        static const Il2CppType* GetInterfaceFromOffset(const Il2CppTypeDefinition* typeDefine, TypeInterfaceIndex offset)
        {
            return GetImage(typeDefine)->GetInterfaceFromOffset(typeDefine, offset);
        }
 
        static Il2CppInterfaceOffsetInfo GetInterfaceOffsetInfo(const Il2CppTypeDefinition* typeDefine, TypeInterfaceOffsetIndex index)
        {
            return GetImage(typeDefine)->GetInterfaceOffsetInfo(typeDefine, index);
        }
 
        static Il2CppClass* GetNestedTypeFromOffset(const Il2CppClass* klass, TypeNestedTypeIndex offset)
        {
            return GetImage(klass)->GetNestedTypeFromOffset(klass, offset);
        }
 
        static Il2CppClass* GetNestedTypeFromOffset(const Il2CppTypeDefinition* typeDefinition, TypeNestedTypeIndex offset)
        {
            return GetImage(typeDefinition)->GetNestedTypeFromOffset(typeDefinition, offset);
        }
 
        static Il2CppMetadataTypeHandle GetNestedTypes(Il2CppMetadataTypeHandle handle, void** iter)
        {
            Il2CppTypeDefinition* typeDef = (Il2CppTypeDefinition*)handle;
            return (Il2CppMetadataTypeHandle)(GetImage(typeDef)->GetNestedTypes(typeDef, iter));
        }
 
        static const Il2CppGenericContainer* GetGenericContainerFromEncodeIndex(uint32_t index)
        {
            return GetImage(DecodeImageIndex(index))->GetGenericContainerByRawIndex(DecodeMetadataIndex(index));
 
        }
 
        static const Il2CppFieldDefaultValue* GetFieldDefaultValueEntry(uint32_t index)
        {
            return GetImage(DecodeImageIndex(index))->GetFieldDefaultValueEntryByRawIndex(DecodeMetadataIndex(index));
        }
 
        static const uint8_t* GetFieldOrParameterDefalutValue(uint32_t index)
        {
            return GetImage(DecodeImageIndex(index))->GetFieldOrParameterDefalutValueByRawIndex(DecodeMetadataIndex(index));
        }
 
#if HYBRIDCLR_UNITY_2020
        static bool HasAttribute(const Il2CppImage* image, uint32_t token, Il2CppClass* attribute)
        {
            return GetImage(image)->HasAttributeByToken(token, attribute);
        }
 
        static std::tuple<void*, void*> GetCustomAttributeDataRange(const Il2CppImage* image, uint32_t token)
        {
            return GetImage(image)->GetCustomAttributeDataRange(token);
        }
#endif
 
        static bool IsImplementedByInterpreter(MethodInfo* method)
        {
            Il2CppClass* klass = method->klass;
            Il2CppClass* parent = klass->parent;
            if (parent != il2cpp_defaults.multicastdelegate_class && parent != il2cpp_defaults.delegate_class)
            {
                return AOTHomologousImage::FindImageByAssembly(klass->image->assembly);
            }
            else
            {
                return strcmp(method->name, "Invoke") == 0;
            }
        }
 
        static Il2CppMethodPointer GetReversePInvokeWrapper(const Il2CppImage* image, const MethodInfo* method);
 
        static const MethodInfo* GetMethodInfoByReversePInvokeWrapperIndex(int32_t index)
        {
            return s_reverseInfos[index].methodInfo;
        }
 
        static const MethodInfo* GetMethodInfoByReversePInvokeWrapperMethodPointer(Il2CppMethodPointer methodPointer)
        {
            auto it = s_methodPointer2ReverseInfos.find(methodPointer);
            return it != s_methodPointer2ReverseInfos.end() ? it->second->methodInfo : nullptr;
        }
 
        static int32_t GetWrapperIndexByReversePInvokeWrapperMethodPointer(Il2CppMethodPointer methodPointer)
        {
            auto it = s_methodPointer2ReverseInfos.find(methodPointer);
            return it != s_methodPointer2ReverseInfos.end() ? it->second->index : -1;
        }
 
        static LoadImageErrorCode LoadMetadataForAOTAssembly(const void* dllBytes, uint32_t dllSize, HomologousImageMode mode);
    private:
        static void InitReversePInvokeInfo();
 
        static Il2CppHashMap<const char*, int32_t, CStringHash, CStringEqualTo> s_methodSig2Indexs;
        static Il2CppHashMap<const MethodInfo*, const ReversePInvokeInfo*, il2cpp::utils::PointerHash<MethodInfo>> s_methodInfo2ReverseInfos;
        static Il2CppHashMap<Il2CppMethodPointer, const ReversePInvokeInfo*, il2cpp::utils::PassThroughHash<Il2CppMethodPointer>> s_methodPointer2ReverseInfos;
        static std::vector<ReversePInvokeInfo> s_reverseInfos;
    };
}
 
}