Skip to content

Commit 773a925

Browse files
committed
V6.0.9
1 parent 08097d1 commit 773a925

File tree

69 files changed

+1322
-615
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

69 files changed

+1322
-615
lines changed

BeatSaberPlus/BeatSaberPlus.csproj

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -342,8 +342,9 @@
342342
<Compile Include="CP_SDK\Network\LiteNetLib\Utils\NtpPacket.cs" />
343343
<Compile Include="CP_SDK\Network\LiteNetLib\Utils\NtpRequest.cs" />
344344
<Compile Include="CP_SDK\Network\RateLimitInfo.cs" />
345-
<Compile Include="CP_SDK\Network\WebClient.cs" />
346-
<Compile Include="CP_SDK\Network\WebClientEx.cs" />
345+
<Compile Include="CP_SDK\Network\WebClientUnity.cs" />
346+
<Compile Include="CP_SDK\Network\WebClientCore.cs" />
347+
<Compile Include="CP_SDK\Network\WebContent.cs" />
347348
<Compile Include="CP_SDK\Network\WebResponse.cs" />
348349
<Compile Include="CP_SDK\Network\websocket-sharp\ByteOrder.cs" />
349350
<Compile Include="CP_SDK\Network\websocket-sharp\CloseEventArgs.cs" />
-14 Bytes
Binary file not shown.

BeatSaberPlus/CP_SDK/Chat/ChatImageProvider.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public class ChatImageProvider
2626
/// <summary>
2727
/// Network client
2828
/// </summary>
29-
private static Network.WebClient m_WebClient;
29+
private static Network.WebClientUnity m_WebClient;
3030

3131
////////////////////////////////////////////////////////////////////////////
3232
////////////////////////////////////////////////////////////////////////////
@@ -83,8 +83,7 @@ public class ChatImageProvider
8383
internal static void Init()
8484
{
8585
m_CacheFolder = Path.Combine(ChatPlexSDK.BasePath, $"UserData/{ChatPlexSDK.ProductName}/Cache/Chat/");
86-
m_WebClient = new Network.WebClient("", TimeSpan.FromSeconds(10));
87-
m_WebClient.Timeout = 10;
86+
m_WebClient = new Network.WebClientUnity("", TimeSpan.FromSeconds(10));
8887

8988
try
9089
{

BeatSaberPlus/CP_SDK/Chat/Services/Twitch/TwitchBadgeProvider.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,9 @@ public class TwitchBadgeProvider : IChatResourceProvider<ChatResourceData>
4141
/// <returns></returns>
4242
public async Task TryRequestResources(string p_ChannelID, string p_ChannelName, string p_AccessToken)
4343
{
44-
var l_WebClient = new Network.WebClient("https://api.twitch.tv/helix/", TimeSpan.FromSeconds(10), true);
45-
if (!l_WebClient.Headers.ContainsKey("Client-Id"))
46-
l_WebClient.Headers.Remove("Authorization");
47-
48-
if (l_WebClient.Headers.ContainsKey("Client-Id"))
49-
l_WebClient.Headers.Remove("Authorization");
50-
51-
l_WebClient.Headers.Add("client-id", TwitchService.TWITCH_CLIENT_ID);
52-
l_WebClient.Headers.Add("Authorization", "Bearer " + p_AccessToken.Replace("oauth:", ""));
44+
var l_WebClient = new Network.WebClientUnity("https://api.twitch.tv/helix/", TimeSpan.FromSeconds(10), true);
45+
l_WebClient.SetHeader("client-id", TwitchService.TWITCH_CLIENT_ID);
46+
l_WebClient.SetHeader("Authorization", "Bearer " + p_AccessToken.Replace("oauth:", ""));
5347

5448
bool l_IsGlobal = string.IsNullOrEmpty(p_ChannelID);
5549
try

BeatSaberPlus/CP_SDK/Chat/Services/Twitch/TwitchCheermoteProvider.cs

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,9 @@ public class TwitchCheermoteProvider : IChatResourceProvider<TwitchCheermoteData
3131
/// <returns></returns>
3232
public async Task TryRequestResources(string p_ChannelID, string p_ChannelName, string p_AccessToken)
3333
{
34-
var l_WebClient = new Network.WebClient("https://api.twitch.tv/helix/", TimeSpan.FromSeconds(10), true);
35-
if (!l_WebClient.Headers.ContainsKey("Client-Id"))
36-
l_WebClient.Headers.Remove("Authorization");
37-
38-
if (l_WebClient.Headers.ContainsKey("Client-Id"))
39-
l_WebClient.Headers.Remove("Authorization");
40-
41-
l_WebClient.Headers.Add("client-id", TwitchService.TWITCH_CLIENT_ID);
42-
l_WebClient.Headers.Add("Authorization", "Bearer " + p_AccessToken.Replace("oauth:", ""));
34+
var l_WebClient = new Network.WebClientUnity("https://api.twitch.tv/helix/", TimeSpan.FromSeconds(10), true);
35+
l_WebClient.SetHeader("client-id", TwitchService.TWITCH_CLIENT_ID);
36+
l_WebClient.SetHeader("Authorization", "Bearer " + p_AccessToken.Replace("oauth:", ""));
4337

4438
bool l_IsGlobal = string.IsNullOrEmpty(p_ChannelID);
4539
try

BeatSaberPlus/CP_SDK/Chat/Services/Twitch/TwitchHelix.cs

Lines changed: 16 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ public class TwitchHelix
4545
/// <summary>
4646
/// Web Client
4747
/// </summary>
48-
private Network.WebClient m_WebClient = new Network.WebClient ("https://api.twitch.tv/helix/", TimeSpan.FromSeconds(10), true);
49-
private Network.WebClientEx m_WebClientEx = new Network.WebClientEx("https://api.twitch.tv/helix/", TimeSpan.FromSeconds(10), true);
48+
private Network.WebClientUnity m_WebClient = new Network.WebClientUnity ("https://api.twitch.tv/helix/", TimeSpan.FromSeconds(10), true);
49+
private Network.WebClientCore m_WebClientEx = new Network.WebClientCore("https://api.twitch.tv/helix/", TimeSpan.FromSeconds(10), true);
5050
/// <summary>
5151
/// Broadcaster ID
5252
/// </summary>
@@ -94,8 +94,8 @@ public class TwitchHelix
9494
/// <summary>
9595
/// Client
9696
/// </summary>
97-
public Network.WebClient WebClient => m_WebClient;
98-
public Network.WebClientEx WebClientEx => m_WebClientEx;
97+
public Network.WebClientUnity WebClient => m_WebClient;
98+
public Network.WebClientCore WebClientEx => m_WebClientEx;
9999
/// <summary>
100100
/// Broadcaster ID
101101
/// </summary>
@@ -133,27 +133,15 @@ internal void OnTokenChanged(string p_Token)
133133
{
134134
try
135135
{
136-
if (m_WebClient.Headers.ContainsKey("Client-Id"))
137-
m_WebClient.Headers.Remove("Client-Id");
138-
139-
if (m_WebClient.Headers.ContainsKey("Authorization"))
140-
m_WebClient.Headers.Remove("Authorization");
141-
142-
m_WebClient.Headers.Add("Client-Id", TwitchService.TWITCH_CLIENT_ID);
143-
m_WebClient.Headers.Add("Authorization", "Bearer " + p_Token.Replace("oauth:", ""));
136+
m_WebClient.SetHeader("Client-Id", TwitchService.TWITCH_CLIENT_ID);
137+
m_WebClient.SetHeader("Authorization", "Bearer " + p_Token.Replace("oauth:", ""));
144138
}
145139
catch (System.Exception) { }
146140

147141
try
148142
{
149-
if (!m_WebClientEx.InternalClient.DefaultRequestHeaders.Contains("Client-Id"))
150-
m_WebClientEx.InternalClient.DefaultRequestHeaders.Remove("Client-Id");
151-
152-
if (m_WebClientEx.InternalClient.DefaultRequestHeaders.Contains("Authorization"))
153-
m_WebClientEx.InternalClient.DefaultRequestHeaders.Remove("Authorization");
154-
155-
m_WebClientEx.InternalClient.DefaultRequestHeaders.Add("Client-Id", TwitchService.TWITCH_CLIENT_ID);
156-
m_WebClientEx.InternalClient.DefaultRequestHeaders.Add("Authorization", "Bearer " + p_Token.Replace("oauth:", ""));
143+
m_WebClientEx.SetHeader("Client-Id", TwitchService.TWITCH_CLIENT_ID);
144+
m_WebClientEx.SetHeader("Authorization", "Bearer " + p_Token.Replace("oauth:", ""));
157145
}
158146
catch (System.Exception) { }
159147

@@ -268,15 +256,12 @@ internal void Update()
268256
/// </summary>
269257
private void ValidateToken()
270258
{
271-
var l_WebClient = new Network.WebClient("", TimeSpan.FromSeconds(10), true);
259+
var l_WebClient = new Network.WebClientUnity("", TimeSpan.FromSeconds(10), true);
272260
try
273261
{
274-
l_WebClient.Headers.Add("Authorization", "OAuth " + m_APIToken.Replace("oauth:", ""));
275-
}
276-
catch
277-
{
278-
262+
l_WebClient.SetHeader("Authorization", "OAuth " + m_APIToken.Replace("oauth:", ""));
279263
}
264+
catch { }
280265

281266
l_WebClient.GetAsync("https://id.twitch.tv/oauth2/validate", CancellationToken.None, (p_Result) =>
282267
{
@@ -354,14 +339,8 @@ public void CreatePoll(Helix_CreatePoll p_Poll, Action<TwitchHelixResult, Helix_
354339
}
355340

356341
p_Poll.broadcaster_id = m_BroadcasterID;
357-
var l_ContentStr = new StringContent(JsonConvert.SerializeObject(p_Poll), Encoding.UTF8);
358-
359-
#if DEBUG
360-
ChatPlexSDK.Logger.Debug("[CP_SDK.Chat.Service.Twitch][TwitchHelix.CreatePoll] Sending:");
361-
ChatPlexSDK.Logger.Debug(JsonConvert.SerializeObject(p_Poll, Formatting.Indented));
362-
#endif
363342

364-
m_WebClient.PostAsync("polls", l_ContentStr, "application/json", CancellationToken.None, (p_Result) =>
343+
m_WebClient.PostAsync("polls", Network.WebContent.FromJson(p_Poll), CancellationToken.None, (p_Result) =>
365344
{
366345
#if DEBUG
367346
if (p_Result != null)
@@ -469,14 +448,7 @@ public void EndPoll(Helix_Poll p_Poll, Helix_Poll.Status p_EndStatus, Action<Twi
469448
["status"] = (p_EndStatus == Helix_Poll.Status.ARCHIVED ? p_EndStatus : Helix_Poll.Status.TERMINATED).ToString()
470449
};
471450

472-
var l_ContentStr = new StringContent(JsonConvert.SerializeObject(l_Content), Encoding.UTF8);
473-
474-
#if DEBUG
475-
ChatPlexSDK.Logger.Debug("[CP_SDK.Chat.Service.Twitch][TwitchHelix.EndPoll] Sending:");
476-
ChatPlexSDK.Logger.Debug(JsonConvert.SerializeObject(l_Content, Formatting.Indented));
477-
#endif
478-
479-
m_WebClient.PatchAsync("polls", l_ContentStr, "application/json", CancellationToken.None, (p_Result) =>
451+
m_WebClient.PatchAsync("polls", Network.WebContent.FromJson(l_Content), CancellationToken.None, (p_Result) =>
480452
{
481453
#if DEBUG
482454
if (p_Result != null)
@@ -639,9 +611,7 @@ public void EndPrediction(string p_ID, Helix_Prediction.Status p_Status, string
639611
if (p_Status == Helix_Prediction.Status.RESOLVED)
640612
l_Body["winning_outcome_id"] = p_WinningOutcomeID;
641613

642-
var l_ContentStr = new StringContent(l_Body.ToString(Formatting.None), Encoding.UTF8);
643-
644-
m_WebClient.PatchAsync("predictions", l_ContentStr, "application/json", CancellationToken.None, (p_Result) =>
614+
m_WebClient.PatchAsync("predictions", Network.WebContent.FromJson(l_Body), CancellationToken.None, (p_Result) =>
645615
{
646616
#if DEBUG
647617
if (p_Result != null)
@@ -693,8 +663,7 @@ public void CreateClip(Action<TwitchHelixResult, Helix_CreateClip> p_Callback)
693663
return;
694664
}
695665

696-
var l_ContentStr = new StringContent("{}", Encoding.UTF8);
697-
m_WebClient.PostAsync("clips?broadcaster_id="+ m_BroadcasterID, l_ContentStr, "application/json", CancellationToken.None, (p_Result) =>
666+
m_WebClient.PostAsync("clips?broadcaster_id="+ m_BroadcasterID, Network.WebContent.FromJson(new JObject()), CancellationToken.None, (p_Result) =>
698667
{
699668
#if DEBUG
700669
if (p_Result != null)
@@ -753,9 +722,7 @@ public void CreateMarker(string p_MarkerName, Action<TwitchHelixResult> p_Callba
753722
["description"] = p_MarkerName.Length > 140 ? p_MarkerName.Substring(0, 140) : p_MarkerName
754723
};
755724

756-
var l_ContentStr = new StringContent(JsonConvert.SerializeObject(l_Content), Encoding.UTF8);
757-
758-
m_WebClient.PostAsync("streams/markers", l_ContentStr, "application/json", CancellationToken.None, (p_Result) =>
725+
m_WebClient.PostAsync("streams/markers", Network.WebContent.FromJson(l_Content), CancellationToken.None, (p_Result) =>
759726
{
760727
#if DEBUG
761728
if (p_Result != null)

BeatSaberPlus/CP_SDK/Chat/Services/Twitch/TwitchMessageParser.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ public bool ParseRawMessage(string p_RawMessages, ConcurrentDictionary<string, T
288288
{
289289
Id = l_EmoteId,
290290
Name = $"[{l_EmoteId}]",
291-
Uri = l_ProfileImage,
291+
Uri = l_ProfileImage.Replace("%s", "70x70"),
292292
StartIndex = 0,
293293
EndIndex = l_EmoteId.Length + 1,
294294
Animation = Animation.EAnimationType.NONE,

BeatSaberPlus/CP_SDK/Network/IWebClient.cs

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,27 @@ namespace CP_SDK.Network
99
/// </summary>
1010
public interface IWebClient
1111
{
12+
/// <summary>
13+
/// Get header
14+
/// </summary>
15+
/// <param name="p_Name">Headername</param>
16+
/// <returns></returns>
17+
string GetHeader(string p_Name);
18+
/// <summary>
19+
/// Set header
20+
/// </summary>
21+
/// <param name="p_Name">Header name</param>
22+
/// <param name="p_Value">Header value</param>
23+
void SetHeader(string p_Name, string p_Value);
24+
/// <summary>
25+
/// Remove header
26+
/// </summary>
27+
/// <param name="p_Name">Header name</param>
28+
void RemoveHeader(string p_Name);
29+
30+
////////////////////////////////////////////////////////////////////////////
31+
////////////////////////////////////////////////////////////////////////////
32+
1233
/// <summary>
1334
/// Do Async GET query
1435
/// </summary>
@@ -18,27 +39,33 @@ public interface IWebClient
1839
/// <param name="p_DontRetry">Should not retry</param>
1940
/// <param name="p_Progress">Progress reporter</param>
2041
void GetAsync(string p_URL, CancellationToken p_Token, Action<WebResponse> p_Callback, bool p_DontRetry = false, IProgress<float> p_Progress = null);
42+
/// <summary>
43+
/// Do Async GET query
44+
/// </summary>
45+
/// <param name="p_URL">Target URL</param>
46+
/// <param name="p_Token">Cancellation token</param>
47+
/// <param name="p_Callback">Callback</param>
48+
/// <param name="p_DontRetry">Should not retry</param>
49+
/// <param name="p_Progress">Progress reporter</param>
2150
void DownloadAsync(string p_URL, CancellationToken p_Token, Action<WebResponse> p_Callback, bool p_DontRetry = false, IProgress<float> p_Progress = null);
2251
/// <summary>
2352
/// Do Async POST query
2453
/// </summary>
2554
/// <param name="p_URL">Target URL</param>
26-
/// <param name="p_Content">Optional content to post</param>
27-
/// <param name="p_ContentType">Content type</param>
55+
/// <param name="p_Content">Content to post</param>
2856
/// <param name="p_Token">Cancellation token</param>
2957
/// <param name="p_Callback">Callback</param>
3058
/// <param name="p_DontRetry">Should not retry</param>
31-
void PostAsync(string p_URL, HttpContent p_Content, string p_ContentType, CancellationToken p_Token, Action<WebResponse> p_Callback, bool p_DontRetry = false);
59+
void PostAsync(string p_URL, WebContent p_Content, CancellationToken p_Token, Action<WebResponse> p_Callback, bool p_DontRetry = false);
3260
/// <summary>
3361
/// Do Async PATCH query
3462
/// </summary>
3563
/// <param name="p_URL">Target URL</param>
36-
/// <param name="p_Content">Optional content to post</param>
37-
/// <param name="p_ContentType">Content type</param>
64+
/// <param name="p_Content">Content to post</param>
3865
/// <param name="p_Token">Cancellation token</param>
3966
/// <param name="p_Callback">Callback</param>
4067
/// <param name="p_DontRetry">Should not retry</param>
41-
void PatchAsync(string p_URL, HttpContent p_Content, string p_ContentType, CancellationToken p_Token, Action<WebResponse> p_Callback, bool p_DontRetry = false);
68+
void PatchAsync(string p_URL, WebContent p_Content, CancellationToken p_Token, Action<WebResponse> p_Callback, bool p_DontRetry = false);
4269
/// <summary>
4370
/// Do Async DELETE query
4471
/// </summary>

0 commit comments

Comments
 (0)