WildPokemon getTimeTillHiddenMs() returns large negative numbers
Description: Sometimes the getTimeTillHiddenMs() method returns a feasible number, but a lot of times it returns a huge negative number which obviously isn't correct. Could this be just an overflow of the int32 that holds it? If so is there a way to infer the actual value based on MAX_INT?
Example of a WildPokemon toString() encounter_id: 17736830237155595229 last_modified_timestamp_ms: 1469509425575 latitude: xx.15776268002814 longitude: -xx.74958767808612 spawn_point_id: "xxxxxa87fef" pokemon_data { pokemon_id: CATERPIE } time_till_hidden_ms: -630610344
(x's are just to obfuscate my actual location)
Its an unsigned long, there arent handled natively by Java, you need to use java 8 methods : Long.toUnsignedString(var) to print them into your console.
Note that these methods doesnt exist in Java 7 or under, you need to figurate a way to print them.
Ok I've been working on converting the returned value to an unsigned value. Now instead of something like -701128148 I get 3593839148, which is obviously not the amount of ms left. This number does decrease perfectly with time though. The digit in the thousands position decreases with seconds. I can't figure out why it corresponds to time because there definitely aren't 3593839 seconds until the despawn. Does anybody know what to do with this number after converting it to a Java friendly value? It doesn't seem to be in ms even though it is labeled as such and behaves like a time value.
if you bitshift the time 16 bits right (3593839148 >> 16) do you get the number you are expecting?
Thanks for the response. I just tried bitshifting a time (3590370382) and it gave me 54784, which looked promising but it doesn't decrease at all with seconds. I must be doing the unsigned conversion wrong.
Say the getTimeTillHiddenMs() method returns -704596914. I'm currently ANDing that result with 0xffffffffL but that obviously isn't the right thing to do. Specifically I'm doing this getTimeTillHiddenMs() & 0xffffffffL
I've also tried the following but it gave a huge number that I couldn't do anything with. I should note that this number also decreased properly with time.
public static String asString(long l) {
return l >= 0 ? String.valueOf(l) : toBigInteger(l).toString();
}
public static BigInteger toBigInteger(long l) {
final BigInteger bi = BigInteger.valueOf(l);
return l >= 0 ? bi : bi.add(BI_2_64);
}
Passing the result of getTimeTillHiddenMs() to the asString() function converts the number -705331251 to 18446744073004220365 which ticks down properly with time but the first say 12 digits from the left never change. Can you give me any more info about the value returned from the getTimeTillHiddenMs() function, like how many bits the original value is supposed to use? I get that Java 1.7 (which is needed for Android) can't natively use unsigned data types, but I'm not really sure what the number of bits for the returned number is supposed to be. Thanks so much for the help!
hmmm this proto: https://github.com/AeonLucid/POGOProtos/blob/master/src/POGOProtos/Map/Pokemon/WildPokemon.proto says it an int32, so there shouldnt be any need to deal with signdness.
My current theory is the proto is wrong, could you modify the protos and retry a few times and see what you get? i would try using a long first (because if it is an unsigned int it will fit into a normal java long)
Interesting, that makes sense why the number returned is so bizarre. I don't have much experience with protos (or data comm in general) but I'll give it a shot and see what happens. I think other APIs and sites like Pokevision have gotten the correct time so maybe you're right. I'll let you know what I find out.
Its pretty easy, you should see the protos checked out as submodule (resources/proto i think), data types can be found here https://developers.google.com/protocol-buffers/docs/proto, pretty much want to swap int32 with int64 right now and then do a gradle build, should update
Well I changed the int32 to int64 but it's still giving me times like -710980456 when I call getTimeTillHiddenMs(). Not sure where to go from here.
try fixed32, and then fixed64
Will do, thanks.
i was just thinking, maybe WildPokemon dont show expiry time, and CatchablePokemon do, hence why it works sometimes and not others (though i would expect 0 as default hmm)
Interesting, because I have seen sensible numbers on some of the WildPokemon in my scans. It's always either a nice 6 digit number like you would expect or a hideous negative number. I'll run some scans and cross-reference the CatchablePokemon with the WildPokemon. Maybe if they are both, the WildPokemon gets a valid expiry time.
getTimeTillHiddenMs() works for WildPokemon. I'm using it with no problems, except I do occasionally see a Pokemon appear and then disappear a second later. I wonder if that is because I am getting a negative getTimeTillHiddenMs().
So I tried both fixed32 and fixed64 but nothing changed. I did run a scan in a more populated area and got some interesting results. I found several WildPokemon and most of them had valid expiry values. There were 2 WildPokemon that had the crazy negative values, and the interesting thing is that these same Pokemon were found as CatchablePokemon from one of the points in the scan. And every CatchablePokemon had a valid expiry timestamp except for those 2 WildPokemon, who had a value of -1. Seems like some of these Pokemon just don't like to disclose their expiry for whatever reason. Here's some of the actual output:
Found WildPokemon:
encounter_id: 11618392653089048205
last_modified_timestamp_ms: 1469594001651
latitude: 34.256282027793844
longitude: -88.70152845516041
spawn_point_id: "88874ea2b5d"
pokemon_data {
pokemon_id: RATTATA
}
time_till_hidden_ms: -715186420
And here's the same Pokemon as a CatchablePokemon. This is verified by the GPS coords:
Found CatchablePokemon: CatchablePokemon(api=com.pokegoapi.api.PokemonGo@9a2f69d, spawnPointId=88874ea2b5d, encounterId=-6828351420620503411, pokemonId=RATTATA, expirationTimestampMs=-1, latitude=34.256282027793844, longitude=-88.70152845516041, encountered=false)
Thnakyou, im guessing the server is trying to hide that pokemon from the client, i think we should add checks to see if its negative and just set it to -1 in the wrapper object and add/modify isExpired
What if these are Pokémon that never expire?
Has anyone wtinessed those :p? I dont think it would make sense to have non expiring pokemon
I just scanned again and didn't see any sign of those 2 Pokemon so it looks like they despawn like the rest of them. Guess it could just be a glitch in their server since the majority of Pokemon work. It does seem to be a property of the spawn point because the one spawn point that is close to me never seems to have valid expiry times for CatchablePokemon or WildPokemon. Is it possible for the field before the expiry time to be running into the expiry time, maybe because of wrong bit positioning on our part?
yes it is possible, but implies something wrong with the PokemonData proto. Will need to do some network sniffing after work
Oh well it seems to be working for most Pokemon, so for now I'll just display whatever times I am able to get and ignore the negative ones. Thanks again for all the work you guys have done with this API!