ChatPlexSDK-BS 1.0.1-v6.2.0
C++ ChatPlex BeatSaber SDK
Loading...
Searching...
No Matches
BeatMapsClient.hpp
1#pragma once
2
3#include "BeatMaps/MapDetail.hpp"
4#include "../../CP_SDK/Network/WebClientUnity.hpp"
5#include "../../CP_SDK/ChatPlexSDK.hpp"
6
7#include <System/Threading/CancellationToken.hpp>
8
9namespace CP_SDK_BS::Game {
10
11 namespace _u
12 {
13 using namespace System;
14 using namespace System::Threading;
15 }
16 namespace _v
17 {
18 using namespace CP_SDK::Utils;
19 using namespace CP_SDK::Network;
20 }
21
24 {
25 CP_SDK_NO_DEF_CTORS(BeatMapsClient);
26
27 private:
28 static _v::WebClientUnity::Ptr m_WebClient;
29
30 public:
31 static _v::WebClientUnity::Ptr& WebClient();
32
33 public:
35 static void Init();
36
37 public:
41 static void GetOnlineByKey(std::u16string_view p_Key, _v::CActionRef<bool, BeatMaps::MapDetail::Ptr> p_Callback);
45 static void GetOnlineByHash(std::u16string_view p_Hash, _v::CActionRef<bool, BeatMaps::MapDetail::Ptr> p_Callback);
49 static void GetOnlineBySearch(std::u16string_view p_Query, _v::CActionRef<bool, std::vector<BeatMaps::MapDetail::Ptr>&> p_Callback);
50
51 public:
55 static void PopulateOnlineByKey(BeatMaps::MapDetail::Ptr& p_BeatMap, _v::CActionRef<bool> p_Callback);
59 static void PopulateOnlineByHash(BeatMaps::MapDetail::Ptr& p_BeatMap, _v::CActionRef<bool> p_Callback);
60
61 public:
68 static void DownloadSong( BeatMaps::MapDetail::Ptr p_Song,
69 BeatMaps::MapVersion::Ptr p_Version,
70 _u::CancellationToken p_Token,
72 _v::CActionRef<float> p_Progress = nullptr);
73
74 private:
80 static std::pair<bool, std::u16string> ExtractZipAsync( BeatMaps::MapDetail::Ptr p_Song,
81 _v::CMonoPtrRef<::Array<uint8_t>> p_ZIPBytes,
82 std::u16string_view p_CustomSongsPath,
83 bool p_Overwrite = false);
84
85 private:
91 template<typename t_Type>
92 static bool GetObjectFromJsonString(std::u16string_view p_Serialized, std::shared_ptr<t_Type>& p_Object)
93 {
94 p_Object = nullptr;
95 try
96 {
97 _v::Json::U16Document l_Document;
98 if (!_v::Json::TryFromU16String(p_Serialized, l_Document))
99 return false;
100
101 p_Object = std::make_shared<t_Type>();
102 p_Object->Unserialize(l_Document);
103 }
104 catch (const std::exception& l_Exception)
105 {
106 p_Object = nullptr;
107 CP_SDK::ChatPlexSDK::Logger()->Error(u"[CP_SDK_BS.Game][BeatMapsClient.GetObjectFromJsonString] Error :");
108 CP_SDK::ChatPlexSDK::Logger()->Error(l_Exception);
109 return false;
110 }
111
112 return p_Object != nullptr;
113 }
114
115 };
116
117}
static Logging::ILogger * Logger()
Logger instance.
static void Init()
Init the BeatMaps client.
static void PopulateOnlineByHash(BeatMaps::MapDetail::Ptr &p_BeatMap, _v::CActionRef< bool > p_Callback)
Populate partial BeatMap by hash.
static void GetOnlineByKey(std::u16string_view p_Key, _v::CActionRef< bool, BeatMaps::MapDetail::Ptr > p_Callback)
Get online by key.
static void DownloadSong(BeatMaps::MapDetail::Ptr p_Song, BeatMaps::MapVersion::Ptr p_Version, _u::CancellationToken p_Token, _v::CActionRef< bool, std::u16string_view > p_Callback, _v::CActionRef< float > p_Progress=nullptr)
Download a song.
static void GetOnlineByHash(std::u16string_view p_Hash, _v::CActionRef< bool, BeatMaps::MapDetail::Ptr > p_Callback)
Get online by hash.
static void PopulateOnlineByKey(BeatMaps::MapDetail::Ptr &p_BeatMap, _v::CActionRef< bool > p_Callback)
Populate partial BeatMap by key.
static void GetOnlineBySearch(std::u16string_view p_Query, _v::CActionRef< bool, std::vector< BeatMaps::MapDetail::Ptr > & > p_Callback)
Get online by search.
Network and HTTP utilities.
Various platform utils like Delegate/Action/Function/Event system.
Definition Delegate.hpp:8
Game specific helper and utilities.
Definition MapDetail.hpp:12