Creating a Game Bot using PyAutoGUI, OpenCV, and Pytesseract — Part 1

April–June 2024

When I was a kid, I used to play a MMORPG called Metin2. Like many RPGs, progression relied heavily on grinding repetitive tasks. I’d heard of hacks for the game, but my limited knowledge back then made me cautious — I didn’t want to risk viruses or getting my account stolen.

Recently, I came across a YouTube video demonstrating a simple fishbot. That brought back memories and sparked the idea: what if I tried building my own?

My first curiosity was: how did those old hacks even work? I learned they relied on memory manipulation and DLL injection — techniques that have become ineffective since more game logic has shifted to the server side.

I decided to try something different. I found a Metin2 private server that seemed to have protections against those classic hacks. That meant fewer botters and (hopefully) less admin scrutiny.

I began with simple tasks like fishing and killing monsters. First, I needed a way to automate input. While many downloadable tools exist, I wanted more control and opted for pyautogui.

It worked fine on my browser, but not in-game. There were no errors, but nothing was happening. After some digging, I discovered the issue: DirectX input in the game. The solution? pydirectinput. With that, inputs started working.

Next challenge: triggering input at the right moment. For attacking monsters, it was easy — just spam keys every few seconds as they respawned.

Fishing was trickier. The game displayed a fish icon and a chat message showing how many times to press space (between 1–5 times). That number changed randomly.

This was the fun part. I started fishing and observing. That’s when I noticed — the number of clicks was always in the same place in the chat!

I took screenshots, narrowed the detection area to just that part of the screen, and used pyautogui to read the number (by matching exact pixels). Then, my script would press space the right number of times and cast the rod again.

After fine-tuning (especially reducing the area scanned for text), the bot worked really well.