Search in sources :

Example 6 with HashProvider

use of com.pokegoapi.util.hash.HashProvider in project PokeGOAPI-Java by Grover-c13.

the class CheckEvolutionExample method main.

/**
 * Displays pokemon evolutions
 *
 * @param args Not used
 */
public static void main(String[] args) {
    OkHttpClient http = new OkHttpClient();
    final PokemonGo api = new PokemonGo(http);
    try {
        // Login and set location
        HashProvider hasher = ExampleConstants.getHashProvider();
        api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
        api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
        // Get the evolution meta from the item templates received from the game server
        Evolutions evolutionMeta = api.itemTemplates.evolutions;
        System.out.println("Evolutions: ");
        for (PokemonId pokemon : PokemonId.values()) {
            List<PokemonId> evolutions = evolutionMeta.getEvolutions(pokemon);
            if (evolutions.size() > 0) {
                System.out.println(pokemon + " -> " + evolutions);
            }
        }
        System.out.println();
        System.out.println("Most basic: ");
        for (PokemonId pokemon : PokemonId.values()) {
            List<PokemonId> basic = evolutionMeta.getBasic(pokemon);
            if (basic.size() > 0) {
                // Check this is not the most basic pokemon
                if (!(basic.size() == 1 && basic.contains(pokemon))) {
                    System.out.println(pokemon + " -> " + basic);
                }
            }
        }
        System.out.println();
        System.out.println("Highest: ");
        for (PokemonId pokemon : PokemonId.values()) {
            List<PokemonId> highest = evolutionMeta.getHighest(pokemon);
            if (highest.size() > 0) {
                // Check this is not the highest pokemon
                if (!(highest.size() == 1 && highest.contains(pokemon))) {
                    System.out.println(pokemon + " -> " + highest);
                }
            }
        }
    } catch (RequestFailedException e) {
        // failed to login, invalid credentials, auth issue or server issue.
        Log.e("Main", "Failed to login, captcha or server issue: ", e);
    }
}
Also used : PtcCredentialProvider(com.pokegoapi.auth.PtcCredentialProvider) OkHttpClient(okhttp3.OkHttpClient) PokemonId(POGOProtos.Enums.PokemonIdOuterClass.PokemonId) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) PokemonGo(com.pokegoapi.api.PokemonGo) HashProvider(com.pokegoapi.util.hash.HashProvider) Evolutions(com.pokegoapi.api.pokemon.Evolutions)

Example 7 with HashProvider

use of com.pokegoapi.util.hash.HashProvider in project PokeGOAPI-Java by Grover-c13.

the class TransferMultiplePokemon method main.

/**
 * Transfers all bad pokemon from the player's inventory.
 */
public static void main(String[] args) {
    OkHttpClient http = new OkHttpClient();
    PokemonGo api = new PokemonGo(http);
    try {
        HashProvider hasher = ExampleConstants.getHashProvider();
        api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
        api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
        PokeBank pokebank = api.inventories.pokebank;
        List<Pokemon> pokemons = pokebank.pokemons;
        List<Pokemon> transferPokemons = new ArrayList<>();
        // Find all pokemon of bad types or with IV less than 25%
        for (Pokemon pokemon : pokemons) {
            PokemonId id = pokemon.getPokemonId();
            double iv = pokemon.getIvInPercentage();
            if (iv < 90) {
                if (id == PokemonId.RATTATA || id == PokemonId.PIDGEY || id == PokemonId.CATERPIE || id == PokemonId.WEEDLE || id == PokemonId.MAGIKARP || id == PokemonId.ZUBAT || iv < 25) {
                    transferPokemons.add(pokemon);
                }
            }
        }
        System.out.println("Releasing " + transferPokemons.size() + " pokemon.");
        Pokemon[] transferArray = transferPokemons.toArray(new Pokemon[transferPokemons.size()]);
        Map<PokemonFamilyId, Integer> responses = pokebank.releasePokemon(transferArray);
        // Loop through all responses and find the total amount of candies earned for each family
        Map<PokemonFamilyId, Integer> candies = new HashMap<>();
        for (Map.Entry<PokemonFamilyId, Integer> entry : responses.entrySet()) {
            int candyAwarded = entry.getValue();
            PokemonFamilyId family = entry.getKey();
            Integer candy = candies.get(family);
            if (candy == null) {
                // candies map does not yet contain the amount if null, so set it to 0
                candy = 0;
            }
            // Add the awarded candies from this request
            candy += candyAwarded;
            candies.put(family, candy);
        }
        for (Map.Entry<PokemonFamilyId, Integer> entry : candies.entrySet()) {
            System.out.println(entry.getKey() + ": " + entry.getValue() + " candies awarded");
        }
    } catch (RequestFailedException e) {
        // failed to login, invalid credentials, auth issue or server issue.
        Log.e("Main", "Failed to login. Invalid credentials, captcha or server issue: ", e);
    }
}
Also used : PtcCredentialProvider(com.pokegoapi.auth.PtcCredentialProvider) PokeBank(com.pokegoapi.api.inventory.PokeBank) OkHttpClient(okhttp3.OkHttpClient) PokemonId(POGOProtos.Enums.PokemonIdOuterClass.PokemonId) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) PokemonFamilyId(POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) PokemonGo(com.pokegoapi.api.PokemonGo) HashProvider(com.pokegoapi.util.hash.HashProvider) Pokemon(com.pokegoapi.api.pokemon.Pokemon) HashMap(java.util.HashMap) Map(java.util.Map)

Example 8 with HashProvider

use of com.pokegoapi.util.hash.HashProvider in project PokeGOAPI-Java by Grover-c13.

the class TutorialHandleExample method main.

/**
 * Goes through the tutorial with custom responses.
 *
 * @param args args
 */
public static void main(String[] args) {
    OkHttpClient http = new OkHttpClient();
    final PokemonGo api = new PokemonGo(http);
    try {
        // Add listener to listen for all tutorial related events, must be registered before login is called,
        // otherwise it will not be used
        api.addListener(new TutorialListener() {

            @Override
            public String claimName(PokemonGo api, String lastFailure) {
                // Last attempt to set a codename failed, set a random one by returning null
                if (lastFailure != null) {
                    System.out.println("Codename \"" + lastFailure + "\" is already taken. Using random name.");
                    return null;
                }
                System.out.println("Selecting codename");
                // Set the PTC name as the POGO username
                return ExampleConstants.LOGIN;
            }

            @Override
            public StarterPokemon selectStarter(PokemonGo api) {
                // Catch Charmander as your starter pokemon
                System.out.println("Selecting starter pokemon");
                return StarterPokemon.CHARMANDER;
            }

            @Override
            public PlayerAvatar selectAvatar(PokemonGo api) {
                System.out.println("Selecting player avatar");
                return new PlayerAvatar(PlayerGender.FEMALE, Avatar.Skin.YELLOW.id(), Avatar.Hair.BLACK.id(), Avatar.FemaleShirt.BLUE.id(), Avatar.FemalePants.BLACK_PURPLE_STRIPE.id(), Avatar.FemaleHat.BLACK_YELLOW_POKEBALL.id(), Avatar.FemaleShoes.BLACK_YELLOW_STRIPE.id(), Avatar.Eye.BROWN.id(), Avatar.FemaleBackpack.GRAY_BLACK_YELLOW_POKEBALL.id());
            }
        });
        HashProvider hasher = ExampleConstants.getHashProvider();
        api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
        api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
    } catch (RequestFailedException e) {
        Log.e("Main", "Failed to login!", e);
    }
}
Also used : PtcCredentialProvider(com.pokegoapi.auth.PtcCredentialProvider) OkHttpClient(okhttp3.OkHttpClient) TutorialListener(com.pokegoapi.api.listener.TutorialListener) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) PokemonGo(com.pokegoapi.api.PokemonGo) HashProvider(com.pokegoapi.util.hash.HashProvider) PlayerAvatar(com.pokegoapi.api.player.PlayerAvatar) StarterPokemon(com.pokegoapi.api.pokemon.StarterPokemon)

Example 9 with HashProvider

use of com.pokegoapi.util.hash.HashProvider in project PokeGOAPI-Java by Grover-c13.

the class Signature method setSignature.

/**
 * Given a fully built request, set the signature correctly.
 *
 * @param api the api
 * @param builder the RequestEnvelope builder
 * @throws RequestFailedException if an invalid request is sent
 */
public static void setSignature(PokemonGo api, RequestEnvelope.Builder builder) throws RequestFailedException {
    boolean usePtr8 = false;
    byte[][] requestData = new byte[builder.getRequestsCount()][];
    for (int i = 0; i < builder.getRequestsCount(); i++) {
        requestData[i] = builder.getRequests(i).toByteArray();
        RequestType requestType = builder.getRequests(i).getRequestType();
        if (requestType == RequestType.GET_PLAYER) {
            usePtr8 |= api.firstGP;
            api.firstGP = false;
        } else if (requestType == RequestType.GET_MAP_OBJECTS) {
            usePtr8 |= !api.firstGMO;
            api.firstGMO = false;
        }
    }
    double latitude = api.latitude;
    double longitude = api.longitude;
    double accuracy = api.accuracy;
    if (Double.isNaN(latitude)) {
        latitude = 0.0;
    }
    if (Double.isNaN(longitude)) {
        longitude = 0.0;
    }
    if (Double.isNaN(accuracy)) {
        accuracy = 0.0;
    }
    byte[] authTicket;
    if (builder.hasAuthTicket()) {
        authTicket = builder.getAuthTicket().toByteArray();
    } else {
        authTicket = builder.getAuthInfo().toByteArray();
    }
    long currentTimeMillis = api.currentTimeMillis();
    byte[] sessionHash = api.sessionHash;
    HashProvider provider = api.hashProvider;
    Hash hash = provider.provide(currentTimeMillis, latitude, longitude, accuracy, authTicket, sessionHash, requestData);
    long timeSinceStart = currentTimeMillis - api.startTime;
    SignatureOuterClass.Signature.Builder signatureBuilder = SignatureOuterClass.Signature.newBuilder().setLocationHash1(hash.locationAuthHash).setLocationHash2(hash.locationHash).setSessionHash(ByteString.copyFrom(sessionHash)).setTimestamp(currentTimeMillis).setTimestampSinceStart(timeSinceStart).setDeviceInfo(api.getDeviceInfo()).addAllLocationFix(LocationFixes.getDefault(api, builder, currentTimeMillis, RANDOM)).setActivityStatus(api.getActivitySignature(RANDOM)).setUnknown25(provider.getUNK25()).setUnknown27(// Currently random, generation is unknown
    RANDOM.nextInt(59000) + 1000);
    final SignatureOuterClass.Signature.SensorInfo sensorInfo = SensorInfo.getDefault(api, currentTimeMillis, RANDOM);
    if (sensorInfo != null)
        signatureBuilder.addSensorInfo(sensorInfo);
    List<Long> requestHashes = hash.requestHashes;
    for (int i = 0; i < builder.getRequestsCount(); i++) signatureBuilder.addRequestHash(requestHashes.get(i));
    Crypto crypto = new Crypto();
    SignatureOuterClass.Signature signature = signatureBuilder.build();
    byte[] signatureByteArray = signature.toByteArray();
    byte[] encrypted = crypto.encrypt(signatureByteArray, timeSinceStart);
    ByteString signatureBytes = SendEncryptedSignatureRequest.newBuilder().setEncryptedSignature(ByteString.copyFrom(encrypted)).build().toByteString();
    RequestEnvelope.PlatformRequest signatureRequest = RequestEnvelope.PlatformRequest.newBuilder().setType(PlatformRequestType.SEND_ENCRYPTED_SIGNATURE).setRequestMessage(signatureBytes).build();
    builder.addPlatformRequests(signatureRequest);
    if (usePtr8) {
        ByteString ptr8 = UnknownPtr8RequestOuterClass.UnknownPtr8Request.newBuilder().setMessage("15c79df0558009a4242518d2ab65de2a59e09499").build().toByteString();
        builder.addPlatformRequests(RequestEnvelope.PlatformRequest.newBuilder().setType(PlatformRequestType.UNKNOWN_PTR_8).setRequestMessage(ptr8).build());
    }
}
Also used : ByteString(com.google.protobuf.ByteString) Hash(com.pokegoapi.util.hash.Hash) Crypto(com.pokegoapi.util.hash.crypto.Crypto) HashProvider(com.pokegoapi.util.hash.HashProvider) SignatureOuterClass(POGOProtos.Networking.Envelopes.SignatureOuterClass) RequestEnvelope(POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope) RequestType(POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType) PlatformRequestType(POGOProtos.Networking.Platform.PlatformRequestTypeOuterClass.PlatformRequestType)

Example 10 with HashProvider

use of com.pokegoapi.util.hash.HashProvider in project PokeGOAPI-Java by Grover-c13.

the class TravelToPokestopExample method main.

/**
 * Travels to a Pokestop and loots it
 *
 * @param args args
 */
public static void main(String[] args) {
    OkHttpClient http = new OkHttpClient();
    PokemonGo api = new PokemonGo(http);
    try {
        HashProvider hasher = ExampleConstants.getHashProvider();
        api.login(new PtcCredentialProvider(http, ExampleConstants.LOGIN, ExampleConstants.PASSWORD), hasher);
        api.setLocation(ExampleConstants.LATITUDE, ExampleConstants.LONGITUDE, ExampleConstants.ALTITUDE);
        Set<Pokestop> pokestops = api.getMap().mapObjects.pokestops;
        System.out.println("Found " + pokestops.size() + " pokestops in the current area.");
        Pokestop destinationPokestop = null;
        for (Pokestop pokestop : pokestops) {
            // Check if not in range and if it is not on cooldown
            if (!pokestop.inRange() && pokestop.canLoot(true)) {
                destinationPokestop = pokestop;
                break;
            }
        }
        if (destinationPokestop != null) {
            Point destination = new Point(destinationPokestop.getLatitude(), destinationPokestop.getLongitude());
            // Use the current player position as the source and the pokestop position as the destination
            // Travel to Pokestop at 20KMPH
            Path path = new Path(api.getPoint(), destination, 20.0);
            System.out.println("Traveling to " + destination + " at 20KMPH!");
            path.start(api);
            try {
                while (!path.complete) {
                    // Calculate the desired intermediate point for the current time
                    Point point = path.calculateIntermediate(api);
                    // Set the API location to that point
                    api.setLatitude(point.getLatitude());
                    api.setLongitude(point.getLongitude());
                    System.out.println("Time left: " + (int) (path.getTimeLeft(api) / 1000) + " seconds.");
                    // Sleep for 2 seconds before setting the location again
                    Thread.sleep(2000);
                }
            } catch (InterruptedException e) {
                return;
            }
            System.out.println("Finished traveling to pokestop!");
            if (destinationPokestop.inRange()) {
                System.out.println("Looting pokestop...");
                PokestopLootResult result = destinationPokestop.loot();
                System.out.println("Pokestop loot returned result: " + result.getResult());
            } else {
                System.out.println("Something went wrong! We're still not in range of the destination pokestop!");
            }
        } else {
            System.out.println("Couldn't find out of range pokestop to travel to!");
        }
    } catch (RequestFailedException e) {
        Log.e("Main", "Failed to login, captcha or server issue: ", e);
    }
}
Also used : Path(com.pokegoapi.util.path.Path) PtcCredentialProvider(com.pokegoapi.auth.PtcCredentialProvider) OkHttpClient(okhttp3.OkHttpClient) RequestFailedException(com.pokegoapi.exceptions.request.RequestFailedException) PokemonGo(com.pokegoapi.api.PokemonGo) Pokestop(com.pokegoapi.api.map.fort.Pokestop) HashProvider(com.pokegoapi.util.hash.HashProvider) Point(com.pokegoapi.api.map.Point) PokestopLootResult(com.pokegoapi.api.map.fort.PokestopLootResult)

Aggregations

HashProvider (com.pokegoapi.util.hash.HashProvider)10 PokemonGo (com.pokegoapi.api.PokemonGo)9 PtcCredentialProvider (com.pokegoapi.auth.PtcCredentialProvider)9 OkHttpClient (okhttp3.OkHttpClient)9 RequestFailedException (com.pokegoapi.exceptions.request.RequestFailedException)8 Point (com.pokegoapi.api.map.Point)3 Pokemon (com.pokegoapi.api.pokemon.Pokemon)3 Path (com.pokegoapi.util.path.Path)3 ArrayList (java.util.ArrayList)3 PokemonId (POGOProtos.Enums.PokemonIdOuterClass.PokemonId)2 MapObjects (com.pokegoapi.api.map.MapObjects)2 Pokestop (com.pokegoapi.api.map.fort.Pokestop)2 PokemonFamilyId (POGOProtos.Enums.PokemonFamilyIdOuterClass.PokemonFamilyId)1 RequestEnvelope (POGOProtos.Networking.Envelopes.RequestEnvelopeOuterClass.RequestEnvelope)1 SignatureOuterClass (POGOProtos.Networking.Envelopes.SignatureOuterClass)1 PlatformRequestType (POGOProtos.Networking.Platform.PlatformRequestTypeOuterClass.PlatformRequestType)1 RequestType (POGOProtos.Networking.Requests.RequestTypeOuterClass.RequestType)1 ByteString (com.google.protobuf.ByteString)1 Battle (com.pokegoapi.api.gym.Battle)1 Gym (com.pokegoapi.api.gym.Gym)1