Skip to content

Commit c931017

Browse files
authored
Merge pull request issuimo#27 from Kn0wns/main
Update UnityResolve.hpp
2 parents 89917cb + 26ab854 commit c931017

File tree

1 file changed

+41
-1
lines changed

1 file changed

+41
-1
lines changed

UnityResolve.hpp

+41-1
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,33 @@
11
#ifndef UNITYRESOLVE_HPP
22
#define UNITYRESOLVE_HPP
33

4-
#define WINDOWS_MODE 1 // 如果需要请改为 1 | 1 if you need
4+
// ============================== 自动检测当前环境 ==============================
5+
6+
#if defined(_WIN32) || defined(_WIN64)
7+
#define WINDOWS_MODE 1
8+
#else
9+
#define WINDOWS_MODE 0
10+
#endif
11+
12+
#if defined(__ANDROID__)
13+
#define ANDROID_MODE 1
14+
#else
515
#define ANDROID_MODE 0
16+
#endif
17+
18+
#if defined(__linux__) && !defined(__ANDROID__)
19+
#define LINUX_MODE 1
20+
#else
621
#define LINUX_MODE 0
22+
#endif
23+
24+
// ============================== 强制设置当前执行环境 ==============================
25+
26+
// #define WINDOWS_MODE 0
27+
// #define ANDROID_MODE 1 // 设置运行环境
28+
// #define LINUX_MODE 0
29+
30+
// ============================== 导入对应环境依赖 ==============================
731

832
#if WINDOWS_MODE || LINUX_MODE
933
#include <format>
@@ -2899,6 +2923,22 @@ class UnityResolve final {
28992923
}
29002924
};
29012925

2926+
struct Screen {
2927+
static auto get_width() -> Int32 {
2928+
static Method *method;
2929+
if (!method) method = Get("UnityEngine.CoreModule.dll")->Get("Screen")->Get<Method>("get_width");
2930+
if (method) return method->Invoke<int32_t>();
2931+
return 0;
2932+
}
2933+
2934+
static auto get_height() -> Int32 {
2935+
static Method *method;
2936+
if (!method) method = Get("UnityEngine.CoreModule.dll")->Get("Screen")->Get<Method>("get_height");
2937+
if (method) return method->Invoke<int32_t>();
2938+
return 0;
2939+
}
2940+
};
2941+
29022942
template <typename Return, typename... Args>
29032943
static auto Invoke(void* address, Args... args) -> Return {
29042944
#if WINDOWS_MODE

0 commit comments

Comments
 (0)