Dinones / Nintendo-Switch-Pokemon-Shiny-Hunter

Search for shiny pokémon on your Nintendo Switch while sleeping!
Other
78 stars 4 forks source link

Infinite loop in "RESTART_GAME_1" state #11

Closed SoaringEagle93 closed 3 weeks ago

SoaringEagle93 commented 4 weeks ago

Before my game will launch I get the following message "Checking if the the software can be played.." Sometimes it will get past this screen and sometimes it doesn't. Even when it does get past this and launches the game, it still restarts the game before it can even load the save.

Dinones commented 4 weeks ago

Can you provide me more information about this issue?

  1. Did you follow all the instructions step by step? If yes, what step are you stuck on?
  2. What script are you trying to execute?
  3. Can you please upload a screenshot of the error?
SoaringEagle93 commented 4 weeks ago
  1. Yes I followed each step and made sure the controller connects and runs the test script. The part I am stuck on is when I try and run the Shiny Hunt.
  2. Shiny Hunter with Static Pokemon.
  3. https://youtu.be/RX0AM1clDsA Here is a video of what it is doing.

Thanks

Dinones commented 4 weeks ago

Thank you for the answer, it really helped me understand what is happening!

I didn't know this message even existed. I found this on the official Nintendo webpage: https://en-americas-support.nintendo.com/app/answers/detail/a_id/47555/~/%E2%80%9Cchecking-if-the-software-can-be-played%E2%80%A6%E2%80%9D-message-when-starting-software

Regarding the autorestart issue, the program automatically restarts the game when it gets stuck in some states for more than STUCK_TIMER_SECONDS, which is set to 30s by default. It sometimes happens that a button is not correctly received by the console and the program would get stuck in the same state forever. It is a correction measure.

May I ask you some questions:

  1. Is this your primary Nintendo Switch?
  2. Does the error disappear if you activate the Airplane mode?

This is the worst option (not recommended as you will lose a lot of time every reset), but you can increase the STUCK_TIMER_SECONDS in the Constants.py file to 45 or above if necessary and the game will not restart. As said, I highly recommend finding another solution if can you help me solve this issue.

SoaringEagle93 commented 4 weeks ago

So this is not my primary Switch as I purchase games digitally so that my fiance can play them on her Switch which is set as my primary. I am unable to set the switch to airplane mode when on the dock.

I did however change the Stuck_Timer_Seconds to 45 and that didn't resolve the issue. I then changed it to 60 and it launches the game now sometimes and gets into combat. It will stay on ENTER_COMBAT_2 for quite awhile before restarting the game again. ( I assume this is where the 60 seconds is coming into place.)

Also even with that timer change, the Game will still not launch sometimes. It seems when it is trying to launch the "controller" is spamming "A" which hits cancel on the checking message.

Not sure if it is related but the Encounter Count is staying at 0.

Dinones commented 4 weeks ago
  1. In order to solve the "Checking if the the software can be played..." issue: a. Update the program to the latest version of the program. You can either clone the repository again git clone https://github.com/Dinones/Nintendo-Switch-Pokemon-Shiny-Hunter.git or update the current one git pull origin master in your local repository folder. b. Now, you have two options:

    • (Recommended) Set your Nintendo Switch as your primary console (explained in the link previously shared in https://github.com/Dinones/Nintendo-Switch-Pokemon-Shiny-Hunter/issues/11#issuecomment-2299613946)
    • (Workaround) Go to the Macros.py script inside the Modules/ folder and change the restart_game_macro() function as follows: image This will make the macro wait some time between button presses. The error should be solved; if not, try to increase the sleep time to 2 or even more if necessary.
  2. Can you please upload a video of the ENTER_COMBAT_2 issue so I can check it? The encounter count is 0 because it increases in the following states your execution doesn't arrive at.

SoaringEagle93 commented 4 weeks ago

Ok I updated the program and made the 2 changes you listed in the Macros.py. The game seems to launch everytime now, however I am unable to get to load into a save.

It also waits much longer on the WAIT_PAIRING_SCREEN before moving on now.

Here is a video of the full process. https://www.youtube.com/watch?v=SanPFHMD5RA

SoaringEagle93 commented 4 weeks ago

I did some more testing and I changed for_in range(4): back to for_in range(10): and now I can get the save to load. Now I am back to the Enter_Combat_2. See the video below:

https://youtu.be/eNwMuEcg1bA

Dinones commented 3 weeks ago

Thank you for the videos; I really appreciate them! Now, I understand the problem. It seems your capture card is capturing slightly different colors from mine. For you to understand how the program works: Do you see the little purple line that moves around the bottom-left part of the screen? The program is checking the color of these pixels and comparing them with some values. Let's break this into two parts:

  1. In the https://github.com/Dinones/Nintendo-Switch-Pokemon-Shiny-Hunter/issues/11#issuecomment-2299913054 video, your state is not going from RESTART_GAME_1 to RESTART_GAME_2 because it is not detecting the black color of the screen. In my case, values are (B, G, R) = (7, 7, 7).

  2. In the https://github.com/Dinones/Nintendo-Switch-Pokemon-Shiny-Hunter/issues/11#issuecomment-2299928628 video, your state does not go from ENTER_COMBAT_2 to ENTER_COMBAT_3 because the program is not detecting the white colors of the text box. In my case, these values are (B, G, R) = (255, 255, 255).

I will need some help from you to solve this issue, since I'm not able to replicate it. I'd really appreciate it if you did the following steps so I could push a new version that works regardless of the capture card that is being used: 

  1. Put the Nintendo Switch on the dock station, wait in the Home menu (not the pairing one), and connect your physical joycons to it wirelessly. Connect the dock station to the computer using the capture card.
  2. Open a terminal in the Modules/ folder and run python3 Game_Capture.py. Select the option 2 "Check current capture device". Now you should be able to see the Nintendo Switch screen and control it using your joycons.
  3. Open the game. When you are on the black load screen, press the C key on your keyboard. You should see a message on the terminal that says "Image saved: xxxxx.png"; if not, click on the window that shows you the Nintendo output and try again.
  4. Take another screenshot of the Regirock encounter when the "Regirock appeared!" text box pops.
  5. Now, you should find two screenshots in the Media/Tests/ folder. Can you please tell me the color of the pixels that correspond to the black loading screen and white text box? If you don't know how to do it, you can send both images to me, or you can follow these steps:
    1. Go to the bottom of the Constants.py script and change the TESTING_IMAGE_PATH for one of the two images' path. It should look something like 'Media/Tests/xxxxx.png'.
    2. Open a terminal in the Modules/ folder and run python3 Image_Processing.py. Select the option 1 "Process image". The image should plot.
    3. Place your mouse on the white/black pixels you want to analyze. The color should be shown in the bottom-left corner of the plot, as seen in the following image: image
    4. Please, send me both color values and if you can, also attach both images to the response so I can also work with them.
    5. Repeat the process with the other image.

Really appreciate the effort, thank you!

Xion3582 commented 3 weeks ago

Screenshot_2024-08-21_17-45-37 Screenshot_2024-08-21_17-48-16

Here are the two screenshots, black screen is R:0 G:0 B:0 and white text box is R:255 G:255 B:255

Dinones commented 3 weeks ago

I uploaded a new version of the program, it now checks a range of values for each pixel instead of an exact value. Can you both @SoaringEagle93 and @Xion3582 confirm whether the issue is solved or not?

In order to download the latest version, you can either clone the repository again git clone https://github.com/Dinones/Nintendo-Switch-Pokemon-Shiny-Hunter.git or update the current one git pull origin master in your local repository folder.

SoaringEagle93 commented 3 weeks ago

Ok so after taking the screenshots and doing the image processing, the black screen is showing as R:0 G:0 B:0. The white part when the pokemon appears is showing as R:250 G:250 B:250.

Here are both screenshots. black white

TheFinalNuke commented 3 weeks ago

https://github.com/user-attachments/assets/5f1f17eb-ef8e-4cf0-a6b6-4118ecf83c00

I am experiencing the same infinite loop of resets even with the new version of the program (as of about an hour ago). It also took over 90 seconds to change from the pairing state to the restart game state.

SoaringEagle93 commented 3 weeks ago

I uploaded a new version of the program, it now checks a range of values for each pixel instead of an exact value. Can you both @SoaringEagle93 and @Xion3582 confirm whether the issue is solved or not?

In order to download the latest version, you can either clone the repository again git clone https://github.com/Dinones/Nintendo-Switch-Pokemon-Shiny-Hunter.git or update the current one git pull origin master in your local repository folder.

I tested the new version and was no longer getting stuck booting the game or getting stuck on ENTER_COMBAT_2. However now there is a weird stutter when the pokemon appears and it is causing the program to see it as a shiny. I will get a video of it happening after work. I ran out of time on my lunch when getting you the color values.

Dinones commented 3 weeks ago

I am experiencing the same infinite loop of resets even with the new version of the program (as of about an hour ago). It also took over 90 seconds to change from the pairing state to the restart game state.

I see... The error you are encountering is the same as for the other users. Please make sure you have updated the program to the latest version. In order to download the latest version, you can either clone the repository again git clone https://github.com/Dinones/Nintendo-Switch-Pokemon-Shiny-Hunter.git or update the current one git pull origin master in your local repository folder.

Dinones commented 3 weeks ago

I tested the new version and was no longer getting stuck booting the game or getting stuck on ENTER_COMBAT_2. However now there is a weird stutter when the pokemon appears and it is causing the program to see it as a shiny. I will get a video of it happening after work. I ran out of time on my lunch when getting you the color values.

We are making some improvements, we are almost there. The stutter you say happens because when the pokémon appears, exactly at the frame the following image shows, it performs text detection to recognize what pokémon has appeared (in this case, "Regirock"). If the resources of the VM are low it can produce a small lag. The program detects if the pokémon is shiny by calculating the stars' animation time. That spark could cause it to be higher than it should be.

image

The solution I propose to you is to slightly increase the SHINY_DETECTION_TIME in the Constants.py file from 2 (seconds) to 3 or maybe a little bit more. Just don't exceed the animation time, which is about 6 seconds.

SoaringEagle93 commented 3 weeks ago

Ok I got home from work and tried it again. Everything worked for about 3 resets before the stutter. I am going to up the SHINY_DETECTION_TIME per you recommendation. However do you think increasing the Memory or CPU allocated to the VM would help with the stutter? I already have it set to 4gb of memory and 4 CPU cores.

SoaringEagle93 commented 3 weeks ago

Changing the SHINY_DETECTION_TIME still results in false shiny detection when it stutters even with 4,5,or 6 seconds. Something else I have noticed is that when I check the Database it doesn't show Regirock, instead it shows the following: image

Dinones commented 3 weeks ago

Ok I got home from work and tried it again. Everything worked for about 3 resets before the stutter. I am going to up the SHINY_DETECTION_TIME per you recommendation. However do you think increasing the Memory or CPU allocated to the VM would help with the stutter? I already have it set to 4gb of memory and 4 CPU cores.

Regarding the resources allocated, they should be sufficient. The program only uses about 200 MB of RAM; you can try allocating more, but I don't think it will change anything. On the other hand, I have the same CPU allocated to my VM:

image

  1. The stutter you are referring to is that the screen freezes at some point or that it shows a completely white image for just a frame?
  2. Could you please upload a video of the encounter? I'd appreciate it, as it would help me understand the issue.

Changing the SHINY_DETECTION_TIME still results in false shiny detection when it stutters even with 4,5,or 6 seconds. Something else I have noticed is that when I check the Database it doesn't show Regirock, instead it shows the following: !

If you are increasing the SHINY_DETECTION_TIME and the issue still happens, it's because, for some reason, during the spike it's detecting a white background and, thus, wrongly detecting a shiny. Please send me the video if you can. 

Finally, regarding the Database, it does not affect the program at all, just saves the wrong pokémon in the database. This happens because there are different texts for different encounters, and I set the program to take the last word of the sentence (in the image's case, "Buizel"). So the sentence I was working with was "You encountered a wild Regirock!", but for legendary pokémons it is "Regirock has appeared!". I didn't think about it; thank you for reporting that, I'll change it in the next update.

image

SoaringEagle93 commented 3 weeks ago

I did verify that increasing the RAM to 8gb and the CPU to 8 cores still didn't fix the stutter so I set that back to 4gb and 4 cores. Here is a video of the lag/stutter. In the video it even works the first time but occurs on the second encounter. It seems to be the whole program locking up as even the time stops advancing until it unlocks.

https://youtu.be/uQg7esfAN90

As for the database issue, I will disregard since you will have to push a new update to fix that.

Dinones commented 3 weeks ago

Thank you for the video. I think the name recognition is causing the issue for some reason. Let's confirm that. In the Shiny_Hunter.py script, could you please comment on the line where the name is being recognized and just set the name "manually", as in the following image (Don't forget to save the file using Ctrl+S):

image

Does the issue disappear if you run the program after this change?

On the other hand, I have seen it takes a whole 2 minutes on the pairing screen after the controller is connected. This should not happen; the program should start a few seconds after the controller connects. I will work on a solution.

SoaringEagle93 commented 3 weeks ago

I did some testing and it seems that when I set pokemon_name to Regirock it fixes the stutter/lag. I was able to do 10 back to back encounters with no issue. I then set the code back and it failed on the second encounter. I went back and forth with that 3 different times with the same results. I think you are correct in saying the recognition is causing the issue.

In regards to the 2 minutes on the pairing screen. It started doing that when you had me update back 2 days ago

Dinones commented 3 weeks ago

I did some testing and it seems that when I set pokemon_name to Regirock it fixes the stutter/lag. I was able to do 10 back to back encounters with no issue. I then set the code back and it failed on the second encounter. I went back and forth with that 3 different times with the same results. I think you are correct in saying the recognition is causing the issue.

Thank you! It may be that the function is using so many resources, but for some reason, my computer does not make even a small stutter. I run the program on a minicomputer with superlimited resources, and it does not happen even there. I'll have to investigate a bit.

In regards to the 2 minutes on the pairing screen. It started doing that when you had me update back 2 days ago

So in the previous versions you downloaded, it was exiting the pairing menu right after connecting the controller?

SoaringEagle93 commented 3 weeks ago

I mentioned back in this comment that the pairing menu was staying up for a long time. This was the first time I noticed it.

https://github.com/Dinones/Nintendo-Switch-Pokemon-Shiny-Hunter/issues/11#issuecomment-2299913054

Is there a reason I should pull my capture card into the VM via webcam and not USB? I tried doing it that route and surprisingly enough it seemed to run without the stutter for a few encounters. I am going to let it run for a while and see what it does. Before I tried that I was up to 75 encounters and no stutter with the manual entry of the pokemon name.

Dinones commented 3 weeks ago

I mentioned back in this comment that the pairing menu was staying up for a long time. This was the first time I noticed it. #11 (comment)

Thank you for clarifying, it seems it is not correctly detecting the pairing menu gray color (see image). I will need some help from you, as I'm not able to replicate the issue on my computer.

image

Can you please try going to the Image_Processing.py script (inside the Modules/ folder) and adding the following line in the check_pixel_color() function: print(self.original_image[pixel[0]][pixel[1]], color, differences). It should look like this:

image

It should spam a message on the terminal. Please, before executing the program, make sure you are already at the pairing menu. Can you please send me the output that is being spammed in the terminal?

Is there a reason I should pull my capture card into the VM via webcam and not USB? I tried doing it that route and surprisingly enough it seemed to run without the stutter for a few encounters. I am going to let it run for a while and see what it does. Before I tried that I was up to 75 encounters and no stutter with the manual entry of the pokemon name.

There's no reason at all; I just solved the lower FPS issue that happened when it was connected as a USB device instead of a webcam, and it is easier and more convenient since you don't have to manually add the capture card every time you start the VM. I don't think it will affect the performance of the text detection, but anyways, it'd be nice if you could confirm that. Thank you.

SoaringEagle93 commented 3 weeks ago

Here is what spams in the terminal when I run the Shiny_Hunter.py with that code inserted.

image

Over the last 5 hours I have let it run with my capture card set as USB instead of webcam and had zero issues. That is even with letting the program determine the pokemon. (Once you fix the detection it will hopefully even see the correct pokemon.)

So it seems running as USB seems to be the fix for my case with the stutter. Its not an issue to me to have to select it each time, because I had to select it even as a webcam each time.

Dinones commented 3 weeks ago

That is even with letting the program determine the pokemon.

So can you confirm the stutter issue was solved by connecting the capture card as a USB device?

So it seems running as USB seems to be the fix for my case with the stutter. Its not an issue to me to have to select it each time, because I had to select it even as a webcam each time.

No, with the USB device system, you do not have to select it every time. Just repeat the same process as you did with the Bluetooth card.

Here is what spams in the terminal when I run the Shiny_Hunter.py with that code inserted.

Thank you for the image! It seems the problem is related to color detection again. For your information, the program has a default color to detect, which is slightly different depending on the capture card that is being used. To solve that issue, I added a range of ±5 points for every color, but as you can see, one value is getting a difference of 8 points. I tuned the color for the black load screen color and the white text box, but not this one.

I have pushed a new version of the program, please download the latest version. You can either clone the repository again git clone https://github.com/Dinones/Nintendo-Switch-Pokemon-Shiny-Hunter.git or update the current one git pull origin master in your local repository folder. Can you confirm if the issue has been solved?

SoaringEagle93 commented 3 weeks ago

Yes connecting my capture card via the USB device and not webcam fixed the stutter issue completely. Not sure why one is fine and the other isn't, however I ran it all night with zero issues. If it works then that doesn't bother me any.

The lastest version of the program has fixed where it was getting stuck on the WAIT_PAIRING_SCREEN. However now it seems to get stuck when launching the game the first time. It still shows WAIT_PAIRING_SCREEN even though it is launching the game, then switches to ENTER_STATIC_COMBAT_3. It does get past it eventually but it takes a little bit. Its fine after that first launch. I included a video to show it.

https://youtu.be/zYdfB91R3i4

Dinones commented 3 weeks ago

The lastest version of the program has fixed where it was getting stuck on the WAIT_PAIRING_SCREEN. However now it seems to get stuck when launching the game the first time. It still shows WAIT_PAIRING_SCREEN even though it is launching the game, then switches to ENTER_STATIC_COMBAT_3.

The same color detection issue is happening with the home screen. Could you please repeat this and provide me the otuput values that prints when you are on the home screen and in WAIT_PAIRING_SCREEN state? 

It does get past it eventually but it takes a little bit. Its fine after that first launch. I included a video to show it.

Regarding this, the game should be opened before executing the program. You have to load the game, wait in front of the pokémon and then go to the pairing screen without turning off the game. That's why it gets stuck.

Again, thank you so much! You are helping me a lot in solving this issue; I didn't even know this could happen.

SoaringEagle93 commented 3 weeks ago

image Here is the output while on the home screen while in the WAIT_PAIRING_SCREEN state.

Dinones commented 3 weeks ago

I have pushed a new version of the program, please download the latest version. You can either clone the repository again git clone https://github.com/Dinones/Nintendo-Switch-Pokemon-Shiny-Hunter.git or update the current one git pull origin master in your local repository folder. Can you confirm if the issue has been solved?

SoaringEagle93 commented 3 weeks ago

Ok I downloaded the latest version and it seems to resolved. Once the controller pairs it starts right up with the first encounter and continues from there. Really appreciate how fast you have been able to fix these color issues for me! Any update on getting the pokemon name to appear correct since Regirock's name shows up at the beginning of the text box and not the end?

Dinones commented 3 weeks ago

Thank you! I try to do my best! Enjoy your shiny hunting now (while you spend your free time on more important things)! 

Regarding the name issue, let's continue on this thread https://github.com/Dinones/Nintendo-Switch-Pokemon-Shiny-Hunter/issues/20. Could you please resend what's exactly the issue?