Azelphur / PokemonGo-CalcyIV-Renamer

Uses adb to send fake tap events to your phone, alongside Calcy IV to automatically rename all your pokemon.
GNU General Public License v3.0
77 stars 32 forks source link

If the internet is unstable or slow, the script fails after rename_ok #33

Closed esauvisky closed 5 years ago

esauvisky commented 5 years ago

Sometimes on unstable connections, PoGo hangs or takes a lot longer than usually after clicking OK on the rename box.

Is this happens, the script assumes everything went good and tries to send the intent for the next pokémon, which fails and makes calcy return the Bulbasaur 0CP from the previous issue I opened (which I'm closing now that I found the root cause)

How could we make the script check if the renaming dialog was successfully closed (and perhaps try to click OK several times, as that helps) before moving on to the next pokémon? Perhaps a screencap?

esauvisky commented 5 years ago

Relevant log below:

  DEBUG    | logcat line received: D/MainService(15114): Received values: Id: 149 (Mewtwo), Nr: 150, CP: 2332, Max HP: 136, Dust cost: 2500, Level: 20.0, FastMove Psycho Cut, SpecialMove Flamethrower, Gender 0, Level-up false:
  DEBUG    | RE_CALCY_IV matched
  DEBUG    | Running ['adb', '-s', '10.42.0.41:5555', 'shell', 'input', 'tap', 530, 880]
  DEBUG    | Return code 0
  INFO     | Waiting 0.5 seconds after [530, 880]...
  DEBUG    | Running ['adb', '-s', '10.42.0.41:5555', 'shell', 'input', 'keyevent', 'KEYCODE_PASTE']
  DEBUG    | Return code 0
  DEBUG    | Running ['adb', '-s', '10.42.0.41:5555', 'shell', 'input', 'keyevent', 'KEYCODE_MOVE_HOME']
  DEBUG    | Return code 0
  INFO     | Sending intent: am broadcast -a clipper.set -e text '»'
  DEBUG    | Running ['adb', '-s', '10.42.0.41:5555', 'shell', "am broadcast -a clipper.set -e text '»'"]
  DEBUG    | Return code 0
  DEBUG    | Running ['adb', '-s', '10.42.0.41:5555', 'shell', 'input', 'keyevent', 'KEYCODE_PASTE']
  DEBUG    | Return code 0
  DEBUG    | Running ['adb', '-s', '10.42.0.41:5555', 'shell', 'input', 'keyevent', 'KEYCODE_TAB']
  DEBUG    | Return code 0
  DEBUG    | Running ['adb', '-s', '10.42.0.41:5555', 'shell', 'input', 'keyevent', 'KEYCODE_ENTER']
  DEBUG    | Return code 0
  DEBUG    | Running ['adb', '-s', '10.42.0.41:5555', 'shell', 'input', 'tap', 540, 1050]
  DEBUG    | Return code 0
  INFO     | Waiting 2.1 seconds after [540, 1050]...
  DEBUG    | Running ['adb', '-s', '10.42.0.41:5555', 'shell', 'input', 'tap', 980, 280]
  DEBUG    | Return code 0
  INFO     | Waiting 0.8 seconds after [980, 280]...
  INFO     | Sending intent: am broadcast -a tesmath.calcy.ACTION_ANALYZE_SCREEN -n tesmath.calcy/.IntentReceiver --ez silentMode true --user 0
  DEBUG    | Running ['adb', '-s', '10.42.0.41:5555', 'shell', 'am broadcast -a tesmath.calcy.ACTION_ANALYZE_SCREEN -n tesmath.calcy/.IntentReceiver --ez silentMode true --user 0']
  DEBUG    | Return code 0
  DEBUG    | logcat line received: D/bh      (15114): setValues() - ID: 149 (Level 20.0), 2332 CP, 136 HP, 2500 dust cost
  DEBUG    | logcat line received: I/at      (15114): Levels to far apart -> no relation
  DEBUG    | logcat line received: I/chatty  (15114): uid=10195(tesmath.calcy) identical 3 lines
  DEBUG    | logcat line received: I/at      (15114): Levels to far apart -> no relation
  [...]
  DEBUG    | logcat line received: D/az      (15114): ********* Analyzing 5 screenshots ***********
  DEBUG    | logcat line received: D/az      (15114): isMonsterScreen: White box confidence: 0.24
  DEBUG    | logcat line received: D/az      (15114): isMonsterScreen: HP-Bar confidence: 0.00
  DEBUG    | logcat line received: I/az      (15114): isAppraisalScreen: false, finished after 0ms
  DEBUG    | logcat line received: D/az      (15114): Found no motivation heart - no arena screen
  DEBUG    | logcat line received: I/g       (15114): findArenaBossOrangeTimer() finished without success after 0ms
  DEBUG    | logcat line received: I/az      (15114): isArenaBossScreen() has finished (no) after 3ms
  DEBUG    | logcat line received: I/az      (15114): isCatchBossScreen() has finished (no) after 3ms
  DEBUG    | logcat line received: D/az      (15114): Screen has not enough of a white box in it to be a gym badge screen.
  DEBUG    | logcat line received: I/az      (15114): isCatchScreen() (configuration failed) has finished after 5ms
  DEBUG    | logcat line received: W/az      (15114): Did not detect any screen type
  DEBUG    | logcat line received: I/az      (15114): Screenshot analysis took 26ms
  DEBUG    | logcat line received: D/MainService(15114): Received values: Id: 0 (Bulbasaur), Nr: 1, CP: 0, Max HP: 0, Dust cost: 0, Level: 0.0, FastMove Wrap, SpecialMove Wrap, Gender 0, Level-up false:
  DEBUG    | RE_CALCY_IV matched
  INFO     | Sending intent: am broadcast -a clipper.get
  DEBUG    | Running ['adb', '-s', '10.42.0.41:5555', 'shell', 'am broadcast -a clipper.get']
  DEBUG    | Return code 0
  INFO     | RE_CLIPBOARD_TEXT matched.
  DEBUG    | Device clipboard is: »
  DEBUG    | Normalized clipboard is: »
/usr/lib/python3.7/asyncio/unix_events.py:861: RuntimeWarning: A loop is being detached from a child watcher with pending handlers
  RuntimeWarning)
Traceback (most recent call last):
  File "ivcheck.py", line 353, in <module>
    asyncio.run(Main(args).start())
  File "/usr/lib/python3.7/asyncio/runners.py", line 43, in run
    return loop.run_until_complete(main)
  File "/usr/lib/python3.7/asyncio/base_events.py", line 568, in run_until_complete
    return future.result()
  File "ivcheck.py", line 95, in start
    actions = await self.get_actions(values)
  File "ivcheck.py", line 259, in get_actions
    clipboard_values = await self.get_data_from_clipboard()
  File "ivcheck.py", line 177, in get_data_from_clipboard
    raise Exception("Clipboard regex did not match, got " + clipboard)
Exception: Clipboard regex did not match, got »
Azelphur commented 5 years ago

Hmm, tricky one to solve without slowing things down. I don't like the idea of taking a screencap after every scan.

It's interesting that it produces this exact bulbasaur entry, does it do this every time? Maybe we could detect the bulbasaur response, then fire off a screenshot and confirm we are "stuck" and then loop pressing the button and taking a screenshot until it goes away.

esauvisky commented 5 years ago

Did some boring QA by disconnecting the internet just before pressing OK... The CP0 Bulbassaur response does not happen every time unfortunately. Sometimes it just doesn't output anything and the script patiently waits forever for any output on the logcat – which is actually issue #27, so we can close that one as it's the same problem with a different behaviour.

Also, adding or values['cp'] == '0' to the if condition on check_pokemon()@ivcheck.py, like we did with the -1.0 float problem, does not solve the problem, as the script keeps sending the calcy intent but doesn't gets any output whatsoever. However, I think doing this plus adding a long timeout for a logcat without any meaningful messages (say 10-15 seconds), would be a good candidate for a solution. If these conditions happen, we could then just re-press the OK button or do the screencap thing.

:thinking:

esauvisky commented 5 years ago

This never happened again, I guess https://github.com/Azelphur/PokemonGo-CalcyIV-Renamer/commit/551fb2bb7e6aad00e20298e9bc6dd2324d67c9c6 had something to do with it and ended up fixing it.

Closing the last one!