-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathCreator.cs
237 lines (206 loc) · 11.2 KB
/
Creator.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
using System;
using System.IO;
using System.Net;
using System.Security.Cryptography;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using Entropy.Responses;
using GeoCoordinatePortable;
using Google.Protobuf;
using Newtonsoft.Json;
using POGOLib.Official.LoginProviders;
using POGOLib.Official.Net;
using POGOLib.Official.Net.Authentication;
using POGOLib.Official.Net.Authentication.Data;
using POGOLib.Official.Util.Hash;
using POGOProtos.Inventory.Item;
using POGOProtos.Map.Fort;
using POGOProtos.Networking.Requests;
using POGOProtos.Networking.Requests.Messages;
using POGOProtos.Networking.Responses;
using RestSharp;
using Troschuetz.Random;
namespace Entropy
{
public class Creator
{
public static async Task<AccountCreationResult> Create(AccountCreationOptions options)
{
var random = new TRandom();
var client = new RestClient { Proxy = options.Proxy };
var page = client.Execute(new RestRequest("https://club.pokemon.com/us/pokemon-trainer-club/sign-up/",
Method.GET));
var csrf = string.Empty;
// Get CSRF
var match =
new Regex("<input type='hidden' name='csrfmiddlewaretoken' value='(\\w+)' />").Match(page.Content);
if (match.Success)
csrf = match.Groups[1].Value;
client.Execute(new RestRequest("https://club.pokemon.com/us/pokemon-trainer-club/sign-up/", Method.POST)
.AddParameter("csrfmiddlewaretoken", csrf)
.AddParameter("dob", options.Dob)
.AddParameter("country", "US")
.AddParameter("country", "US")
.AddParameter("picker__year", options.Dob.Split('-')[0])
.AddParameter("picker__month", options.Dob.Split('-')[1]));
await Task.Delay(random.Next(2000, 3000));
var user = client.Execute<VerifyUsernameResponse>(new RestRequest("https://club.pokemon.com/api/signup/" +
"verify-username", Method.POST)
.AddJsonBody(new {name = options.Username})
.AddHeader("X-CSRFToken", csrf));
// If username is in use, switch to a random suggestion from PTC
if (user.Data.InUse)
options.Username = random.Choice(user.Data.Suggestions);
var captcha = options.CaptchaService.Solve();
await Task.Delay(random.Next(1500, 2500));
var res = client.Execute(new RestRequest("https://club.pokemon.com/us/pokemon-trainer-club/sign-up/", Method
.POST)
.AddParameter("csrfmiddlewaretoken", csrf)
.AddParameter("username", options.Username));
return new AccountCreationResult
{
Successful = res.StatusCode == HttpStatusCode.Found,
Username = options.Username,
Password = options.Password
};
}
public static async Task HandleAccountAfterCreation(Configuration config, AccountCreationResult account)
{
var random = new TRandom();
POGOLib.Official.Configuration.Hasher = new PokeHashHasher(config.TutorialSettings.HashKey);
var client = await GetSession(new PtcLoginProvider(account.Username, account.Password),
config.TutorialSettings.Latitude, config.TutorialSettings.Longitude);
if (!await client.StartupAsync())
{
throw new SessionFailedError();
}
if (config.TutorialSettings.Level2 || config.TutorialSettings.Level5)
{
var ts = await Tutorial.GetTutorialState(client);
await Tutorial.CompleteTutorial(client, ts);
// Level 2: Stop here.
// Level 5: Keep going.
if (config.TutorialSettings.Level5)
{
while (client.Player.Stats.Level < 5)
{
var lat = client.Player.Latitude + random.NextDouble(0.005, -0.005);
var lng = client.Player.Longitude + random.NextDouble(0.005, -0.005);
client.Player.SetCoordinates(lat, lng);
foreach (var cell in client.Map.Cells)
{
foreach (var pokemon in cell.CatchablePokemons)
{
if (DistanceBetweenPlaces(client.Player.Longitude, client.Player.Latitude,
pokemon.Latitude, pokemon.Longitude) <= client.GlobalSettings.MapSettings
.EncounterRangeMeters / 1000)
{
var encRes = EncounterResponse.Parser.ParseFrom(await client.RpcClient.
SendRemoteProcedureCallAsync(new Request
{
RequestType = RequestType.Encounter,
RequestMessage = new EncounterMessage
{
EncounterId = pokemon.EncounterId,
SpawnPointId = pokemon.SpawnPointId,
PlayerLatitude = client.Player.Latitude,
PlayerLongitude = client.Player.Longitude
}.ToByteString()
}));
await Task.Delay(random.Next(825, 1250));
if (encRes.Status == EncounterResponse.Types.Status.EncounterSuccess)
{
while (true)
{
var r = CatchPokemonResponse.Parser.ParseFrom(
await client.RpcClient.SendRemoteProcedureCallAsync(new Request
{
RequestType = RequestType.CatchPokemon,
RequestMessage = new CatchPokemonMessage
{
EncounterId = pokemon.EncounterId,
HitPokemon = true,
SpawnPointId = pokemon.SpawnPointId,
NormalizedHitPosition = 1,
NormalizedReticleSize = random.NextDouble(1.7, 1.95),
Pokeball = ItemId.ItemPokeBall,
SpinModifier = 1
}.ToByteString()
}));
if (r.Status == CatchPokemonResponse.Types.CatchStatus.CatchSuccess ||
r.Status == CatchPokemonResponse.Types.CatchStatus.CatchEscape)
{
break;
}
}
}
}
}
foreach (var fort in cell.Forts)
{
if (DistanceBetweenPlaces(client.Player.Longitude, client.Player.Latitude,
fort.Longitude, fort.Latitude) <=
client.GlobalSettings.FortSettings.InteractionRangeMeters / 1000)
{
if (fort.Type == FortType.Checkpoint)
{
await client.RpcClient.SendRemoteProcedureCallAsync(new Request
{
RequestType = RequestType.FortDetails,
RequestMessage = new FortDetailsMessage
{
FortId = fort.Id,
Latitude = fort.Latitude,
Longitude = fort.Longitude
}.ToByteString()
});
await Task.Delay(random.Next(600, 750));
await client.RpcClient.SendRemoteProcedureCallAsync(new Request
{
RequestType = RequestType.FortSearch,
RequestMessage = new FortSearchMessage
{
FortId = fort.Id,
FortLatitude = fort.Latitude,
FortLongitude = fort.Longitude,
PlayerLatitude = client.Player.Latitude,
PlayerLongitude = client.Player.Longitude
}.ToByteString()
});
}
}
}
}
}
}
}
}
private static async Task<Session> GetSession(ILoginProvider loginProvider, double initLat, double initLong)
{
return await Login.GetSession(loginProvider, initLat, initLong);
}
// cos(d) = sin(φА)·sin(φB) + cos(φА)·cos(φB)·cos(λА − λB),
// where φА, φB are latitudes and λА, λB are longitudes
// Distance = d * R
private static double DistanceBetweenPlaces(double lon1, double lat1, double lon2, double lat2)
{
const double R = 6371; // km
var sLat1 = Math.Sin(Radians(lat1));
var sLat2 = Math.Sin(Radians(lat2));
var cLat1 = Math.Cos(Radians(lat1));
var cLat2 = Math.Cos(Radians(lat2));
var cLon = Math.Cos(Radians(lon1) - Radians(lon2));
var cosD = sLat1*sLat2 + cLat1*cLat2*cLon;
var d = Math.Acos(cosD);
var dist = R * d;
return dist;
}
private static double Radians(double x)
{
return x * Math.PI / 180;
}
}
public class SessionFailedError : Exception
{
}
}