ChatPlexSDK-BS 1.0.1-v6.2.0
C++ ChatPlex BeatSaber SDK
Loading...
Searching...
No Matches
UIIl2cpp.hpp
1#pragma once
2
3#include "../Utils/Delegate.hpp"
4#include "../Utils/Il2cpp.hpp"
5#include "../Utils/MonoPtr.hpp"
6
7#include <custom-types/shared/delegate.hpp>
8#include <UnityEngine/Object.hpp>
9#include <UnityEngine/Events/UnityAction.hpp>
10#include <UnityEngine/Events/UnityAction_1.hpp>
11#include <UnityEngine/Events/UnityAction_2.hpp>
12#include <UnityEngine/Events/UnityAction_3.hpp>
13#include <UnityEngine/Events/UnityAction_4.hpp>
14#include <UnityEngine/UI/Button_ButtonClickedEvent.hpp>
15
16namespace CP_SDK::UI {
17
19 template<class t_Type>
21
24
26 template<class t_Type>
28
31
32 template<class t_Type>
34 {
35 static_assert(std::is_assignable_v<UnityEngine::Object, t_Type>);
36 static Utils::MonoPtr<t_Type> Value;
37 };
39
42
43 template<class t_Type> struct UIFieldRefDelExtractor;
44 template<class t_Type> struct UIFieldRefDelExtractor<Utils::Func<Utils::MonoPtr<t_Type>&>>
45 {
48 };
49
52
53 #define CP_SDK_UI_IL2CPP_BIND_FIELD(__Field, __Variable) __Field = [this]() -> CP_SDK::UI::UIFieldRefDelExtractor<typeof(__Field)>::t_PtrType { return __Variable; };
54
57
63 template <typename t_Type, typename t_DelegateType>
64 inline t_Type CustomTypesMakeDelegate(t_DelegateType p_Delegate)
65 {
66 return custom_types::MakeDelegate<t_Type>(p_Delegate);
67 }
68
73 template<typename... t_Args>
74 auto MakeUnityAction(std::function<void(t_Args...)> p_Delegate)
75 {
76 constexpr int l_ArgCount = sizeof...(t_Args);
77
78 if constexpr (l_ArgCount == 0) return CustomTypesMakeDelegate<UnityEngine::Events::UnityAction*>(p_Delegate);
79 else if constexpr (l_ArgCount == 1) return CustomTypesMakeDelegate<UnityEngine::Events::UnityAction_1<t_Args...>*>(p_Delegate);
80 else if constexpr (l_ArgCount == 2) return CustomTypesMakeDelegate<UnityEngine::Events::UnityAction_2<t_Args...>*>(p_Delegate);
81 else if constexpr (l_ArgCount == 3) return CustomTypesMakeDelegate<UnityEngine::Events::UnityAction_3<t_Args...>*>(p_Delegate);
82 else if constexpr (l_ArgCount == 4) return CustomTypesMakeDelegate<UnityEngine::Events::UnityAction_4<t_Args...>*>(p_Delegate);
83
85 static_assert(l_ArgCount <= 4, "argument count was greater than supported");
86 }
92 template<typename t_Type, typename...t_Args>
93 requires(std::is_constructible_v<std::function<void(t_Args...)>, t_Type> && !std::is_same_v<std::function<void(t_Args...)>, t_Type>)
94 auto MakeUnityAction(t_Type p_Delegate)
95 {
96 return MakeUnityAction<t_Args...>(std::function<void(t_Args...)>(p_Delegate));
97 }
103 template<typename...t_Args>
104 auto MakeUnityAction(Il2CppObject* p_Instance, const MethodInfo* p_MethodInfo)
105 {
106 if (p_MethodInfo->parameters_count != sizeof...(t_Args))
107 throw std::runtime_error("Argcount mismatch between p_MethodInfo and t_Args");
108
109 return MakeUnityAction<t_Args...>(std::function<void(t_Args...)>([p_Instance, p_MethodInfo](t_Args... p_Args){
110 il2cpp_utils::RunMethod(p_Instance, p_MethodInfo, p_Args...);
111 }));
112 }
113
114}
Delegate helper class.
Definition Delegate.hpp:123
User interface components, views, flow coordinator, builders and factories.
t_Type CustomTypesMakeDelegate(t_DelegateType p_Delegate)
a templated method to put the MakeDelegate call into a function so that when we change where the Make...
Definition UIIl2cpp.hpp:64
auto MakeUnityAction(std::function< void(t_Args...)> p_Delegate)
templated method to turn an std::function into an action
Definition UIIl2cpp.hpp:74