Skip to content

Commit a490672

Browse files
authored
Hash improvements, and other fixes (#838)
* Add getMaxStorage method to ItemBag and Pokebank * Use SSL for hash * Fix Evolutions containing unreleased pokemon evolutions, update hash API endpoint & change captcha user agent
1 parent b2c9f2a commit a490672

File tree

7 files changed

+51
-11
lines changed

7 files changed

+51
-11
lines changed

library/src/main/java/com/pokegoapi/api/gym/Gym.java

+10
Original file line numberDiff line numberDiff line change
@@ -286,4 +286,14 @@ public void updateState(GymState state) {
286286
proto = state.getFortData();
287287
clearDetails();
288288
}
289+
290+
@Override
291+
public int hashCode() {
292+
return getId().hashCode();
293+
}
294+
295+
@Override
296+
public boolean equals(Object obj) {
297+
return obj instanceof Gym && ((Gym) obj).getId().equals(getId());
298+
}
289299
}

library/src/main/java/com/pokegoapi/api/inventory/ItemBag.java

+7
Original file line numberDiff line numberDiff line change
@@ -317,4 +317,11 @@ public void addAwardedItems(LevelUpRewardsResponse levelUpResponse) {
317317
item.setCount(item.getCount() + itemAward.getItemCount());
318318
}
319319
}
320+
321+
/**
322+
* @return the maximum amount of items this item bag can store
323+
*/
324+
public int getMaxStorage() {
325+
return api.getPlayerProfile().getPlayerData().getMaxItemStorage();
326+
}
320327
}

library/src/main/java/com/pokegoapi/api/inventory/PokeBank.java

+8-1
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ public Map<PokemonFamilyId, Integer> releasePokemon(Pokemon... releasePokemon)
160160
.build();
161161
ServerRequest inventoryRequest = new ServerRequest(RequestType.GET_INVENTORY, inventoryMessage);
162162
ServerRequest releaseRequest = new ServerRequest(RequestType.RELEASE_POKEMON, releaseBuilder.build());
163-
api.getRequestHandler().sendServerRequests(releaseRequest, inventoryRequest);
164163
Map<PokemonFamilyId, Integer> lastCandies = new HashMap<>(api.getInventories().getCandyjar().getCandies());
164+
api.getRequestHandler().sendServerRequests(releaseRequest, inventoryRequest);
165165
try {
166166
GetInventoryResponse inventoryResponse = GetInventoryResponse.parseFrom(inventoryRequest.getData());
167167
ReleasePokemonResponse releaseResponse = ReleasePokemonResponse.parseFrom(releaseRequest.getData());
@@ -195,4 +195,11 @@ public Map<PokemonFamilyId, Integer> releasePokemon(Pokemon... releasePokemon)
195195
throw new RemoteServerException(e);
196196
}
197197
}
198+
199+
/**
200+
* @return the maximum amount of pokemon this pokebank can store
201+
*/
202+
public int getMaxStorage() {
203+
return api.getPlayerProfile().getPlayerData().getMaxPokemonStorage();
204+
}
198205
}

library/src/main/java/com/pokegoapi/api/map/fort/Pokestop.java

+10
Original file line numberDiff line numberDiff line change
@@ -311,4 +311,14 @@ public boolean hasLure(boolean updateFortDetails)
311311
return fortData.getActiveFortModifierList()
312312
.contains(ItemIdOuterClass.ItemId.ITEM_TROY_DISK);
313313
}
314+
315+
@Override
316+
public int hashCode() {
317+
return getId().hashCode();
318+
}
319+
320+
@Override
321+
public boolean equals(Object obj) {
322+
return obj instanceof Pokestop && ((Pokestop) obj).getId().equals(getId());
323+
}
314324
}

library/src/main/java/com/pokegoapi/api/pokemon/Evolutions.java

+12-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import POGOProtos.Enums.PokemonIdOuterClass.PokemonId;
1919
import POGOProtos.Networking.Responses.DownloadItemTemplatesResponseOuterClass.DownloadItemTemplatesResponse.ItemTemplate;
2020
import POGOProtos.Settings.Master.PokemonSettingsOuterClass.PokemonSettings;
21+
import com.pokegoapi.main.PokemonMeta;
2122

2223
import java.util.ArrayList;
2324
import java.util.HashMap;
@@ -29,6 +30,7 @@ public class Evolutions {
2930

3031
/**
3132
* Initializes these evolutions from PokemonSettings
33+
*
3234
* @param templates the templates to initialize from
3335
*/
3436
public static void initialize(List<ItemTemplate> templates) {
@@ -37,15 +39,21 @@ public static void initialize(List<ItemTemplate> templates) {
3739
if (template.hasPokemonSettings()) {
3840
PokemonSettings settings = template.getPokemonSettings();
3941
PokemonId[] parents = {};
42+
PokemonId pokemon = settings.getPokemonId();
4043
if (settings.getParentPokemonId() != null) {
41-
parents = new PokemonId[]{settings.getParentPokemonId()};
44+
PokemonSettings parentSettings = PokemonMeta.getPokemonSettings(settings.getParentPokemonId());
45+
List<PokemonId> parentEvolutions = parentSettings != null ? parentSettings.getEvolutionIdsList()
46+
: null;
47+
if (parentEvolutions != null && parentEvolutions.contains(pokemon)) {
48+
parents = new PokemonId[]{settings.getParentPokemonId()};
49+
}
4250
}
43-
Evolution evolution = new Evolution(parents, settings.getPokemonId());
44-
EVOLUTIONS.put(settings.getPokemonId(), evolution);
51+
Evolution evolution = new Evolution(parents, pokemon);
52+
EVOLUTIONS.put(pokemon, evolution);
4553
for (PokemonId parent : parents) {
4654
Evolution parentEvolution = EVOLUTIONS.get(parent);
4755
if (parentEvolution != null) {
48-
parentEvolution.addEvolution(settings.getPokemonId());
56+
parentEvolution.addEvolution(pokemon);
4957
}
5058
}
5159
}

library/src/main/java/com/pokegoapi/util/CaptchaSolveHelper.java

+1-4
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,7 @@
2727
import java.util.regex.Pattern;
2828

2929
public class CaptchaSolveHelper {
30-
public static final String USER_AGENT =
31-
"Mozilla/5.0 (Windows NT 10.0; WOW64) "
32-
+ "AppleWebKit/537.36 (KHTML, like Gecko) "
33-
+ "Chrome/54.0.2840.99 Safari/537.36";
30+
public static final String USER_AGENT = "Niantic App";
3431

3532
private static final List<Listener> LISTENERS = new ArrayList<>();
3633
private static final Queue<Listener> QUEUED_ADDITION = new LinkedBlockingDeque<>();

library/src/main/java/com/pokegoapi/util/hash/pokehash/PokeHashProvider.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import lombok.Getter;
2727
import net.iharder.Base64;
2828

29+
import javax.net.ssl.HttpsURLConnection;
2930
import java.io.BufferedReader;
3031
import java.io.DataOutputStream;
3132
import java.io.IOException;
@@ -39,7 +40,7 @@
3940
* This requires a key and is not free like the legacy provider.
4041
*/
4142
public class PokeHashProvider implements HashProvider {
42-
private static final String HASH_ENDPOINT = "http://pokehash.buddyauth.com/api/v122/hash";
43+
private static final String HASH_ENDPOINT = "https://pokehash.buddyauth.com/api/v121_2/hash";
4344

4445
private static final int VERSION = 5100;
4546
private static final long UNK25 = -8832040574896607694L;
@@ -64,7 +65,7 @@ public Hash provide(long timestamp, double latitude, double longitude, double al
6465
byte[] sessionData, byte[][] requests) throws HashException {
6566
Request request = new Request(latitude, longitude, altitude, timestamp, authTicket, sessionData, requests);
6667
try {
67-
HttpURLConnection connection = (HttpURLConnection) new URL(HASH_ENDPOINT).openConnection();
68+
HttpsURLConnection connection = (HttpsURLConnection) new URL(HASH_ENDPOINT).openConnection();
6869
connection.setRequestMethod("POST");
6970
connection.setRequestProperty("X-AuthToken", key);
7071
connection.setRequestProperty("content-type", "application/json");

0 commit comments

Comments
 (0)