11using System ;
22using System . Runtime . InteropServices ;
3+ using Windows . Security . Authentication . Web . Core ;
34
45namespace MCLauncher {
56 class WUTokenHelper {
@@ -19,9 +20,13 @@ public static string GetWUToken() {
1920 }
2021 }
2122
22- private const int WU_ERRORS_START = 0x7ffc0200 ;
23- private const int WU_NO_ACCOUNT = 0x7ffc0200 ;
24- private const int WU_ERRORS_END = 0x7ffc0200 ;
23+ private const int WU_ERRORS_START = unchecked ( ( int ) 0x80040200 ) ;
24+ private const int WU_NO_ACCOUNT = unchecked ( ( int ) 0x80040200 ) ;
25+
26+ private const int WU_TOKEN_FETCH_ERROR_BASE = unchecked ( ( int ) 0x80040300 ) ;
27+ private const int WU_TOKEN_FETCH_ERROR_END = unchecked ( ( int ) 0x80040400 ) ;
28+
29+ private const int WU_ERRORS_END = unchecked ( ( int ) 0x80040400 ) ;
2530
2631 [ DllImport ( "WUTokenHelper.dll" , CallingConvention = CallingConvention . StdCall ) ]
2732 private static extern int GetWUToken ( [ MarshalAs ( UnmanagedType . LPWStr ) ] out string token ) ;
@@ -31,8 +36,33 @@ public WUTokenException(int exception) : base(GetExceptionText(exception)) {
3136 HResult = exception ;
3237 }
3338 private static String GetExceptionText ( int e ) {
39+ if ( e >= WU_TOKEN_FETCH_ERROR_BASE && e < WU_TOKEN_FETCH_ERROR_END )
40+ {
41+ var actualCode = ( byte ) e & 0xff ;
42+
43+ if ( ! Enum . IsDefined ( typeof ( WebTokenRequestStatus ) , e ) )
44+ {
45+ return $ "WUTokenHelper returned bogus HRESULT: { e } (THIS IS A BUG)";
46+ }
47+ var status = ( WebTokenRequestStatus ) Enum . ToObject ( typeof ( WebTokenRequestStatus ) , actualCode ) ;
48+ switch ( status )
49+ {
50+ case WebTokenRequestStatus . Success :
51+ return "Success (THIS IS A BUG)" ;
52+ case WebTokenRequestStatus . UserCancel :
53+ return "User cancelled token request (THIS IS A BUG)" ; //TODO: should never happen?
54+ case WebTokenRequestStatus . AccountSwitch :
55+ return "User requested account switch (THIS IS A BUG)" ; //TODO: should never happen?
56+ case WebTokenRequestStatus . UserInteractionRequired :
57+ return "User interaction required to complete token request (THIS IS A BUG)" ;
58+ case WebTokenRequestStatus . AccountProviderNotAvailable :
59+ return "Xbox Live account services are currently unavailable" ;
60+ case WebTokenRequestStatus . ProviderError :
61+ return "Unknown Xbox Live error" ;
62+ }
63+ }
3464 switch ( e ) {
35- case WU_NO_ACCOUNT : return "No account" ;
65+ case WU_NO_ACCOUNT : return "No Microsoft account found " ;
3666 default : return "Unknown " + e ;
3767 }
3868 }
0 commit comments