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

IOError: cannot identify image file <_io.BytesIO object at 0x0000000005137D00> #2

Closed MrE3gman closed 5 years ago

MrE3gman commented 6 years ago

Im having issues running the script, i have python 2.7 and instaled the python-pillow aswell, after getting my phone on adb I get this.

imagen

I'm not very literate in coding, so I'm not really sure whats going on, i have two 18:9 phones (Redmi 5 Plus and OPO 5T). Thanks in advance

marob commented 6 years ago

Hi @MrE3gman.

I think the problem comes from https://github.com/Azelphur/PokemonGo-CalcyIV-Renamer/blob/039103de533501be9605c2151412c6378e6010ef/pokemonlib.py#L46 where it should be (exec-out instead of shell):

_, stdout, _ = self.__adb(["adb", "-s", self.device_id, "exec-out", "screencap", "-p"])

You should try and tell us if it solves the problem.

I'm also working on a fork of the project here: https://github.com/marob/PokemonGo-CalcyIV-Renamer/tree/v2 that should solve this problem (as well as add new features I'm currently working on).

Regards

MrE3gman commented 6 years ago

could you please paste me the line as i should write it

PS: your branch gives me errors finding configparser

marob commented 6 years ago

Sorry if I was not clear. You should either keep the code of this project (not my fork) and replace the line https://github.com/Azelphur/PokemonGo-CalcyIV-Renamer/blob/039103de533501be9605c2151412c6378e6010ef/pokemonlib.py#L46 with:

_, stdout, _ = self.__adb(["adb", "-s", self.device_id, "exec-out", "screencap", "-p"])

or try to use my fork that fixes this issue. But you will indeed need other dependencies for my fork (pip install configparser and maybe others but I haven't documented it yet)

MrE3gman commented 6 years ago

After installing the modules i didn't have from your branch it gave me the same cannot identify image file error

marob commented 6 years ago

Can you try to run the following code (save it in a file or just copy/paste it in python REPL)?

import time
import subprocess
from PIL import Image
from io import BytesIO

args = ["adb", "exec-out", "screencap", "-p"]

p = subprocess.Popen([str(arg) for arg in args], stdout=subprocess.PIPE)
stdout, stderr = p.communicate()

image = Image.open(BytesIO(stdout))

image.save('{}.png'.format(time.time()))

It should create a png file in the current directory. And that file should be a valid image (try to open it with any image viewer).

Azelphur commented 6 years ago

@marob thanks for the suggestion on line 46, It's a good one and I've made the change.

@MrE3gman can you download the latest version and see if it works for you now?

MrE3gman commented 6 years ago

@Azelphur I get the exact same error, it changes the code of the object depending on where the calcy button is exactly but the error is the same imagen

Azelphur commented 6 years ago

@MrE3gman oops, I messed up the commit with the fix, can you update again and try the latest version?

MrE3gman commented 6 years ago

@Azelphur The error has been resolved, but now I'm facing a bunch of other problems that I think are caused due to the diference in the UI on an 18/9 device. I have to position the calcy button lower to make it actually work wich is why i think that might be the problem.

The issues are as following:

The renaming tap does not open the renaming dialog (prob is tapping lower than where it should)

On the Redmi 5 Plus I have gestures enabled so when it swipes it actually detects it as a back, I would suggest changing the swipe to get to the next pokemon for a tap under the fav icon on the top right of the screen.

Azelphur commented 6 years ago

That's gonna be interesting to solve. Can you send a screenshot of your phone with the calcy IV dialog open? I'll investigate.

MrE3gman commented 6 years ago

Here are a couple of screenshots of how calcy looks, first ones from the Redmi 5 Plus and the third one is from the OPO 5T. I added one without calcy open so you can see all the UI (Redmi 5 Plus). All screenshots are taken on 0.103.3. Calcy config is he exact same one on booth phones, was imported for theese screenshots. screenshot_2018-05-16-11-58-00-448_com nianticlabs pokemongo 1 screenshot_2018-05-16-12-02-11-270_com nianticlabs pokemongo 1 screenshot_20180516-115857 1

Azelphur commented 6 years ago

Thanks, you are correct it is an aspect ratio thing. Not sure how I'm going to solve it yet. Will need to give it some thought.

Tapping below the favourite icon is pretty cool - didn't know that was a thing. Will definitely be making that change once I figure out how best to support different aspect ratios.

MrE3gman commented 6 years ago

If you need any help on trying updated versions definetly reach me, I'd be glad to help.

marob commented 6 years ago

@Azelphur on my fork, I'm adding auto-detection based on image analysis to be resolution and ratio free. It's still in progress, but I think it's a good approach.

For example, I'm already detecting the Y coordinate of the pokemon name / rename button by image analysis. I'm also finding the CalcyIV coordinates by image analysis (to make it simpler, as I've no idea where the button can be on the screen and whether it has transparency or not, I'm going on the rename screen that has a green background to make it easier to spot).

N.B.: I wasn't aware of the "tapping under the favorite" feature either! That's cool and I think I'll use it. I've also recently discovered that there is no need to spot the exact location of the rename button as you can click on the name of the pokemon (so you only need the Y coordinate and use width/2 as X coordinate)

Azelphur commented 6 years ago

Why close? It's still a bug that needs fixing :)

Azelphur commented 6 years ago

@marob It does sound very good, I eagerly await your pull request :)

Azelphur commented 6 years ago

@MrE3gman I've done an ugly hack that should make things work on your 18:9 phone, until I come up with a better idea. Can you download the aspect-ratio-hack branch and let me know if it works for you?

MrE3gman commented 6 years ago

Seems to work better, but the script enters on a loop detecting if calcy has oppened when it checks pixel 49x129 it does not get the expected value even tho calcy is open. Also after a number of errors it seems that the script is designed to swipe to the next pokemon, triggering my gesture detection making a back and landing me on the pokemons list

TurnrDev commented 6 years ago

@Azelphur you can fix that by tapping the far left and far right of a pokemon to switch between them instead

image

Azelphur commented 6 years ago

I've just done some of this, mainly: Calcy IV communication is now done with intents, so it doesn't matter where the Calcy IV button is Advancing to next pokemon is now done with taps instead of swipes

Still work to be done, though.

marob commented 6 years ago

Hi @Azelphur. I'm really interested by your intent approach. How did you find the ACTION_ANALYZE_SCREEN and ACTION_HIDE_BUTTON intents? Is there a way to list them?

By the way, I previously suggested some improvements in a branch on my fork, but it lead to huge modifications... that lead to re-writing everything in Node (electron): https://github.com/marob/pokemon-go-toolbox It's a work in progress, but some of my new approaches may interest you:

Azelphur commented 6 years ago

Those are some really interesting features, cool stuff. Those intents are actually documented: https://www.reddit.com/r/CalcyIV/wiki/features

You can also get at a list of intents by running dumpsys package tesmath.calcy

What log file are you tailing to get at that info?

Azelphur commented 6 years ago

Actually just found it, it spits it out on logcat, that's really useful to know. :)

marob commented 6 years ago

Nice! I actually didn't think they were documented.

Azelphur commented 6 years ago

Have you managed to resolve aspect ratios? I haven't figured out a good way to do that, as of yet.

marob commented 6 years ago

I'm currently not trying to rename pokemons (at first), just scan them and display them in the UI (on desktop), so I don't have any needs for zone detection. But you can find some unused code that does pixel detection (that should't be affected by aspect ratio) in my project. You can also find usage of dumpsys window windows for CalcyIV overlay detection (that will probably soon be replaced by Intents!).

Azelphur commented 6 years ago

@MrE3gman with the latest patch, the script no longer uses screenshots to detect Calcy IV success, and now uses logcat. This should be the last piece in the puzzle to get things working on your phone.

Try running the script with --name_line_y=42.59 - you may also need to specify --ok_button_y and --save_button_y

Let me know if you're able to get it working :)

MrE3gman commented 5 years ago

I've actually tried to run the script and now i get this error, and also the calcy iv button disapears on my phone, it seems to bugg out the app

2018-07-22 22:54:46,417 - PokemonGo - DEBUG - Return code 0 Traceback (most recent call last): File "ivcheck.py", line 63, in p.read_logcat() File "D:\Escritorio\PokemonGo-CalcyIV-Renamer-master\pokemonlib.py", line 165, in read_logcat while select.select([self.logcat_task.stdout], [], [], 0.1)[0] != []: select.error: (10093, 'La aplicaci\xf3n no ha llamado a WSAStartup, o bien se ha producido un error en WSAStartup')

Azelphur commented 5 years ago

This should all be solved in the rewrite, you'll need to edit config.yaml to set the appropriate x,y locations for your 16:10 phones. :)

Can you give it another try and report back if it works for you?

Azelphur commented 5 years ago

Closing due to inactivity.