Code Monkey home page Code Monkey logo

Comments (3)

nopeAnon avatar nopeAnon commented on June 12, 2024

I've tried implementing this

 # If Special K is running, this number is 3. If not, 1
    result = windll.user32.PrintWindow(hwnd, save_dc.GetSafeHdc(), 3)

but the fps went from 250-500 to 30-70. But it shouldn't matter too much since holocure is fixed at 60 fps.

diff --git a/holocure_fishing.py b/holocure_fishing.py
index f3cfc63..e2b5f10 100644
--- a/holocure_fishing.py
+++ b/holocure_fishing.py
@@ -12,7 +12,7 @@ import win32con, win32gui, win32ui
 from imgproc import templates, masks
 from send_input import press
 
-DEBUG = False
+DEBUG = True
 
 
 def main() -> None:
@@ -54,6 +54,8 @@ def main() -> None:
         scale = round(height / 360)
         roi = np.multiply(scale, BASE_ROI)
         img_src = capture_game(hwndMain, *roi)
+        if img_src is None:
+            continue
         # used to send input - a bit wasteful to call every loop though...
         win = win32ui.CreateWindowFromHandle(hwndMain)
 
@@ -172,6 +174,9 @@ def capture_game(hwnd, left: int, top: int, width: int, height: int):
     dataBitMap = win32ui.CreateBitmap()
     dataBitMap.CreateCompatibleBitmap(dcObj, width, height)
     cDC.SelectObject(dataBitMap)
+
+    result = ctypes.windll.user32.PrintWindow(hwnd, cDC.GetSafeHdc(), 3)
+
     cDC.BitBlt(
         (0, 0),
         (width, height),
@@ -188,7 +193,9 @@ def capture_game(hwnd, left: int, top: int, width: int, height: int):
     cDC.DeleteDC()
     win32gui.ReleaseDC(hwnd, wDC)
     win32gui.DeleteObject(dataBitMap.GetHandle())
-    return converted
+    if result == 1:
+        return converted
+    return None
 
 
 if __name__ == "__main__":

It should also fix python crashing, but I can't replicate the bug, so I can't test it if it works. If it's still crashing, please send the error message.

And please share your code if you can. We might learn something that might be causing the issue.

from automated-holocure-fishing.

tmmjelde avatar tmmjelde commented on June 12, 2024

So this is the error I have
Traceback (most recent call last):
File "holocure_fishing.py", line 244, in
main()
File "holocure_fishing.py", line 58, in main
img_src = wincap.get_screenshot()
File "C:\pythontest\org\Automated-HoloCure-Fishing-master\windowcapture.py", line 57, in get_screenshot
save_dc = mfc_dc.CreateCompatibleDC()
win32ui.error: CreateCompatibleDC failed

"My" code is this here - although it's really pieced together from everyone elses code. I didn't write anything noteworthy.
holocure_fishing.zip

I patched something together from this guy:
https://www.youtube.com/watch?v=WymCpVUPWQ4&list=PL1m2M8LQlzfKtkKq2lK5xko4X-8EZzFPI&index=4

Pretty interesting things he's done (classes), and he's also got a github.

However - his code also struggles with the black screen - so I've combined that with the other stuff.
He claims there's a fix for black screen in vid 5 - but alas it does not solve the issue. However, some comment in a video pointed me to the real black screen fix, which I've implemented into his code, then took that and implemented it into your code ;)
I didn't make notes along as I tried things unfortunately.

So anyway, I tried adding this to the right place:
if img_src is None:
continue

I already had something similar to this:
if result == 1:
return converted
return None

Problem now is I don't get an error and the Source window just freezes after a while.
No more images are captured, and hence no keypresses are sent.

I also noticed that when I first run the script in debug mode it starts off at 200 fps and around there, then it gradually lowers itself down to about 60 FPS before it crashes.
Not sure if there might be some sort of leak somewhere to cause that or what.

With all I've said, I should be very up front and also say I don't know either Python or OpenCV. I'm a Powershell guy, but we don't have these nice OpenCV things.
Your project got me interested in actually trying :)

I should also note that I changed the batch file to use my own Python version - so I'm running on 3.9.7 with OpenCV 4.2 (because someone said that would fix black screen - which it didn't and I'm lazy)
If you want me to change that back I can do that no problem.

from automated-holocure-fishing.

Hexus-One avatar Hexus-One commented on June 12, 2024

win32ui.error: CreateCompatibleDC failed

I also noticed that when I first run the script in debug mode it starts off at 200 fps and around there, then it gradually lowers itself down to about 60 FPS before it crashes.
Not sure if there might be some sort of leak somewhere to cause that or what.

Yep if i remember correctly there's a limit on how many Device Contexts (DC) there can be, so the function needs to release it safely in order to run continuously without crashing - so you need to make sure the relevant objects are deleted/released before you exit the function. I haven't looked at your code but my guess is that you have an early return/early exit somewhere without ReleaseDC and DeleteObject being called, so the program is accumulating DCs and hits the limit after some time.

from automated-holocure-fishing.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.