-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.cs
243 lines (227 loc) · 10.6 KB
/
Main.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
using MessagePack;
using System.Text;
namespace LiBCAT
{
/// <summary>
/// The base class.
/// </summary>
public static class Bcat
{
/// <summary>
/// The passphrase used for news decryption.
/// </summary>
public static readonly byte[] NewsPassphrase =
{
0x61, 0x63, 0x64, 0x61, 0x33, 0x35, 0x38, 0x62,
0x34, 0x64, 0x33, 0x32, 0x64, 0x31, 0x37, 0x66,
0x64, 0x34, 0x30, 0x33, 0x37, 0x63, 0x31, 0x62,
0x35, 0x65, 0x30, 0x32, 0x33, 0x35, 0x34, 0x32,
0x37, 0x61, 0x38, 0x35, 0x36, 0x33, 0x66, 0x39,
0x33, 0x62, 0x30, 0x66, 0x64, 0x62, 0x34, 0x32,
0x61, 0x34, 0x61, 0x35, 0x33, 0x36, 0x65, 0x65,
0x39, 0x35, 0x62, 0x62, 0x66, 0x38, 0x30, 0x66
};
/// <summary>
/// QLaunch's title ID, used for news.
/// </summary>
public const ulong QLaunchTID = 0x100000000001000;
internal static byte[] TBA(this string Input) => Encoding.ASCII.GetBytes(Input);
/// <summary>
/// Gets the news article JSON from the specified URL.
/// </summary>
/// <param name="URL">The target URL.</param>
/// <param name="AsJson">Whether to return it as raw data or a Json.</param>
/// <param name="TID">The target title ID.</param>
/// <param name="Passphrase">The target title's passphrase.</param>
/// <param name="isRetail">Whether the data being decrypted is for retail units.</param>
/// <returns>The news article JSON as a string.</returns>
public static object GetData(string URL, bool AsJson, ulong TID, string Passphrase, bool isRetail = true)
{
var BcatFile =
Crypto.DecryptBcatData
(
Crypto.GetBcatData(URL),
TID,
Encoding.ASCII.GetBytes(Passphrase),
isRetail
);
if (AsJson) return MessagePackSerializer.ToJson(BcatFile);
else return BcatFile;
}
/// <summary>
/// Provides a wrapper for the BCAT news API.
/// </summary>
public static class News
{
/// <summary>
/// A structure containing the target language and country.
/// </summary>
public struct Region
{
/// <summary>
/// A language; see the Languages class for a list.
/// </summary>
public string Language;
/// <summary>
/// A country; see the Countries class for a list.
/// </summary>
public string Country;
}
/// <summary>
/// Countries news is available in.
/// </summary>
public static class Countries
{
public const string Australia = "AU";
public const string Austria = "AT";
public const string Belgium = "BE";
public const string Brazil = "BR";
public const string Canada = "CA";
public const string CzechRepublic = "CZ";
public const string Denmark = "DK";
public const string Finland = "FI";
public const string France = "FR";
public const string Germany = "DE";
public const string HongKong = "HK";
public const string Hungary = "HU";
public const string Ireland = "IE";
public const string Italy = "IT";
public const string Japan = "JP";
public const string Mexico = "MX";
public const string Netherlands = "NL";
public const string NewZealand = "NZ";
public const string Norway = "NO";
public const string Poland = "PL";
public const string Portugal = "PT";
public const string Russia = "RU";
public const string SouthAfrica = "ZA";
public const string SouthKorea = "KR";
public const string Spain = "ES";
public const string Sweden = "SE";
public const string Switzerland = "CH";
public const string UnitedKingdom = "GB";
public const string UnitedStates = "US";
}
/// <summary>
/// Languages news is available in.
/// </summary>
public static class Languages
{
public const string Japanese = "ja";
public const string AmericanEnglish = "en-US";
public const string French = "fr";
public const string German = "de";
public const string Italian = "it";
public const string Spanish = "es";
public const string Chinese = "zh-CN";
public const string Korean = "ko";
public const string Dutch = "nl";
public const string Portuguese = "pt";
public const string Russian = "ru";
public const string Taiwanese = "zh-TW";
public const string BritishEnglish = "en-GB";
public const string CanadianFrench = "fr-CA";
public const string LatinAmericanSpanish = "es-419";
public const string SimplifiedChinese = "zh-Hans";
public const string TraditionalChinese = "zh-Hant";
}
/// <summary>
/// Returns the Nintendo News list for the specified region.
/// </summary>
/// <param name="Reg">A Region struct.</param>
/// <returns>Nintendo News list JSON as a string.</returns>
public static string GetNxNewsList(Region Reg) => MessagePackSerializer.ToJson(
Crypto.DecryptBcatData
(
Crypto.GetBcatData($"https://bcat-list-lp1.cdn.nintendo.net/api/nx/v1/list/nx_news?l={Reg.Language}&c[]={Reg.Country}"),
QLaunchTID,
NewsPassphrase
));
/// <summary>
/// Returns the news list for a specified region and topic ID.
/// </summary>
/// <param name="Reg">A Region struct.</param>
/// <param name="TopicID">The topic ID for the title you wish to retrieve news for.</param>
/// <returns>News list JSON as a string.</returns>
public static string GetNewsList(Region Reg, string TopicID) => MessagePackSerializer.ToJson(
Crypto.DecryptBcatData
(
Crypto.GetBcatData($"https://bcat-list-lp1.cdn.nintendo.net/api/nx/v1/list/{TopicID}?l={Reg.Language}&c[]={Reg.Country}"),
QLaunchTID,
NewsPassphrase
));
/// <summary>
/// Returns the icon for a topic.
/// </summary>
/// <param name="TopicID">The topic ID for the title you wish to retrieve an icon for.</param>
/// <returns>News list JSON as a string.</returns>
public static byte[] GetIcon(string TopicID) =>
Crypto.DecryptBcatData
(
Crypto.GetBcatData($"https://bcat-topics-lp1.cdn.nintendo.net/api/nx/v1/topics/{TopicID}/icon"),
QLaunchTID,
NewsPassphrase
);
/// <summary>
/// Returns details given a specified region and topic ID.
/// </summary>
/// <param name="Reg">A Region struct.</param>
/// <param name="TopicID">The topic ID for the title you wish to retrieve news for.</param>
/// <returns>News list JSON as a string.</returns>
public static string GetDetails(Region Reg, string TopicID) => MessagePackSerializer.ToJson(
Crypto.DecryptBcatData
(
Crypto.GetBcatData($"https://bcat-topics-lp1.cdn.nintendo.net/api/nx/v1/topics/{TopicID}/detail?l={Reg.Language}&c[]={Reg.Country}"),
QLaunchTID,
NewsPassphrase
));
/// <summary>
/// Gets the topics for a specified title ID.
/// </summary>
/// <param name="Reg">A Region struct.</param>
/// <param name="TitleID">The title ID of the game you wish to retrieve news for.</param>
/// <returns>The topics list JSON as a string.</returns>
public static string GetTopics(Region Reg, ulong TitleID) => MessagePackSerializer.ToJson(
Crypto.DecryptBcatData
(
Crypto.GetBcatData($"https://bcat-topics-lp1.cdn.nintendo.net/api/nx/v1/titles/{TitleID:x16}/topics?l={Reg.Language}&c[]={Reg.Country}"),
QLaunchTID,
NewsPassphrase
));
/// <summary>
/// Gets the news catalog for a specified region.
/// </summary>
/// <param name="Reg">A Region struct.</param>
/// <returns>The catalog JSON as a string.</returns>
public static string GetCatalog(Region Reg) => MessagePackSerializer.ToJson(
Crypto.DecryptBcatData
(
Crypto.GetBcatData($"https://bcat-topics-lp1.cdn.nintendo.net/api/nx/v1/topics/catalog?l={Reg.Language}&c[]={Reg.Country}"),
QLaunchTID,
NewsPassphrase
));
}
/// <summary>
/// Provides a wrapper for the BCAT data API.
/// </summary>
public static class Data
{
/// <summary>
/// Gets the BCAT data for a specified title ID.
/// </summary>
/// <param name="TitleID">The target title ID.</param>
/// <param name="Passphrase">The passphrase for the target title.</param>
/// <param name="Environment">What console environment to use.</param>
/// <param name="isRetail">Whether the data being decrypted is for retail units.</param>
/// <returns></returns>
public static string GetNxData(ulong TitleID, string Passphrase, string Environment = "lp1", bool isRetail = true) => MessagePackSerializer.ToJson(
Crypto.DecryptBcatData
(
Crypto.GetBcatData($"https://bcat-list-{Environment}.cdn.nintendo.net/api/nx/v1/list/nx_data_{TitleID:x16}"),
TitleID,
Encoding.ASCII.GetBytes(Passphrase),
isRetail
));
}
}
}