-
Notifications
You must be signed in to change notification settings - Fork 88
Expand file tree
/
Copy pathEventBase.hpp
More file actions
116 lines (94 loc) · 4.28 KB
/
EventBase.hpp
File metadata and controls
116 lines (94 loc) · 4.28 KB
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
#pragma once
#include "UserSettings/GlobalSettings.hpp"
#include "Il2CppHeaders.hpp"
#include "UnityStructures.hpp"
#include "MethodBase.hpp"
// NOLINTBEGIN
namespace BNM {
#pragma pack(push, 1)
template <typename Ret, typename ...Parameters> struct Event;
/**
@brief Class base for working with il2cpp events.
This class provides fields and some basic functions to allow call, add and remove methods in event.
*/
struct EventBase {
/**
@brief Create empty event base.
*/
inline constexpr EventBase() noexcept = default;
/**
@brief Copy event.
@param other Other event
*/
inline EventBase(const EventBase &other) = default;
/**
@brief Create event from il2cpp event.
@param info Il2cpp event
*/
EventBase(const IL2CPP::EventInfo *info);
/**
@brief Set event instance if it's non-static.
@param instance Instance
@return Reference to current EventBase
*/
EventBase &SetInstance(IL2CPP::Il2CppObject *instance);
/**
@brief Get class that contains this event.
@return BNM::Class of event's class
*/
[[nodiscard]] BNM::Class GetParentClass() const;
/**
@brief Operator for setting instance.
@param instance Instance
@return Reference to current EventBase
*/
inline EventBase &operator[](void *instance) { SetInstance((IL2CPP::Il2CppObject *) instance); return *this;}
/**
@brief Operator for setting instance.
@param instance Instance
@return Reference to current EventBase
*/
inline EventBase &operator[](IL2CPP::Il2CppObject *instance) { SetInstance(instance); return *this;}
/**
@brief Operator for setting instance.
@param instance Instance
@return Reference to current EventBase
*/
inline EventBase &operator[](UnityEngine::Object *instance) { SetInstance((IL2CPP::Il2CppObject *) instance); return *this;}
/**
@brief Check if event is valid.
@return State of event
*/
[[nodiscard]] inline bool IsValid() const noexcept { return _data; }
#ifdef BNM_ALLOW_STR_METHODS
/**
@brief Get full event name.
Returns string with full event name: ClassFullName.(event name){add method: exists/not exist, remove method: exists/not exist, raise method: exists/not exist} (static)/nothing
@return Event's full name or "Dead event".
*/
[[nodiscard]] inline std::string str() const {
if (!_data) return BNM_OBFUSCATE(DBG_BNM_MSG_EventBase_str_nullptr);
auto isStatic = _hasAdd ? _add._isStatic : _hasRemove ? _remove._isStatic : _raise._isStatic;
return Class(_data->parent).str() + BNM_OBFUSCATE(".(") +
#if UNITY_VER >= 233
_data->name +
#else
((Structures::Mono::String *)_data->name)->str() +
#endif
BNM_OBFUSCATE("){" DBG_BNM_MSG_EventBase_str_add ": ") + (_hasAdd ? BNM_OBFUSCATE(DBG_BNM_MSG_EventBase_str_exists) : BNM_OBFUSCATE(DBG_BNM_MSG_EventBase_str_not_exists)) +
BNM_OBFUSCATE(", " DBG_BNM_MSG_EventBase_str_remove ": ") + (_hasRemove ? BNM_OBFUSCATE(DBG_BNM_MSG_EventBase_str_exists) : BNM_OBFUSCATE(DBG_BNM_MSG_EventBase_str_not_exists)) +
BNM_OBFUSCATE(", " DBG_BNM_MSG_EventBase_str_raise ": ") + (_hasRaise ? BNM_OBFUSCATE(DBG_BNM_MSG_EventBase_str_exists) : BNM_OBFUSCATE(DBG_BNM_MSG_EventBase_str_not_exists)) +
BNM_OBFUSCATE("}") + (isStatic ? BNM_OBFUSCATE("(" DBG_BNM_MSG_EventBase_str_static ")") : BNM_OBFUSCATE(""));
}
#endif
/**
@brief Cast event to be able to add, remove and raise it.
*/
template<typename NewRet, typename ...NewParameters> inline Event<NewRet, NewParameters...> &cast() const { return (Event<NewRet, NewParameters...> &)*this; }
IL2CPP::EventInfo *_data{};
MethodBase _add{}, _remove{}, _raise{};
uint8_t _hasAdd : 1 = false, _hasRemove : 1 = false, _hasRaise : 1 = false;
};
#pragma pack(pop)
}
// NOLINTEND