1+ #pragma once
2+
3+ #include " Network/JsonRPCResult.hpp"
4+ #include " Network/JsonRPCClient.hpp"
5+ #include " Utils/Event.hpp"
6+ #include " Utils/Il2cpp.hpp"
7+ #include " Utils/Delegate.hpp"
8+
9+ #include < beatsaber-hook/shared/utils/il2cpp-utils.hpp>
10+ #include < string>
11+ #include < string_view>
12+
13+ namespace CP_SDK {
14+
15+ namespace _u
16+ {
17+ using namespace il2cpp_utils ;
18+ using namespace System ;
19+ using namespace UnityEngine ;
20+ }
21+
22+ namespace _v
23+ {
24+ using namespace CP_SDK ::Network;
25+ using namespace CP_SDK ::Utils;
26+ }
27+
28+ // / @brief ChatPlexService
29+ class CP_SDK_EXPORT ChatPlexService
30+ {
31+ CP_SDK_NO_DEF_CTORS (ChatPlexService);
32+
33+ public:
34+ enum class EState
35+ {
36+ Disconnected,
37+ LinkRequest,
38+ LinkWait,
39+ Connecting,
40+
41+ Connected,
42+
43+ Error
44+ };
45+
46+ private:
47+ static bool m_ThreadCondition;
48+ static _u::il2cpp_aware_thread* m_Thread;
49+ static EState m_State;
50+ static _v::WebClientCore::Ptr m_WebClientCore;
51+ static _v::JsonRPCClient::Ptr m_JsonRPCClient;
52+ static std::u16string m_LinkRequestID;
53+ static std::u16string m_LinkCode;
54+ static std::u16string m_LastError;
55+ static std::u16string m_ActiveSubscription;
56+ static std::vector<std::u16string> m_UnlockedFeatures;
57+ static std::queue<_v::Action<>> m_OnTokenReadyQueue;
58+ static std::mutex m_OnTokenReadyQueueMutex;
59+ static std::u16string m_DeviceName;
60+
61+ public:
62+ static const EState State ();
63+ static const std::u16string_view Token ();
64+ static const std::u16string_view LinkCode ();
65+ static const std::u16string_view LastError ();
66+ static const std::u16string_view ActiveSubscription ();
67+ static const std::vector<const std::u16string>& UnlockedFeatures ();
68+
69+ static _v::Event<EState, EState> StateChanged;
70+
71+ public:
72+ // / @brief Init the service
73+ static void Init ();
74+ // / @brief Release the service
75+ static void Release ();
76+
77+ public:
78+ // / @brief Add a callback to be called when the token is ready (call immediatly if ready)
79+ // / @param action Callback to be caled
80+ static void OnTokenReady (_v::CActionRef<> action);
81+
82+ public:
83+ // / @brief Start linking procedure
84+ static void StartLinking ();
85+ // / @brief Stop linking procedure
86+ static void StopLinking ();
87+ // / @brief Refresh the session
88+ static void Refresh ();
89+ // / @brief Disconnect and erase the saved connected application token
90+ static void Disconnect ();
91+
92+ private:
93+ // / @brief Change state and notify listenners
94+ static void ChangeState (const EState newState);
95+ // / @brief Fire on token ready actions
96+ static void FireOnTokenReady ();
97+
98+ private:
99+ // / @brief Thread function
100+ static void ThreadRunner ();
101+
102+ private:
103+ // / @brief Is RPC call result a success result?
104+ // / @param rpcResult Result of the RPC command
105+ // / @return True if success
106+ static bool IsRPCSuccess (_v::JsonRPCResult::Ptr& rpcResult);
107+
108+ private:
109+ // / @brief When we are Authed
110+ // / @param rpcResult Result of the RPC command
111+ static void OnAuthed (_v::JsonRPCResult::Ptr& rpcResult);
112+ // / @brief On error received
113+ // / @param rpcResult Result of the RPC command
114+ static void OnError (_v::JsonRPCResult::Ptr& rpcResult);
115+
116+ };
117+
118+ } // /< namespace CP_SDK
0 commit comments