少年修仙传客户端基础资源
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
#pragma once
 
#include <vector>
 
#include "MetadataUtil.h"
 
namespace hybridclr
{
namespace metadata
{
 
    struct FieldLayout
    {
        const Il2CppType* type;
        int32_t offset;
        int32_t size;
        bool isNormalStatic;
        bool isThreadStatic;
    };
 
    struct ClassLayoutInfo
    {
        const Il2CppType* type;
        std::vector<FieldLayout> fields;
        int32_t instanceSize;
        int32_t actualSize;
        int32_t nativeSize;
        uint32_t staticFieldsSize;
        uint32_t threadStaticFieldsSize;
        uint8_t alignment;
#if !HYBRIDCLR_UNITY_2022_OR_NEW
        uint8_t naturalAlignment;
#endif
    };
 
    struct SizeAndAlignment
    {
        int32_t size;
        int32_t nativeSize;
        uint8_t alignment;
#if !HYBRIDCLR_UNITY_2022_OR_NEW
        uint8_t naturalAlignment;
#endif
    };
 
    struct FieldLayoutData
    {
        std::vector<size_t> FieldOffsets;
        int32_t classSize;
        int32_t actualClassSize;
        int32_t nativeSize;
        
        uint8_t minimumAlignment;
#if !HYBRIDCLR_UNITY_2022_OR_NEW
        uint8_t naturalAlignment;
#endif
    };
 
    class InterpreterImage;
 
    typedef Il2CppHashMap<const Il2CppType*, ClassLayoutInfo*, Il2CppTypeHash, Il2CppTypeEqualTo> Il2CppType2ClassLayoutInfoMap;
 
    class ClassFieldLayoutCalculator
    {
    private:
        InterpreterImage* _image;
        Il2CppType2ClassLayoutInfoMap _classMap;
 
    public:
        ClassFieldLayoutCalculator(InterpreterImage* image) : _image(image)
        {
 
        }
 
        ~ClassFieldLayoutCalculator()
        {
            for (auto it : _classMap)
            {
                HYBRIDCLR_FREE(it.second);
            }
        }
 
        ClassLayoutInfo* GetClassLayoutInfo(const Il2CppType* type)
        {
            auto it = _classMap.find(type);
            return it != _classMap.end() ? it->second : nullptr;
        }
 
        void CalcClassNotStaticFields(const Il2CppType* type);
        void CalcClassStaticFields(const Il2CppType* type);
 
        void LayoutFields(int32_t actualParentSize, int32_t parentAlignment, uint8_t packing, std::vector<FieldLayout*>& fields, FieldLayoutData& data);
        SizeAndAlignment GetTypeSizeAndAlignment(const Il2CppType* type);
    };
}
}