少年修仙传客户端基础资源
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
#include "il2cpp-config.h"
#include "Allocator.h"
 
static allocate_func s_Allocator;
 
extern "C"
{
    void register_allocator(allocate_func allocator)
    {
        s_Allocator = allocator;
    }
}
 
void* Allocator::Allocate(size_t size)
{
    IL2CPP_ASSERT(s_Allocator);
    return s_Allocator(size);
}
 
char* Allocator::CopyToAllocatedStringBuffer(const std::string& input)
{
    size_t size = input.size();
    char* buffer = (char*)Allocator::Allocate(size + 1);
    input.copy(buffer, size);
    buffer[size] = '\0';
    return buffer;
}
 
char* Allocator::CopyToAllocatedStringBuffer(const char* input)
{
    size_t size = strlen(input);
    char* buffer = (char*)Allocator::Allocate(size + 1);
    strcpy(buffer, input);
    return buffer;
}
 
void Allocator::CopyStringVectorToNullTerminatedArray(const std::vector<std::string>& input, void*** output)
{
    if (output != NULL)
    {
        size_t numberOfAddresses = input.size();
        *output = (void**)Allocate(sizeof(void*) * (numberOfAddresses + 1));
        for (size_t i = 0; i < numberOfAddresses; ++i)
            (*output)[i] = CopyToAllocatedStringBuffer(input[i].c_str());
 
        (*output)[numberOfAddresses] = NULL;
    }
}
 
void Allocator::CopyDataVectorToNullTerminatedArray(const std::vector<void*>& input, void*** output, int32_t elementSize)
{
    if (output != NULL)
    {
        size_t numberOfEntries = input.size();
        *output = (void**)Allocate(sizeof(void*) * (numberOfEntries + 1));
        for (size_t i = 0; i < numberOfEntries; ++i)
        {
            (*output)[i] = (void*)Allocate(elementSize);
            memcpy((*output)[i], input[i], elementSize);
        }
 
        (*output)[numberOfEntries] = NULL;
    }
}