少年修仙传客户端基础资源
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
#include "il2cpp-config.h"
#include "il2cpp-vm-support.h"
 
#if !IL2CPP_USE_GENERIC_ENVIRONMENT && IL2CPP_TARGET_POSIX && !IL2CPP_TARGET_PS4 && !IL2CPP_TARGET_PS5
#include "il2cpp-class-internals.h"
#include "os/Environment.h"
#include "il2cpp-api.h"
 
#include <stdlib.h>
#include <unistd.h>
#include <sys/utsname.h>
 
#if defined(__APPLE__) && !defined(__arm__)
// Apple defines this in crt_externs.h but doesn't provide that header for
// arm-apple-darwin9.  We'll manually define the symbol on Apple as it does
// in fact exist on all implementations (so far)
extern "C" char*** _NSGetEnviron(void);
#define environ (*_NSGetEnviron())
#else
extern char **environ; // GNU C library
#endif
 
namespace il2cpp
{
namespace os
{
    int32_t Environment::GetProcessorCount()
    {
        int count = 1;
#ifdef _SC_NPROCESSORS_ONLN
        count = (int)sysconf(_SC_NPROCESSORS_ONLN);
        if (count > 0)
            return count;
#endif
#ifdef USE_SYSCTL
        {
            int mib[2];
            size_t len = sizeof(int);
            mib[0] = CTL_HW;
            mib[1] = HW_NCPU;
            if (sysctl(mib, 2, &count, &len, NULL, 0) == 0)
                return count;
        }
#endif
        return count;
    }
 
#if !IL2CPP_TINY_WITHOUT_DEBUGGER
#if !IL2CPP_TARGET_LUMIN
    std::string Environment::GetMachineName()
    {
        char buf[256];
 
        if (gethostname(buf, sizeof(buf)) != 0)
            return NULL;
 
        return buf;
    }
 
#endif //!IL2CPP_TARGET_LUMIN
 
    std::string Environment::GetOsVersionString()
    {
        struct utsname name;
 
        if (uname(&name) >= 0)
            return name.release;
 
        return "0.0.0.0";
    }
 
    std::string Environment::GetOsUserName()
    {
        const std::string username(GetEnvironmentVariable("USER"));
        return username.empty() ? "Unknown" : username;
    }
 
    std::string Environment::GetEnvironmentVariable(const std::string& name)
    {
        const char* variable = getenv(name.c_str());
        return variable ? std::string(variable) : std::string();
    }
 
    void Environment::SetEnvironmentVariable(const std::string& name, const std::string& value)
    {
        if (value.empty())
        {
            unsetenv(name.c_str());
        }
        else
        {
            setenv(name.c_str(), value.c_str(), 1); // 1 means overwrite
        }
    }
 
    std::vector<std::string> Environment::GetEnvironmentVariableNames()
    {
        std::vector<std::string> result;
 
        for (char **envvar = environ; *envvar != NULL; ++envvar)
        {
            const char* equalAddress = strchr(*envvar, '=');
 
            if (equalAddress != NULL)
                result.push_back(std::string(*envvar, size_t(equalAddress - *envvar)));
        }
 
        return result;
    }
 
    std::string Environment::GetHomeDirectory()
    {
        static std::string homeDirectory;
 
        if (!homeDirectory.empty())
            return homeDirectory;
 
        homeDirectory = GetEnvironmentVariable("HOME");
 
        return homeDirectory.empty() ? "/" : homeDirectory;
    }
 
    std::vector<std::string> Environment::GetLogicalDrives()
    {
        std::vector<std::string> result;
 
        // This implementation is not correct according to the definition of this icall, but this is
        // the only "logical drive" that the Mono version in Unity returns for OSX.
        result.push_back("/");
 
        // TODO: Implement additional logic for Linux
 
        return result;
    }
 
    void Environment::Exit(int result)
    {
        IL2CPP_VM_SHUTDOWN();
        exit(result);
    }
 
#endif // !IL2CPP_TINY_WITHOUT_DEBUGGER
 
    NORETURN void Environment::Abort()
    {
        abort();
    }
 
#if !IL2CPP_TINY_WITHOUT_DEBUGGER
    std::string Environment::GetWindowsFolderPath(int folder)
    {
        // This should only be called on Windows.
        return std::string();
    }
 
    bool Environment::Is64BitOs()
    {
        struct utsname name;
 
        if (uname(&name) >= 0)
        {
            return strcmp(name.machine, "x86_64") == 0 || strncmp(name.machine, "aarch64", 7) == 0 || strncmp(name.machine, "ppc64", 5) == 0;
        }
 
        return false;
    }
 
#endif // !IL2CPP_TINY_WITHOUT_DEBUGGER
}
}
#endif