From 132dc8d59ce7cf85a10228bdd35c8e59f1583174 Mon Sep 17 00:00:00 2001 From: "Robert McLaws (Microsoft MVP)" Date: Sun, 6 Nov 2016 18:49:48 -0500 Subject: [PATCH 1/2] Update external dependencies. --- PokemonGo-UWP/project.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/PokemonGo-UWP/project.json b/PokemonGo-UWP/project.json index f0549583c..9ac771b08 100644 --- a/PokemonGo-UWP/project.json +++ b/PokemonGo-UWP/project.json @@ -1,15 +1,15 @@ { "dependencies": { - "HockeySDK.UWP": "4.1.4", + "HockeySDK.UWP": "4.1.5", "Microsoft.NETCore.UniversalWindowsPlatform": "5.2.2", "Newtonsoft.Json": "9.0.1", "NotificationsExtensions.Win10": "14332.0.2", "Octokit": "0.22.0", - "Template10": "1.1.12-preview-160712", + "Template10": "1.1.12", "UniversalMapControl": "0.3.45", "WinRTXamlToolkit.Controls.Gauge.UWP": "2.0.0", "Xam.Plugin.DeviceMotion": "1.1.2", - "XamlAnimatedGif": "1.1.5" + "XamlAnimatedGif": "1.1.6" }, "frameworks": { "uap10.0": {} From f06a826ef0d13339ada212e564049e3237df768e Mon Sep 17 00:00:00 2001 From: "Robert McLaws (Microsoft MVP)" Date: Mon, 7 Nov 2016 21:24:23 -0500 Subject: [PATCH 2/2] Release build cookie problem fix I swear my code worked in Debug mode. The System.Reflection.TypeExtensions package doesn't work in UWP projects compiled under .NET Native. --- .../Extensions/CookieContainerExtensions.cs | 45 +++++++++++++------ PokemonGoAPI/Login/PtcLogin.cs | 11 +++-- 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/PokemonGoAPI/Extensions/CookieContainerExtensions.cs b/PokemonGoAPI/Extensions/CookieContainerExtensions.cs index a14a98e88..39cf5093c 100644 --- a/PokemonGoAPI/Extensions/CookieContainerExtensions.cs +++ b/PokemonGoAPI/Extensions/CookieContainerExtensions.cs @@ -1,4 +1,6 @@ -using System.Collections.Generic; +using System.Collections; +using System.Collections.Generic; +using System.Dynamic; using System.Reflection; namespace System.Net @@ -19,21 +21,31 @@ public static class CookieContainerExtensions /// public static IEnumerable GetCookies(this CookieContainer cookieContainer, string domain) { +#if WINDOWS_UWP var domainTable = GetFieldValue(cookieContainer, "_domainTable"); - foreach (var entry in domainTable) +#else + var domainTable = GetFieldValue(cookieContainer, "m_domainTable"); +#endif + if (domainTable as IEnumerable != null) { - string key = GetPropertyValue(entry, "Key"); - - if (key.Contains(domain)) + foreach (var entry in domainTable) { - var value = GetPropertyValue(entry, "Value"); + string key = GetPropertyValue(entry, "Key"); - var internalList = GetFieldValue>(value, "_list"); - foreach (var li in internalList) + if (key.Contains(domain)) { - foreach (Cookie cookie in li.Value) + var value = GetPropertyValue(entry, "Value"); +#if WINDOWS_UWP + var internalList = GetFieldValue>(value, "_list"); +#else + var internalList = GetFieldValue>(value, "m_list"); +#endif + foreach (var li in internalList) { - yield return cookie; + foreach (Cookie cookie in li.Value) + { + yield return cookie; + } } } } @@ -49,9 +61,16 @@ public static IEnumerable GetCookies(this CookieContainer cookieContaine /// internal static T GetFieldValue(object instance, string fieldName) { - BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; - FieldInfo fi = instance.GetType().GetField(fieldName, bindFlags); - return (T)fi.GetValue(instance); + try + { + BindingFlags bindFlags = BindingFlags.Instance | BindingFlags.Public | BindingFlags.NonPublic | BindingFlags.Static; + FieldInfo fi = instance.GetType().GetField(fieldName, bindFlags); + return fi != null ? (T)fi.GetValue(instance) : (T)new object(); + } + catch (Exception ex) + { + return (T)new object(); + } } /// diff --git a/PokemonGoAPI/Login/PtcLogin.cs b/PokemonGoAPI/Login/PtcLogin.cs index 2477e38ee..9fb3875c4 100644 --- a/PokemonGoAPI/Login/PtcLogin.cs +++ b/PokemonGoAPI/Login/PtcLogin.cs @@ -79,13 +79,14 @@ public async Task GetAccessToken() { AccessToken accessToken; PtcLoginParameters loginData = null; - var cookies = Cookies.GetCookies("sso.pokemon.com").ToList(); + Cookies = new CookieContainer(); + //var cookies = Cookies.GetCookies("sso.pokemon.com")?.ToList(); // @robertmclaws: "CASTGC" is the name of the login cookie that the service looks for, afaik. // The second one is listed as a backup in case they change the cookie name. - if (!cookies.Any(c => c.Name == "CASTGC") || cookies.Count == 0) - { + //if (!cookies.Any(c => c.Name == "CASTGC") || cookies.Count == 0) + //{ loginData = await GetLoginParameters().ConfigureAwait(false); - } + //} var authTicket = await GetAuthenticationTicket(loginData).ConfigureAwait(false); accessToken = await GetOAuthToken(authTicket).ConfigureAwait(false); @@ -99,7 +100,6 @@ public async Task GetAccessToken() /// /// Responsible for retrieving login parameters for . /// - /// An initialized /// for . private async Task GetLoginParameters() { @@ -112,7 +112,6 @@ private async Task GetLoginParameters() /// /// Authenticates against the PTC login service and acquires an Authentication Ticket. /// - /// The instance to use for this request. /// The to use from this request. Obtained by calling . /// private async Task GetAuthenticationTicket(PtcLoginParameters loginData)