Jump to content

Minesweeper Hack


w0uter
 Share

Recommended Posts

edit: due to trubbles with the datatypes i used regread instead.

edit2: small change so that it didnt continue clicking after we had already won.

evryone made one, so did i. but mine is more leet B)

Opt("MouseClickDelay",0)
Opt("MouseClickDownDelay",0)

Global Const $MEM_O = 0x8
Global Const $MEM_R = 0x10
Global Const $MEM_W = 0x20

Func _MemOpen($i_dwDesiredAccess, $i_bInheritHandle, $i_dwProcessId)
    
    $ai_Handle = DllCall("kernel32.dll", 'int', 'OpenProcess', 'int', $i_dwDesiredAccess, 'int', $i_bInheritHandle, 'int', $i_dwProcessId)
    If @error Then
        SetError(1)
        Return 0
    EndIf
    
    Return $ai_Handle[0]
EndFunc;==> _MemOpen()

Func _MemRead($i_hProcess, $i_lpBaseAddress, $i_nSize, $v_lpNumberOfBytesRead = '')
    
    Local $v_Struct = DllStructCreate ('byte[' & $i_nSize & ']')
    DllCall('kernel32.dll', 'int', 'ReadProcessMemory', 'int', $i_hProcess, 'int', $i_lpBaseAddress, 'int', DllStructGetPtr ($v_Struct, 1), 'int', $i_nSize, 'int', $v_lpNumberOfBytesRead)
    
    Local $v_Return = DllStructGetData ($v_Struct, 1)
    
    DllStructDelete ($v_Struct)
    
    Return $v_Return
    
EndFunc;==> _MemRead()

Func _MemClose($i_hProcess)
    
    $av_CloseHandle = DllCall('kernel32.dll', 'int', 'CloseHandle', 'int', $i_hProcess)
    Return $av_CloseHandle[0]
    
EndFunc;==> _MemClose()


ProcessSetPriority(@autoitpid, 5)
opt('MouseCoordMode', 0)

$i_pid = Run('winmine.exe')
ProcessWait($i_pid)

$v_Open = _MemOpen ($MEM_R, False, $i_pid)

;Width  0x1005334
$i_Width = _MemRead ($v_Open, 0x1005334, 1)
$i_Width = RegRead('HKEY_CURRENT_USER\Software\Microsoft\winmine', 'Width')
;Height 0x1005338
$i_Height = _MemRead ($v_Open, 0x1005338, 1)
$i_Height = RegRead('HKEY_CURRENT_USER\Software\Microsoft\winmine', 'Height')
;Number 0x1005330
$i_NonMines = $i_Width * $i_Height - _MemRead ($v_Open, 0x1005330, 2)
$i_NonMines = $i_Width * $i_Height - RegRead('HKEY_CURRENT_USER\Software\Microsoft\winmine', 'Mines')

Global $i_Array = 0
Dim $ai_Loc[$i_NonMines][2]

For $y = 0 To $i_Height - 1
    For $x = 0 To $i_Width - 1
        
  ;mine   0x1005340 + 32 * y + x
        If _MemRead ($v_Open, 0x1005340 + 32 * ($y + 1) + ($x + 1), 1) = -113 Then
;~           ConsoleWrite("X ")
            ContinueLoop
        Else
;~       ConsoleWrite("O ")
            $ai_Loc[$i_Array][0] = 23 + $x * 16
            $ai_Loc[$i_Array][1] = 112 + $y * 16
            $i_Array += 1
        EndIf
        
        
    Next
;~   consoleWrite(@LF)
Next

_MemClose ($v_Open)

$v_Open = UBound($ai_Loc) - 1

opt('WinTitleMatchMode', 4)

For $i = 0 To $v_Open
    MouseClick('left', $ai_Loc[$i][0], $ai_Loc[$i][1], 1, 0)
    if StringInStr(WinGetText('active'), 'OK') Then exitloop        
Next
Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

  • Replies 40
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

w0uter, that thing is uber leet! :o:graduated::):D

I keep getting highscores like 3 secs on minesweeper with this! Really, great job!

What is missing is a promt that asks if you wanna play again and one that asks on what board (I mean the different sizes) you wanna play!

Kepp up your good work! B)

Felix N.

Link to comment
Share on other sites

On my box the mouse is too low... i changed this

$ai_Loc[$i_Array][1] = 112 + $y * 16

to this

$ai_Loc[$i_Array][1] = 100 + $y * 16

and it works

only thing is its slower then some of the previous ones out there. old one 10 seconds, this one 18. this is on expert of course

Link to comment
Share on other sites

@Felix

i can get 2 if the mines are all in the top B)

@mikey

what os do you use ? and do you use a different windows skin ?

i dont see how this can be slower actually.

all it has to do is click ... all calculations are done before.

could you post a link to the "previous" one ?

Edited by w0uter

My UDF's:;mem stuff_Mem;ftp stuff_FTP ( OLD );inet stuff_INetGetSource ( OLD )_INetGetImage _INetBrowse ( Collection )_EncodeUrl_NetStat_Google;random stuff_iPixelSearch_DiceRoll

Link to comment
Share on other sites

As an example of using kernel32 to do memory access, this is pretty neat. But as a minesweeper cheat, it's a bit slow. Here's a minesweeper that cheats really fast, 4 seconds on expert :o , but no memory access. B)

#CS
    Computer Cheats at Minesweeper
    Works on any size grid (within reason)
    Computer plays minesweeper extremely fast

    Inspired by "Freekills Minesweeper Cheats"
#CE

Opt("MouseClickDelay",0)
Opt("MouseClickDownDelay",0)
Opt("WinTitleMatchMode", 3)

; Exit via Ctrl-Alt-X
HotKeySet("^!x", "MyExit")

; MouseMove speed where applicable
dim $speed = 0

dim $title = "Computer Cheats at Minesweeper"
dim $win = "Minesweeper"

dim $Width, $Height, $wX, $wY, $X, $Y, $X1, $Y1, $X2, $Y2
dim $i, $j, $color, $color1, $color2, $pos, $Cols, $Rows

If WinExists($win) = 0 then
    Run(@SystemDir & "\winmine.exe")
    Sleep(500)
endIf

WinActivate($win)
Sleep(50)

; Get Minesweeper info
$size = WinGetPos($win)
$wX = $size[0]
$wY = $size[1]
$Width = $size[2]
$Height = $size[3]

; Start coords of mine grid -relative to window
$X1 = 16
$Y1 = 97

; End coords of mine grid -relative to window
$X2 = $Width - 11
$Y2 = $Height - 11

; size of each box;W=16;H=16
; Determine Grid size from window size
$Cols = int(($X2 - $X1 + 1) / 16)
$Rows = int(($Y2 - $Y1 + 1) / 16)

if MsgBox(4, $title, "Ready?" & @CR & @CR & "Cols: " & $Cols & @CR & "Rows: " & $Rows & @CR ) <> 6 then exit

AutoItSetOption("MouseCoordMode", 0)
AutoItSetOption("PixelCoordMode", 1)

WinActivate($win)
MouseClick("left", $Width / 2, 69, 0); click new game


; Send happy fun code
Send("xyzzy{RSHIFT}{ENTER}")

;WinActivate($win)
For $i = 1 to $Rows
    For $j = 1 to $Cols
    ; Center of each box
        $X = int($X1 + (($X2 - $X1) / $Cols * $j) - 8)
        $Y = int($Y1 + (($Y2 - $Y1) / $Rows * $i) - 8)

        AutoItSetOption("PixelCoordMode", 0)
        $color1 = PixelGetColor($X - 7, $Y)
        AutoItSetOption("PixelCoordMode", 1)

    ; Unclicked/Unknown color
        If $color1 = 16777215 then
        ; Waive the mouse around a bit to get the pixel
        ; Center
            MouseMove($X, $Y, 0)

            $color = PixelGetColor(0, 0)

        ;If NOT $color = 0 Then
            If $color = 16777215 Then
            ;tooltip("cheat pixel: " & $color, $wX, $wY - 20)
                MouseClick("left")
            ElseIf $color = 0 Then
            ;continueloop
                MouseClick("right")
            Else
            ;tooltip("cheat pixel: " & $color, $wX, $wY - 20)
                tooltip("cheat mode seems disabled...", $wX , $wY - 20)
                Send("xyzzy{RSHIfT}{ENTER}")
            EndIf
        EndIf
    Next;j
Next;i
Link to comment
Share on other sites

@w0uter

Everytime I use your one it hits a mine B):o:graduated:


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

no wonder its slow, add this to the top

Opt("MouseClickDelay",0)
Opt("MouseClickDownDelay",0)
It now hits a mine faster B):o:graduated:


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

lmao.

OS ?

what mine ?

does it click anything else before blowing up ? B)

It usually hits first mine in the second row.

I run XP Pro SP2.

I am using Expert mode minesweeper.

Edited by BigDod


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

Link to comment
Share on other sites

do you move the mouse ?

I thought I might have so I just tried it again and made sure I didn't and it still hit a mine.


Time you enjoyed wasting is not wasted time ......T.S. Elliot
Suspense is worse than disappointment................Robert Burns
God help the man who won't help himself, because no-one else will...........My Grandmother

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...