tmarenko / GenshinImpact_PaimonShutUp

Automatically mutes Paimon when she speaks
Apache License 2.0
39 stars 3 forks source link

Add GPU compatibility and Revise Process Detection #3

Closed Oafish1 closed 2 years ago

Oafish1 commented 2 years ago

OpenCV was returning a black screen when running Genshin on GPU, so we changed the PrintWindow function to use BitBlt instead. IsGenshinProcess also wasn't compiling for @snowystars1, so we changed some types.

snowystars1 commented 2 years ago

Also: The IsGenshinProcess() function wasn't identifying the Genshin Process File Path on my machine. I determined it had to do with the openProcess call and the access security flags that were passed in. The solution in this PR is kinda janky because it requires the program to be run as admin, which might be unfavorable for some users.

tmarenko commented 2 years ago

I determined it had to do with the openProcess call and the access security flags that were passed in.

Have you found out the root of this problem? Why PROCESS_ALL_ACCESS works when PROCESS_QUERY_INFORMATION | PROCESS_VM_READ doesn't? I'm not sure about forcing user to run app as admin

snowystars1 commented 2 years ago

Hey, so I actually looked into this more yesterday. I'm not really all that knowledgeable on Windows process access rights, but PROCESS_ACCESS_ALL wasn't working on my other buddy's machine. Seems like, when the openProcess call tries to get the handle for Genshin, it fails if the flags one passes in don't match the security rights the process has. What I found to work was actually this: I used PROCESS_QUERY_LIMITED_INFORMATION, and QueryFullProcessImageName(). This solution does NOT require the user to run as admin. (I arbitrarily increased the buffer because it was overflowing when not able to grab Genshin. 1024 is enough in practice) IsGenshinProcessImage

Also: there was one other large issue that I fixed yesterday. The height of the character name on the screen seems to depend on if the character has 1, 2, or 3 lines of text (which is kinda weird from a UI perspective haha), and also if the character has a nameplate. Sometimes, underneath the names, there will be flavor text like: "Kujou Clan Head", which also pushes the character name up on the screen. So if in the future they ever give Paimon a nameplate like: "Destoyer of Words", then her name would move on screen. My solution to this was a bit of a brute-force approach, but it seems to work for both my buddy and I: Capture I just essentially use DEAFULT_NAME_POS, and then start it at the middle of the screen height-wise, then shift it down by 1% until tesseract finds something that looks like "Paimon". This is a bit slower than yours because worst case there will be 45 iterations, but one could just increase the starting "top" and "bottom" values or lower the "bottom < .99" while-loop end condition. It still worked fine for us run-time wise, so I don't anticipate something like this being a problem. This issue was mainly visible on 2560x1440 resolution and potentially greater.

Also I didn't add a check for OUT_DIALOGUE_NAME_POS because I'm not really sure what that is.

tmarenko commented 2 years ago

I was thinking about PROCESS_QUERY_LIMITED_INFORMATION as well. Good to know that it fixes the problem. The OUT_DIALOGUE_NAME_POS position was actually just for the problem you're telling: sometimes Paimon can speak out of dialogue (like when you're in battle or exploring) and it changes nameplate position. For now I'm thinking that it would be better to hardcode these various positions because calling Tesseract 45 times would be much slower than 3-5 times (especially on low grade CPUs).

snowystars1 commented 2 years ago

That's understandable. My buddy took some measurements on potential hardcoded values, but he's at work right now. Once he gets off work I'll see if I can't get him to give those to me and I'll relay them here. I hope that Paimon's "open-world" name height doesn't also scale with the number of lines of text, but I have no idea where in-game to test for that haha.

tmarenko commented 2 years ago

I hope that Paimon's "open-world" name height doesn't also scale with the number of lines of text, but I have no idea where in-game to test for that haha.

I suggest to create a new account for testing, there are a lot of talking Paimon possibilities at the start of the game =) Also fishing may be

montgomerysamantha commented 2 years ago

Hi! Is this PR going to be merged sometime? I would love to use this program! It looks like the most recent release is a little out of date. @Oafish1 @snowystars1 @tmarenko

tmarenko commented 2 years ago

@montgomerysamantha Currently I don't have access to my PC where I can build and test this project. I'll be able to do it only at the next week. I'll probably add changes only for PROCESS_QUERY_LIMITED_INFORMATION flag. Without dynamic scan for Paimon's name position because it seems unnecessary (for now at least).

tmarenko commented 2 years ago

It looks like the most recent release is a little out of date.

Tested recent release on

Processor       AMD Ryzen 3 4300U with Radeon Graphics  2.70 GHz
Installed RAM       20.0 GB (19.4 GB usable)
GPU         AMD Radeon(TM) Graphics - Primary/Integrated    512 MB - DDR4 1333 MHz

with running GenshinImpact_PaimonShutUp.exe as administrator -> everything works fine.

montgomerysamantha commented 2 years ago

Ah, missed that part. I tried re-running it as admin and it's working now, thank you. The readme might need to be updated also.

tmarenko commented 2 years ago

The readme might need to be updated also.

Using PROCESS_QUERY_LIMITED_INFORMATION flag will no longer require to run as admin. So I'll just wait for next week to add it =)

tmarenko commented 2 years ago

Looks like still need to run as admin. Otherwise it can't get access to Windows Audio session. I'll update readme then.

tmarenko commented 2 years ago

So turns out that PROCESS_QUERY_LIMITED_INFORMATION doesn't work if 32-bit app tries to access 64-bit app. Unfortunately, this project was built as 32-bit app because I didn't know that it would matter. I'll look into possibility to convert it to 64-bit but no promises. With admin rights app works well as far as I can see.

@montgomerysamantha with https://github.com/tmarenko/GenshinImpact_PaimonShutUp/commit/e119579da02072cc9497dc08de78b173b90b41e6, app will ask for admin rights right on the start. Also I updated readme about it.

@Oafish1 @snowystars1 I'll close this PR because most of the changes doesn't work or even build for me. Not sure if it related to app 32-bit architecture or code itself. Feel free to reopen if necessary.

I added workflow that makes build from scratch: https://github.com/tmarenko/GenshinImpact_PaimonShutUp/actions/workflows/build.yml Maybe this will help to understand ins and outs of building process.