From b66b97b13e47a64533ebf1f633a075eb9ef309ab Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Wed, 29 May 2024 15:36:58 +0200 Subject: [PATCH 1/2] Fixed more issues [ # ] Fixed helpers.DecodeSid [ # ] Fixed #40 [ # ] Fixed #39 [ # ] Fixed #38 (hopefully) [ # ] Fixed #35 --- Amino.NET/Builders/PostBuilder.cs | 2 +- Amino.NET/Client.cs | 9 ++++-- Amino.NET/Objects/CommunityThemePack.cs | 2 +- Amino.NET/Objects/GenericProfile.cs | 2 +- Amino.NET/SubClient.cs | 4 +-- Amino.NET/helpers.cs | 39 +++++++++++++++---------- 6 files changed, 34 insertions(+), 24 deletions(-) diff --git a/Amino.NET/Builders/PostBuilder.cs b/Amino.NET/Builders/PostBuilder.cs index d27f6cc..ab2f040 100644 --- a/Amino.NET/Builders/PostBuilder.cs +++ b/Amino.NET/Builders/PostBuilder.cs @@ -3,7 +3,7 @@ using System.IO; using System.Reflection.Metadata.Ecma335; -namespace Amino.NET.Builders +namespace Amino.Builders { public class PostBuilder { diff --git a/Amino.NET/Client.cs b/Amino.NET/Client.cs index 461df1c..1eeddff 100644 --- a/Amino.NET/Client.cs +++ b/Amino.NET/Client.cs @@ -363,7 +363,8 @@ public Task logout() public Task login_sid(string sessionId, bool fetchProfile = true, bool connectSocket = true) { this.SessionId = sessionId; - + this.UserId = helpers.sid_to_uid(sessionId); + headerBuilder(); if (fetchProfile) { Objects.UserAccount currentAccount = get_account_info(); @@ -767,10 +768,12 @@ public Objects.UserAccount get_account_info() RestClient client = new RestClient(helpers.BaseUrl); RestRequest request = new RestRequest("/g/s/account"); request.AddHeaders(headers); + request.AddHeader("SMDEVICEID", Guid.NewGuid().ToString()); + request.AddOrUpdateHeader("Content-Type", "application/x-www-form-urlencoded"); var response = client.ExecuteGet(request); if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (Debug) { Trace.WriteLine(response.Content); } - return System.Text.Json.JsonSerializer.Deserialize(JsonDocument.Parse(response.Content).RootElement.GetRawText()); + return System.Text.Json.JsonSerializer.Deserialize(JsonDocument.Parse(response.Content).RootElement.GetProperty("account").GetRawText()); } /// @@ -1802,7 +1805,7 @@ public Objects.WalletInfo get_wallet_info() var response = client.ExecuteGet(request); if ((int)response.StatusCode != 200) { throw new Exception(response.Content); } if (Debug) { Trace.WriteLine(response.Content); } - return System.Text.Json.JsonSerializer.Deserialize(JsonDocument.Parse(response.Content).RootElement.GetRawText()); + return System.Text.Json.JsonSerializer.Deserialize(JsonDocument.Parse(response.Content).RootElement.GetProperty("wallet").GetRawText()); } /// diff --git a/Amino.NET/Objects/CommunityThemePack.cs b/Amino.NET/Objects/CommunityThemePack.cs index ef81f27..7a9b0f0 100644 --- a/Amino.NET/Objects/CommunityThemePack.cs +++ b/Amino.NET/Objects/CommunityThemePack.cs @@ -6,7 +6,7 @@ public class CommunityThemePack { [JsonPropertyName("themeColor")] public string ThemeColor { get; set; } [JsonPropertyName("themePackHash")] public string ThemePackHash { get; set; } - [JsonPropertyName("themePackRevision")] public string ThemePackRevision { get; set; } + [JsonPropertyName("themePackRevision")] public int ThemePackRevision { get; set; } [JsonPropertyName("themePackUrl")] public string ThemePackUrl { get; set; } } } diff --git a/Amino.NET/Objects/GenericProfile.cs b/Amino.NET/Objects/GenericProfile.cs index 835622f..267ed0e 100644 --- a/Amino.NET/Objects/GenericProfile.cs +++ b/Amino.NET/Objects/GenericProfile.cs @@ -5,7 +5,7 @@ namespace Amino.Objects public class GenericProfile // ROOT JSON ELEMENT: userProfile { public string Json { get; set; } // NEEDS TO BE SET AFTER - [JsonPropertyName("status")]public int Status { get; set; } + [JsonPropertyName("status")]public int? Status { get; set; } [JsonPropertyName("isNicknameVerified")]public bool IsNicknameVerified { get; set; } [JsonPropertyName("uid")]public string UserId { get; set; } [JsonPropertyName("level")]public int Level { get; set; } diff --git a/Amino.NET/SubClient.cs b/Amino.NET/SubClient.cs index 92f8d49..ce04616 100644 --- a/Amino.NET/SubClient.cs +++ b/Amino.NET/SubClient.cs @@ -1,5 +1,4 @@ -using Amino.NET.Builders; -using Amino.Objects; +using Amino.Objects; using Newtonsoft.Json; using Newtonsoft.Json.Linq; using RestSharp; @@ -15,6 +14,7 @@ using System.Text.Json; using System.Threading; using System.Threading.Tasks; +using Amino.Builders; namespace Amino { diff --git a/Amino.NET/helpers.cs b/Amino.NET/helpers.cs index 666c23a..5ccf2b9 100644 --- a/Amino.NET/helpers.cs +++ b/Amino.NET/helpers.cs @@ -235,28 +235,35 @@ public static List> getTimeData() /// /// /// - public static dynamic DecodeSid(string session) + public static Dictionary DecodeSid(string sid) { - // Replace characters and adjust padding - session = session.Replace('-', '_').Replace('+', '/'); - int padding = session.Length % 4; - if (padding > 0) + sid = sid.Replace('-', '+').Replace('_', '/'); + + int padding = 4 - (sid.Length % 4); + if (padding < 4) { - session = session.PadRight(session.Length + (4 - padding), '='); + sid += new string('=', padding); } - // Decode base64, remove the first byte, and remove the last 21 bytes - byte[] bytes = Convert.FromBase64String(session); - bytes = bytes.Skip(1).Take(bytes.Length - 21).ToArray(); + byte[] decodedBytes = Convert.FromBase64String(sid); + + byte[] trimmedBytes = new byte[decodedBytes.Length - 21]; + Array.Copy(decodedBytes, 1, trimmedBytes, 0, trimmedBytes.Length); + string jsonString = Encoding.UTF8.GetString(trimmedBytes); + + // Deserialize JSON string to dictionary + var options = new JsonSerializerOptions + { + PropertyNameCaseInsensitive = true + }; + var dictionary = System.Text.Json.JsonSerializer.Deserialize>(jsonString, options); - // Convert bytes to UTF-8 string and parse JSON directly - string jsonString = Encoding.UTF8.GetString(bytes); - return System.Text.Json.JsonSerializer.Deserialize(jsonString); + return dictionary; } - public static string sid_to_uid(string session) { return DecodeSid(session)["2"]; } - public static string sid_to_ip_address(string session) { return DecodeSid(session)["4"]; } - public static string sid_created_time(string session) { return DecodeSid(session)["5"]; } - public static string sid_to_client_type(string session) { return DecodeSid(session)["6"]; } + public static string sid_to_uid(string session) { return DecodeSid(session)["2"].ToString(); } + public static string sid_to_ip_address(string session) { return DecodeSid(session)["4"].ToString(); } + public static string sid_created_time(string session) { return DecodeSid(session)["5"].ToString(); } + public static string sid_to_client_type(string session) { return DecodeSid(session)["6"].ToString(); } } } From 56d57d6b7fb51b2c27796388d4ab6fbbaad99045 Mon Sep 17 00:00:00 2001 From: Fabio Gaming Date: Wed, 29 May 2024 15:39:40 +0200 Subject: [PATCH 2/2] adapted dev versioning --- .github/workflows/dev-autopublish.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dev-autopublish.yml b/.github/workflows/dev-autopublish.yml index 049dbce..b8a0e5e 100644 --- a/.github/workflows/dev-autopublish.yml +++ b/.github/workflows/dev-autopublish.yml @@ -26,7 +26,7 @@ jobs: - name: Determine version id: version - run: echo "::set-output name=version::0.$((${GITHUB_RUN_NUMBER} / 10)).$((${GITHUB_RUN_NUMBER} % 10))" + run: echo "::set-output name=version::$((GITHUB_RUN_NUMBER / 100)).$(((GITHUB_RUN_NUMBER % 100) / 10)).$((GITHUB_RUN_NUMBER % 10))" - name: Get Project Version id: base_version