-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from Goose-Bomb/dev
Ready for 7th release version
- Loading branch information
Showing
29 changed files
with
388 additions
and
47 deletions.
There are no files selected for viewing
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
using System.Windows.Media.Imaging; | ||
|
||
namespace GBCLV3.Models | ||
{ | ||
class Skin | ||
{ | ||
public bool IsSlim { get; set; } | ||
|
||
public BitmapImage Body { get; set; } | ||
|
||
public BitmapImage Cape { get; set; } | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
using System; | ||
using System.Diagnostics; | ||
using System.IO; | ||
using System.Net.Http; | ||
using System.Text; | ||
using System.Text.Json; | ||
using System.Threading.Tasks; | ||
using System.Windows; | ||
using System.Windows.Media.Imaging; | ||
using GBCLV3.Models; | ||
|
||
namespace GBCLV3.Services | ||
{ | ||
class SkinService | ||
{ | ||
#region Private Members | ||
|
||
private const string _profileServer = "https://sessionserver.mojang.com/session/minecraft/profile/"; | ||
|
||
private static readonly HttpClient _client = new HttpClient() { Timeout = TimeSpan.FromSeconds(15) }; | ||
|
||
private static readonly JsonSerializerOptions _jsonOptions | ||
= new JsonSerializerOptions { PropertyNamingPolicy = JsonNamingPolicy.CamelCase }; | ||
|
||
#endregion | ||
|
||
public async Task<Skin> GetSkinAsync(string uuid) | ||
{ | ||
try | ||
{ | ||
string profileJson = await _client.GetStringAsync(_profileServer + uuid); | ||
using var profileDoc = JsonDocument.Parse(profileJson); | ||
|
||
string profile = profileDoc.RootElement | ||
.GetProperty("properties")[0] | ||
.GetProperty("value") | ||
.GetString(); | ||
|
||
string skinJson = Encoding.UTF8.GetString(Convert.FromBase64String(profile)); | ||
using var skinDoc = JsonDocument.Parse(skinJson); | ||
var textures = skinDoc.RootElement.GetProperty("textures"); | ||
|
||
var skin = new Skin(); | ||
|
||
if (textures.TryGetProperty("SKIN", out var body)) | ||
{ | ||
string url = body.GetProperty("url").GetString(); | ||
skin.IsSlim = body.TryGetProperty("metadata", out _); | ||
|
||
var httpStream = await _client.GetStreamAsync(url); | ||
skin.Body = await DownloadImage(httpStream); | ||
} | ||
|
||
if (textures.TryGetProperty("CAPE", out var cape)) | ||
{ | ||
string url = cape.GetProperty("url").GetString(); | ||
var httpStream = await _client.GetStreamAsync(url); | ||
skin.Cape = await DownloadImage(httpStream); | ||
} | ||
|
||
return skin; | ||
} | ||
catch (HttpRequestException ex) | ||
{ | ||
Debug.WriteLine(ex.ToString()); | ||
return null; | ||
} | ||
catch (OperationCanceledException) | ||
{ | ||
Debug.WriteLine("[ERROR] Index json download time out"); | ||
return null; | ||
} | ||
catch (Exception ex) | ||
{ | ||
Debug.WriteLine(ex.ToString()); | ||
return null; | ||
} | ||
} | ||
|
||
public CroppedBitmap GetFace(BitmapImage bodySkin) | ||
{ | ||
int regionSize = bodySkin.PixelWidth / 8; | ||
return new CroppedBitmap(bodySkin, new Int32Rect(regionSize, regionSize, regionSize, regionSize)); | ||
} | ||
|
||
#region Private Methods | ||
|
||
private static async Task<BitmapImage> DownloadImage(Stream httpStream) | ||
{ | ||
using var memStream = new MemoryStream(); | ||
await httpStream.CopyToAsync(memStream); | ||
|
||
var img = new BitmapImage(); | ||
img.BeginInit(); | ||
img.StreamSource = memStream; | ||
img.CacheOption = BitmapCacheOption.OnLoad; | ||
img.EndInit(); | ||
img.Freeze(); | ||
|
||
return img; | ||
} | ||
|
||
#endregion | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.