少年修仙传客户端基础资源
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
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
#pragma once
 
#include "il2cpp-config.h"
 
#include "Coff.h"
#include "Tables.h"
 
namespace hybridclr
{
namespace metadata
{
 
    enum class CorILMethodFormat : uint8_t
    {
        Tiny = 0x2,
        Fat = 0x3,
        MoreSects = 0x8,
        InitLocals = 0x10,
    };
 
    enum class CorILSecion : uint8_t
    {
        EHTable = 0x1,
        OptILTable = 0x2,
        FatFormat = 0x40,
        MoreSects = 0x80,
    };
 
    enum class CorILExceptionClauseType
    {
        Exception = 0,
        Filter = 1,
        Finally = 2,
        Fault = 4,
    };
 
    struct CorILMethodFatHeader
    {
        uint16_t flags : 12;
        uint16_t size : 4;
        uint16_t maxStack;
        uint32_t codeSize;
        uint32_t localVarSigToken;
    };
 
    struct CorILEHSmall
    {
        uint16_t flags;
        uint16_t tryOffset;
        uint8_t tryLength;
        uint8_t handlerOffset0;
        uint8_t handlerOffset1;
        uint8_t handlerLength;
        uint32_t classTokenOrFilterOffset;
    };
 
    static_assert(sizeof(CorILEHSmall) == 12, "sizeof(CorILEHSmall) != 12");
 
    struct CorILEHFat
    {
        uint32_t flags;
        uint32_t tryOffset;
        uint32_t tryLength;
        uint32_t handlerOffset;
        uint32_t handlerLength;
        uint32_t classTokenOrFilterOffset;
    };
 
    static_assert(sizeof(CorILEHFat) == 24, "sizeof(CorILEHFat) != 24");
 
    struct CorILEHSectionHeaderSmall
    {
        uint8_t kind;
        uint8_t dataSize;
        uint16_t reserved;
        CorILEHSmall clauses[0];
    };
 
#pragma pack(push, 1)
    struct CorILEHSectionHeaderFat
    {
        uint8_t kind;
        uint8_t dataSize0;
        uint8_t dataSize1;
        uint8_t dataSize2;
        CorILEHFat clauses[0];
    };
#pragma pack(pop)
 
    const int MAX_TABLE_INDEX = 0x2C;
    const int TABLE_NUM = MAX_TABLE_INDEX + 1;
 
    class TagBits
    {
    public:
        static const uint32_t TypeDefOrRef = 2;
        static const uint32_t HasConstant = 2;
        static const uint32_t HasCustomAttribute = 5;
        static const uint32_t HasFieldMarshal = 1;
        static const uint32_t HasDeclSecurity = 2;
        static const uint32_t MemberRefParent = 3;
        static const uint32_t HasSemantics = 1;
        static const uint32_t MethodDefOrRef = 1;
        static const uint32_t MemberForwarded = 1;
        static const uint32_t Implementation = 2;
        static const uint32_t CustomAttributeType = 3;
        static const uint32_t ResoulutionScope = 2;
        static const uint32_t TypeOrMethodDef = 1;
 
    };
 
 
    const TableType HasCustomAttributeAssociateTables[] = {
        TableType::METHOD,
        TableType::FIELD,
        TableType::TYPEREF,
        TableType::TYPEDEF,
        TableType::PARAM,
        TableType::INTERFACEIMPL,
        TableType::MEMBERREF,
        TableType::MODULE,
        TableType::DECLSECURITY,
        TableType::PROPERTY,
        TableType::EVENT,
        TableType::STANDALONESIG,
        TableType::MODULEREF,
        TableType::TYPESPEC,
        TableType::ASSEMBLY,
        TableType::ASSEMBLYREF,
        TableType::FILE,
        TableType::EXPORTEDTYPE,
        TableType::MANIFESTRESOURCE,
        TableType::GENERICPARAM,
        TableType::GENERICPARAMCONSTRAINT,
        TableType::METHODSPEC,
    };
 
    inline TableType DecodeTokenTableType(uint32_t index)
    {
        return TableType(index >> 24);
    }
 
    inline uint32_t DecodeTokenRowIndex(uint32_t index)
    {
        return index & 0xFFFFFF;
    }
 
    struct ColumnOffsetSize
    {
        uint32_t size;
        uint16_t offset;
    };
 
    enum class SigType
    {
        DEFAULT = 0,
        C = 1,
        ST_STDCALL = 2,
        ST_THISCALL = 3,
        ST_FASTCALL = 4,
        VARARG = 5,
        FIELD = 6,
        LOCAL_VAR = 7,
        PROPERTY_NOT_THIS = 8,
        GENERIC = 0x10,
        SENTINEL = 0x41,
    };
 
    const uint32_t kSigMask = 0x0F;
 
    inline SigType DecodeSigType(uint8_t rawSigType)
    {
        return (SigType)(rawSigType & kSigMask);
    }
 
    inline uint8_t DecodeSigFlags(uint8_t rawSigType)
    {
        return (uint8_t)(rawSigType & 0xF0);
    }
 
    inline uint32_t EncodeToken(TableType type, uint32_t index)
    {
        return ((uint32_t)type << 24) | index;
    }
 
    inline void DecodeToken(uint32_t token, TableType& type, uint32_t& rowIndex)
    {
        type = (TableType)(token >> 24);
        rowIndex = token & 0xFFFFFF;
    }
 
    enum class MethodSigFlags
    {
        HAS_THIS = 0x20,
        EXPLICITTHIS = 0x40,
        DEFAULT = 0x0,
        VARARG = 0x5,
        GENERIC = 0x10,
    };
 
    inline Il2CppTypeEnum GetElementType(Il2CppTypeEnum encodeType)
    {
        return (Il2CppTypeEnum)((uint8_t)encodeType & 0x3f);
    }
 
    inline TableType DecodeTypeDefOrRefOrSpecCodedIndexTableType(uint32_t encodedToken)
    {
        switch (encodedToken & 0x3)
        {
        case 0: return TableType::TYPEDEF;
        case 1: return TableType::TYPEREF;
        case 2: return  TableType::TYPESPEC;
        default: IL2CPP_ASSERT(false); return (TableType)-1;
        }
    }
 
    inline uint32_t DecodeTypeDefOrRefOrSpecCodedIndexRowIndex(uint32_t encodedToken)
    {
        return encodedToken >> 2;
    }
 
    inline uint32_t EncodeTypeDefOrRefOrSpecCodedIndex(TableType type, uint32_t rowIndex)
    {
        uint32_t tableBits;
        switch (type)
        {
        case TableType::TYPEDEF: tableBits = 0; break;
        case TableType::TYPEREF: tableBits = 1; break;
        case TableType::TYPESPEC: tableBits = 2; break;
        default: IL2CPP_ASSERT(0); tableBits = 0; break;
        }
        return (rowIndex << 2) | tableBits;
    }
 
    inline uint32_t ConvertTypeDefOrRefOrSpecToken2CodedIndex(uint32_t token)
    {
        TableType type;
        uint32_t rowIndex;
        DecodeToken(token, type, rowIndex);
 
        uint32_t tableBits;
        switch (type)
        {
        case TableType::TYPEDEF: tableBits = 0; break;
        case TableType::TYPEREF: tableBits = 1; break;
        case TableType::TYPESPEC: tableBits = 2; break;
        default: IL2CPP_ASSERT(0); tableBits = 0; break;
        }
        return (rowIndex << 2) | tableBits;
    }
 
    inline void DecodeResolutionScopeCodedIndex(uint32_t encodedToken, TableType& tokenType, uint32_t& rawIndex)
    {
        switch (encodedToken & 0x3)
        {
        case 0: tokenType = TableType::MODULE; break;
        case 1: tokenType = TableType::MODULEREF; break;
        case 2: tokenType = TableType::ASSEMBLYREF; break;
        case 3: tokenType = TableType::TYPEREF; break;
        }
        rawIndex = encodedToken >> 2;
    }
 
    inline TableType DecodeTypeOrMethodDefCodedIndexTableType(uint32_t encodeIndex)
    {
        switch (encodeIndex & 0x1)
        {
        case 0: return TableType::TYPEDEF;
        case 1: return TableType::METHOD;
        }
        IL2CPP_ASSERT(false);
        return (TableType)-1;
    }
 
    inline uint32_t DecodeTypeOrMethodDefCodedIndexRowIndex(uint32_t encodeIndex)
    {
        return encodeIndex >> 1;
    }
 
    inline TableType DecodeMethodDefOrRefCodedIndexTableType(uint32_t token)
    {
        switch (token & 0x1)
        {
        case 0: return TableType::METHOD;
        case 1: return TableType::MEMBERREF;
        }
        return (TableType)-1;
    }
 
    inline uint32_t DecodeMethodDefOrRefCodedIndexRowIndex(uint32_t token)
    {
        return token >> 1;
    }
 
    inline uint32_t EncodeMethodDefOrRefCodedIndex(TableType type, uint32_t rowIndex)
    {
        IL2CPP_ASSERT(type == TableType::METHOD || type == TableType::MEMBERREF);
        return (rowIndex << 1) | (type != TableType::METHOD);
    }
 
    inline uint32_t ConvertMethodDefOrRefToken2CodedIndex(uint32_t token)
    {
        TableType type;
        uint32_t rowIndex;
        DecodeToken(token, type, rowIndex);
        return EncodeMethodDefOrRefCodedIndex(type, rowIndex);
    }
 
    inline TableType DecodeMemberRefParentType(uint32_t token)
    {
        switch (token & 0x7)
        {
        case 0: return TableType::TYPEDEF;
        case 1: return TableType::TYPEREF;
        case 2: return TableType::MODULEREF;
        case 3: return TableType::METHOD;
        case 4: return TableType::TYPESPEC;
        default: IL2CPP_ASSERT(false); return (TableType)-1;
        }
    }
 
    inline uint32_t DecodeMemberRefParentRowIndex(uint32_t token)
    {
        return token >> 3;
    }
 
    inline TableType DecodeFieldDefOrDefType(uint32_t encodeIndex)
    {
        switch (encodeIndex & 0x1)
        {
        case 0: return TableType::FIELD;
        case 1: return TableType::MEMBERREF;
        }
        return (TableType)-1;
    }
 
    inline uint32_t DecodeFieldDefOrDefTypeRowIndex(uint32_t encodeIndex)
    {
        return encodeIndex >> 1;
    }
 
    inline uint32_t EncodeFieldDefOrRefCodedIndex(TableType type, uint32_t rowIndex)
    {
        IL2CPP_ASSERT(type == TableType::FIELD || type == TableType::MEMBERREF);
        return (rowIndex << 1) | (type != TableType::FIELD);
    }
 
    inline uint32_t ConvertFieldDefOrRefToken2CodedIndex(uint32_t token)
    {
        TableType type;
        uint32_t rowIndex;
        DecodeToken(token, type, rowIndex);
        return EncodeFieldDefOrRefCodedIndex(type, rowIndex);
    }
 
    inline TableType DecodeMemberRefParentCodedIndexTableType(uint32_t encodeIndex)
    {
        switch ((encodeIndex & 0x7))
        {
        case 0: return TableType::TYPEDEF;
        case 1: return TableType::TYPEREF;
        case 2: return TableType::MODULEREF;
        case 3: return TableType::METHOD;
        case 4: return TableType::TYPESPEC;
        default: IL2CPP_ASSERT(false); return (TableType)-1;
        }
    }
 
    inline uint32_t DecodeMemberRefParentCodedIndexRowIndex(uint32_t encodeIndex)
    {
        return encodeIndex >> 3;
    }
 
    inline TableType DecodeHasCustomAttributeCodedIndexTableType(uint32_t codedIndex)
    {
        switch (codedIndex & 0x1f)
        {
        case 0: return TableType::METHOD;
        case 1: return TableType::FIELD;
        case 2: return TableType::TYPEREF;
        case 3: return TableType::TYPEDEF;
        case 4: return TableType::PARAM;
        case 5: return TableType::INTERFACEIMPL;
        case 6: return TableType::MEMBERREF;
        case 7: return TableType::MODULE;
        case 8: return TableType::DECLSECURITY;
        case 9: return TableType::PROPERTY;
        case 10: return TableType::EVENT;
        case 11: return TableType::STANDALONESIG;
        case 12: return TableType::MODULEREF;
        case 13: return TableType::TYPESPEC;
        case 14: return TableType::ASSEMBLY;
        case 15: return TableType::ASSEMBLYREF;
        case 16: return TableType::FILE;
        case 17: return TableType::EXPORTEDTYPE;
        case 18: return TableType::MANIFESTRESOURCE;
        case 19: return TableType::GENERICPARAM;
        case 20: return TableType::GENERICPARAMCONSTRAINT;
        case 21: return TableType::METHODSPEC;
        default: IL2CPP_ASSERT(false); return (TableType)-1;
        }
    }
 
    inline uint32_t DecodeHasCustomAttributeCodedIndexRowIndex(uint32_t codedIndex)
    {
        return codedIndex >> 5;
    }
 
    inline TableType DecodeCustomAttributeTypeCodedIndexTableType(uint32_t codeIndex)
    {
        switch (codeIndex & 0x7)
        {
        case 2: return TableType::METHOD;
        case 3: return TableType::MEMBERREF;
        default: IL2CPP_ASSERT(false); return (TableType)-1;
        }
    }
 
    inline uint32_t DecodeCustomAttributeTypeCodedIndexRowIndex(uint32_t codedIndex)
    {
        return codedIndex >> 3;
    }
 
    enum class UserStringEncoding
    {
        ASCII = 0,
        Unicode = 1,
    };
 
    struct ExceptionClause
    {
        CorILExceptionClauseType flags;
        uint32_t tryOffset;
        uint32_t tryLength;
        uint32_t handlerOffsets;
        uint32_t handlerLength;
        uint32_t classTokenOrFilterOffset;
    };
 
    struct MethodBody
    {
        uint32_t flags;
        uint32_t codeSize;
        const uint8_t* ilcodes;
        Il2CppType* localVars;
        uint32_t localVarCount;
        uint32_t maxStack;
        std::vector<ExceptionClause> exceptionClauses;
        // optional data sections
    };
 
 
 
    struct MethodRefInfo
    {
        Il2CppType containerType; // maybe generic
        const Il2CppMethodDefinition* methodDef;
        const Il2CppGenericInst* instantiation;
    };
 
    struct MethodImpl
    {
        MethodRefInfo body;
        MethodRefInfo declaration;
    };
 
    struct MethodDefSig
    {
        Il2CppType classType;
        const char* name;
        uint32_t flags;
        uint32_t genericParamCount;
        Il2CppType returnType;
        std::vector<Il2CppType> params;
    };
 
    struct MethodRefSig
    {
        uint32_t flags;
        uint32_t genericParamCount;
        Il2CppType returnType;
        std::vector<Il2CppType> params;
    };
 
    struct FieldRefSig
    {
        Il2CppType type;
    };
 
    struct FieldRefInfo
    {
        Il2CppType containerType; // maybe generic
        const Il2CppFieldDefinition* field;
    };
 
    struct ResolveModuleRef
    {
 
    };
 
    struct ResolveMethodDef
    {
        const Il2CppMethodDefinition* methodDef;
    };
 
    struct ResolveMemberRefParent
    {
        TableType parentType;
        Il2CppType type; // TYPEREF, TYPEDEF,TYPESPEC
        ResolveModuleRef moduleRef;
        ResolveMethodDef methodDef;
    };
 
    struct ResolveMemberRefSig
    {
        TableType memberType; // FIELD_POINTER OR METHOD_POINTER
        MethodRefSig method;
        FieldRefSig field;
    };
 
    struct ResolveMemberRef
    {
        ResolveMemberRefParent parent;
        const char* name;
        ResolveMemberRefSig signature;
    };
 
    struct MemberRefInfo
    {
        TableType memberType;
        MethodRefInfo method;
        FieldRefInfo field;
    };
 
    struct ResolveStandAloneMethodSig
    {
        int32_t flags;
        uint32_t paramCount;
        Il2CppType returnType;
        Il2CppType* params;
    };
 
    inline TableType DecodeHasConstantType(uint32_t token)
    {
        switch (token & 0x3)
        {
        case 0: return TableType::FIELD;
        case 1: return TableType::PARAM;
        case 2: return TableType::PROPERTY;
        default: IL2CPP_ASSERT(false); return (TableType)-1;
            break;
        }
    }
 
    inline uint32_t DecodeHashConstantIndex(uint32_t token)
    {
        return token >> 2;
    }
 
    enum class MethodSemanticsAttributes
    {
        Setter = 0x1,
        Getter = 0x2,
        Other = 0x4,
        AddOn = 0x8,
        RemoveOn = 0x10,
        Fire = 0x20,
    };
 
    inline TableType DecodeHasSemanticsCodedIndexTableType(uint32_t codedIndex)
    {
        switch (codedIndex & 0x1)
        {
        case 0: return TableType::EVENT;
        case 1: return TableType::PROPERTY;
        }
        return (TableType)-1;
    }
 
    inline uint32_t DecodeHasSemanticsCodedIndexRowIndex(uint32_t codedIndex)
    {
        return codedIndex >> 1;
    }
}
}