forked from Necrobot-Private/PokemonGo.RocketAPI
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.cs
151 lines (123 loc) · 5.56 KB
/
Client.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
#region using directives
using System;
using System.Net;
using PokemonGo.RocketAPI.Enums;
using PokemonGo.RocketAPI.Extensions;
using PokemonGo.RocketAPI.HttpClient;
using PokemonGo.RocketAPI.Rpc;
using POGOProtos.Enums;
using POGOProtos.Networking.Envelopes;
using PokemonGo.RocketAPI.Helpers;
#endregion
namespace PokemonGo.RocketAPI
{
public class Client : ICaptchaResponseHandler
{
public static WebProxy Proxy;
internal readonly PokemonHttpClient PokemonHttpClient;
public Download Download;
public Encounter Encounter;
public Fort Fort;
public Inventory Inventory;
public Rpc.Login Login;
public Map Map;
public Misc Misc;
public Player Player;
string CaptchaToken;
public KillSwitchTask KillswitchTask;
public Client(ISettings settings)
{
Settings = settings;
Proxy = InitProxy();
PokemonHttpClient = new PokemonHttpClient();
Login = new Rpc.Login(this);
Player = new Player(this);
Download = new Download(this);
Inventory = new Inventory(this);
Map = new Map(this);
Fort = new Fort(this);
Encounter = new Encounter(this);
Misc = new Misc(this);
KillswitchTask = new KillSwitchTask(this);
Player.SetCoordinates(Settings.DefaultLatitude, Settings.DefaultLongitude, Settings.DefaultAltitude);
InventoryLastUpdateTimestamp = 0;
Platform = settings.DevicePlatform.Equals("ios", StringComparison.Ordinal) ? Platform.Ios : Platform.Android;
// We can no longer emulate Android so for now just overwrite settings with randomly generated iOS device info.
if (Platform == Platform.Android)
{
DeviceInfo iosInfo = DeviceInfoHelper.GetRandomIosDevice();
settings.DeviceId = iosInfo.DeviceId;
settings.DeviceBrand = iosInfo.DeviceBrand;
settings.DeviceModel = iosInfo.DeviceModel;
settings.DeviceModelBoot = iosInfo.DeviceModelBoot;
settings.HardwareManufacturer = iosInfo.HardwareManufacturer;
settings.HardwareModel = iosInfo.HardwareModel;
settings.FirmwareBrand = iosInfo.FirmwareBrand;
settings.FirmwareType = iosInfo.FirmwareType;
// Clear out the android fields.
settings.AndroidBoardName = "";
settings.AndroidBootloader = "";
settings.DeviceModelIdentifier = "";
settings.FirmwareTags = "";
settings.FirmwareFingerprint = "";
// Now set the client platform to ios
Platform = Platform.Ios;
}
AppVersion = 4500;
SettingsHash = "";
CurrentApiEmulationVersion = new Version("0.45.0");
}
public void SetCaptchaToken(string token)
{
CaptchaToken = token;
}
public ISettings Settings { get; }
public string AuthToken { get; set; }
public double CurrentLatitude { get; internal set; }
public double CurrentLongitude { get; internal set; }
public double CurrentAltitude { get; internal set; }
public double CurrentAccuracy { get; internal set; }
public float CurrentSpeed { get; internal set; }
public AuthType AuthType => Settings.AuthType;
internal string ApiUrl { get; set; }
internal AuthTicket AuthTicket { get; set; }
internal string SettingsHash { get; set; }
internal long InventoryLastUpdateTimestamp { get; set; }
internal Platform Platform { get; set; }
internal uint AppVersion { get; set; }
public long StartTime { get; set; }
public Version CurrentApiEmulationVersion { get; set; }
public Version MinimumClientVersion { get; set; } // This is version from DownloadSettings, but after login is updated from https://pgorelease.nianticlabs.com/plfe/version
//public POGOLib.Net.Session AuthSession { get; set; }
public POGOLib.Official.LoginProviders.ILoginProvider LoginProvider { get; set; }
public POGOLib.Official.Net.Authentication.Data.AccessToken AccessToken { get; set; }
private WebProxy InitProxy()
{
if (!Settings.UseProxy) return null;
var prox = new WebProxy(new Uri($"http://{Settings.UseProxyHost}:{Settings.UseProxyPort}"), false, null);
if (Settings.UseProxyAuthentication)
prox.Credentials = new NetworkCredential(Settings.UseProxyUsername, Settings.UseProxyPassword);
return prox;
}
public bool CheckCurrentVersionOutdated()
{
if (MinimumClientVersion == null)
return false;
return CurrentApiEmulationVersion < MinimumClientVersion;
}
public static Version GetMinimumRequiredVersionFromUrl()
{
try
{
var client = new WebClient();
client.Encoding = System.Text.Encoding.UTF8;
var version = client.DownloadString("https://pgorelease.nianticlabs.com/plfe/version").Replace("\u0006", "").Replace("\n", "");
return new Version(version);
}
catch(Exception)
{
}
return null;
}
}
}