Skip to content

Commit

Permalink
Merge pull request #41 from Amino-NET-Group/patch/fix-more-issues
Browse files Browse the repository at this point in the history
Patch/fix more issues
  • Loading branch information
FabioGaming committed May 29, 2024
2 parents a59271f + 56d57d6 commit 19245fa
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 25 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/dev-autopublish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Amino.NET/Builders/PostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
using System.IO;
using System.Reflection.Metadata.Ecma335;

namespace Amino.NET.Builders
namespace Amino.Builders
{
public class PostBuilder
{
Expand Down
9 changes: 6 additions & 3 deletions Amino.NET/Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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<UserAccount>(JsonDocument.Parse(response.Content).RootElement.GetRawText());
return System.Text.Json.JsonSerializer.Deserialize<UserAccount>(JsonDocument.Parse(response.Content).RootElement.GetProperty("account").GetRawText());

}
/// <summary>
Expand Down Expand Up @@ -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<WalletInfo>(JsonDocument.Parse(response.Content).RootElement.GetRawText());
return System.Text.Json.JsonSerializer.Deserialize<WalletInfo>(JsonDocument.Parse(response.Content).RootElement.GetProperty("wallet").GetRawText());
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion Amino.NET/Objects/CommunityThemePack.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
}
}
2 changes: 1 addition & 1 deletion Amino.NET/Objects/GenericProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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; }
Expand Down
4 changes: 2 additions & 2 deletions Amino.NET/SubClient.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Amino.NET.Builders;
using Amino.Objects;
using Amino.Objects;
using Newtonsoft.Json;
using Newtonsoft.Json.Linq;
using RestSharp;
Expand All @@ -15,6 +14,7 @@
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Amino.Builders;

namespace Amino
{
Expand Down
39 changes: 23 additions & 16 deletions Amino.NET/helpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -235,28 +235,35 @@ public static List<Dictionary<string, long>> getTimeData()
/// </summary>
/// <param name="session"></param>
/// <returns></returns>
public static dynamic DecodeSid(string session)
public static Dictionary<string, object> 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<Dictionary<string, object>>(jsonString, options);

// Convert bytes to UTF-8 string and parse JSON directly
string jsonString = Encoding.UTF8.GetString(bytes);
return System.Text.Json.JsonSerializer.Deserialize<dynamic>(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(); }
}
}

0 comments on commit 19245fa

Please sign in to comment.