Jump to content

Minesweeper bot


Alek
 Share

Recommended Posts

Using winapi memory reading :)

only works in xp (or less maybe)

#include <Winapi.au3>

Global Const $DataPtr = 0x1005330
Global Const $MinesPtr = 0x1005340
Global $MineSweeper_PID = Run("winmine.exe") ;run it
Global $hProcess = _WinAPI_OpenProcess(0x1F0FFF, 1, $MineSweeper_PID, True) ;open it

dim $read

WinWait("Minesweeper") ;wait for the minesweeper to load.

$DataStruct = DllStructCreate("dword mines;dword width;dword height")
_WinAPI_ReadProcessMemory($hProcess, $DataPtr, DllStructGetPtr($DataStruct), DllStructGetSize($DataStruct), $read) ;Get widht, height and number of mines :)


ConsoleWrite(DllStructGetData($DataStruct, "mines") &  " Mines in a  " & DllStructGetData($DataStruct, "width") & " by " & DllStructGetData($DataStruct, "height") &  " grid " & @CRLF)

WinActivate("Minesweeper")

$Width = DllStructGetData($DataStruct, "width") - 1
$Height = DllStructGetData($DataStruct, "height") - 1

For $y = 0 To $Height
    For $x = 0 To $Width
        Switch _IsMine($x,$y)
            Case -1 ;Already open
                ContinueLoop
            Case 0 ;Safe to click on
                ControlClick("Minesweeper", "", "", "left", 1, 20 + ($x *16),(16 * $y) + 60)
            Case 1 ;MINE!!!!
                ControlClick("Minesweeper", "", "", "right", 1, 20 + ($x *16),(16 * $y) + 60)
        EndSwitch
        ;Sleep(25) ;Looks cool :P
    Next
Next


Func _IsMine($x, $y)
    $buffer = DllStructCreate("ubyte mine")
    _WinAPI_ReadProcessMemory($hProcess, $MinesPtr + (32 * ($y + 1)) + ($x + 1) , DllStructGetPtr($buffer), DllStructGetSize($buffer), $read)
    If DllStructGetData($buffer, "mine") = 0x40 Then
        Return -1
    ElseIf DllStructGetData($buffer, "mine") = 0x0F Then
        Return 0
    ElseIf DllStructGetData($buffer, "mine") = 0x8f Then
        Return 1
    EndIf
EndFunc

[font="Impact"]Never fear, I is here.[/font]

Link to comment
Share on other sites

  • 3 weeks later...

Nice >_<.

How of curiosity, who did you figure out how to use the dll file? I mean I know what they do, but how do you know what the... (for lack of a better word choice) stuff in it does?

And the sleep(25) is neccissary if you're trying to solve an Expert puzzle :(. Else it goes too fast for it.

-Pandemic

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...