Sign in to follow this  
Followers 0
rush4hire

Save game codes from screen and enter them.

4 posts in this topic

Here's a pretty good example of a fast OCR method. (~ 200 ms)

It's not all versitile though.

It's made to be fast and it's only for one game.

Link to the application:

http://www.rush4hire.com/files/ddcodes.exe

Script with instructions:

;===============================================================================================
;  Save and enter codes from Warcraft 3 custom map Dark Deeds 6
;
;  Hotkeys are:
;  F5 to save code from screen.
;  F6 to enter last saved code.
;
;  Notes:
;  If code is not entered when you attempt to retrieve, code is gotten from file.
;  You have to have the question mark building at the bottom right of the map selected
;   - so it will punch in your code.
;  Getting code from screen takes about 200 ms on my computer.
;   - To test this uncomment the 2 timer functions
;  Will probably work on other Dark Deeds version, as long as the code is pink..
;  Might add more comments later...
;
;  Author: rush4hire
;  Version: 1.00
;================================================================================================


Global $current_code
Global $current_number_code
HotKeySet ( "{F5}", "HotKey_GetCode" )
HotKeySet ( "{F6}", "enterDDcode" )

;~ Global $file = FileOpen("debuglog.txt", 1)

Global $numbers[12]
$numbers[0]="...111111..."
$numbers[1]=".1111111111."
$numbers[2]="..........1."
$numbers[3]="1..........1"
$numbers[4]="........1..."
$numbers[5]=".11111.....1"
$numbers[6]=".....1111..."
$numbers[7]=".........11."
$numbers[8]="........11.."
$numbers[9]="...111......"
$numbers[10]=".......1...."
$numbers[11]="............"
Global $sendkeys[10] = ["p","q","w","e","r","t","y","u","i","o"]

While 1
        sleep(2000)
WEnd

Func ddResponseSound($e)
        If $e Then
                SoundPlay(@WindowsDir & "\media\tada.wav",1)
        Else
                SoundPlay(@WindowsDir & "\media\chord.wav",1)
        EndIf
EndFunc


Func getLastCodeFromFile($e)
        $size = FileGetSize ("savedDDcodes.txt")
        If @error Then Return ""
        If $size = 0 Then Return ""
        $f = FileOpen ("savedDDcodes.txt", 0)
        $text = FileRead($f, $size)
        FileClose ($f)
        $arr = stringSplit($text, @CRLF, 1)
        If @error Then Return ""
        For $i = $arr[0] to 1 Step -1
                If StringLen($arr[$i]) > 0 Then
                        $x = stringSplit($arr[$i], " ")
                        $x = stringSplit($x[1], ",")
                        $current_number_code = $x[1]
                        Return $x[2]
                EndIf
        Next
        Return ""
EndFunc

Func enterDDcode()
        $len = StringLen($current_code)
        If $len < 20 Then
                $current_code = getLastCodeFromFile(0)
                $len = StringLen($current_code)
                If $len < 20 Then
                        ddResponseSound(0)
                        Return
                EndIf
        EndIf
        ClipPut($current_number_code)
        ddResponseSound(1)
        For $i = 1 to $len
                send(StringMid($current_code,$i,1))
                sleep(30)
        Next
        send("x")
EndFunc

Func HotKey_GetCode()
        $x = getDDcode()
        ddResponseSound($x)
;~      ddResponseSound(getDDcode())
EndFunc


Func getDDcode()
$begin = TimerInit()

Opt("PixelCoordMode", 0)
;$color = 16195831
$title = WinGetTitle("WC3S", "")
$size = WinGetClientSize ( $title )

        ;find about where the pink text is.
$xvar = PixelSearch ( 125, 30, $size[0], $size[1], 0xF720F7, 80 )
If @error Then Return 0
        
        ; There may be some pink text comming first that's too far over to the left.
        ; so start search again below that text.
If $xvar[0] < 175 Then
        $xvar = PixelSearch ( 175, $xvar[1]+20, $size[0], $size[1], 0xF720F7, 30 )
EndIf
If @error Then Return 0

$xstart = $xvar[0] - 3
$ystart= $xvar[1] - 5
; narrow it down
$maxx = $xstart+300
$maxy = $ystart+11

; narrow stuff down
While 1
        $arr = PixelSearch ( $xstart, $ystart, $maxx, $ystart, 0xF720F7, 20)
        If not @error Then ExitLoop
        $ystart+=1
        $maxy+=1
WEnd

While 1
        $arr = PixelSearch ( $xstart, $ystart, $xstart, $maxy, 0xF720F7, 20)
        If Not @error Then ExitLoop
        $xstart+=1
        $maxx+=1
WEnd

Dim $temp[14] = [".",".",".",".",".",".",".",".",".",".",".",".",".","."]
;~ Dim $o[301]

Dim $c = 0
Dim $IsDone = 0
Dim $savestr1 = ""
Dim $savestr2 = ""
;~ FileWriteLine("debuglog.txt", @HOUR & ":" & @MIN)

For $i = $xstart to $maxx
    $start = $ystart
        $x = $temp
    While 1
        ;PixelSearch ( left, top, right, bottom, color [, shade-variation] [, step]] )
        $arr = PixelSearch ( $i, $start, $i, $maxy, 0xF720F7, 20)
        If @error Then ExitLoop
        $x[$arr[1]-$ystart] = 1
        $start = $arr[1]+1
        If $start = $maxy Then ExitLoop
        WEnd
;~      $o[$c] = $x
    $t = getnumber($x)
        If $IsDone Then
                ;lookin for a blank colum to start a new letter.
                If $t = 11 Then
                        $IsDone = 0
                EndIf       
    ElseIf $t > -1 and $t < 11 Then
                $IsDone = 1
                If $t = 10 Then
                        $savestr1 &= "-"
;            $c+=1
                Else
                        $savestr1 &= $t
                        $savestr2 &= $sendkeys[$t]
                EndIf
        EndIf
Next
$current_code = $savestr2
ClipPut($savestr1)
$current_number_code = $savestr1
FileWriteLine("savedDDcodes.txt", $savestr1 &","& $savestr2 &" "& @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN &" saved in "& TimerDiff($begin) &" ms")
;~ InputBox ( "", "" , TimerDiff($begin) )
Return 1

EndFunc


Func getnumber($arr)
        $x = dds($arr)
        For $i = 0 to 11
                If $x = $numbers[$i] Then Return $i
        Next
        Return -1
EndFunc


Func dds($arr)
        $x=""
        For $i = 0 to 11
                $x &=  $arr[$i]
        Next
;~     FileWriteLine("debuglog.txt", $x )
;~  & $arr[12] & $arr[13]
        Return $x
EndFunc

Fully tested on screenshots and in the game.

This is the kind of log it makes:

22899-83588-21083-29814-014,wwiooietiiwqpiewoiqrpqr 2006/07/05 00:15 saved in 194.293 ms
87398-11706-08392-28698-009,iueoiqqupypieowwiyoippo 2006/07/05 00:17 saved in 194.028 ms
81508-32367-98502-28946-019,iqtpieweyuoitpwwiorypqo 2006/07/05 00:22 saved in 190.887 ms

There's the actual code as seen in the screenshots, and the keys to send to enter the code on the little number pad in the game.

Here's a screenshot of the game screen where it saves the code in pink text.

http://www.rush4hire.com/examples1/dd6screen_text.jpg

Share this post


Link to post
Share on other sites



my auto it wont let me run it,

Share this post


Link to post
Share on other sites

@rus4hire - I noticed earlier that you said in another thread, you couldn't understand why your script was working on the screen shots and not the game itself, then I notice above your giving a .jpg as the example pic.

If you haven't guessed it already, you need to use a .bmp when doing this type of work, in order for the results to be the same for the game too. Hope that answers the other question if you hadn't already guessed it.


[center]Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer.[/center]

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

Thanks smoke. Ya it gets the same off screenshots as in the game. Warcraft III saves screenshots as .TGA

I've done quite a bit on this since I posted here.

Here's a nice GUI:

Posted Image

There 5 resolution modes named like they are in wc3

I figure these are the ones ppl use.

800x600x16

800x600x32

1024x768x16

1024x768x32

1280x1024x32

And now there's way to customize the codes that represent numbers in the ini.

So if a user ever has some wierd resolution that's not on here, he can just send me a few screenshots and I can make those key things for it so he can put that in his .ini instead of updating the source.

Or he may be able to figure it out himself and make his own according to what he finds in the debuglog.

And here's a nice example of the debuglog on the highest resolution warcraft III has, 1280x1024x32

This is only part of a game code. The characters are many pixels cause it's high resolution.

from Warcraft III
res=1280x1024x32
1280x1024
............11...
..1111....11111..
.111111..11...11.
.1....11.1.....11
......111.......1
1......11.......1
1......11.......1
1.......1.......1
.1.....111......1
.1......11......1
.111.11..11....1.
..1111...1111111.
..........11111..
.................
.................
.................
................1
..111111111111111
.1111111111111111
.................
...111111........
..11...111.......
.11......11.....1
.1.......11.....1
1.........1....1.
1.........1....1.
11............1..
.1...........11..
.11.........11...
..11......111....
...111111111.....
....11111........
.................
.................
...............1.
.1.............11
.1..............1
11.....1........1
11.....1........1
11.....1........1
11.....11......11
.11...1.1......1.
.11111..11....11.
..111....111111..
..........1111...
.................
.................
............1....
...........11....
.........1111....
.......11...1....
......11....1....
....11......1....
..11........1....
.1..........1....
.1.........111.11
.1111111111111111
............1...1
............1....
............1....
.................
.................
.................
..........1......
..........1......
..........1......
..........1......
..........1......
.................
.................

81934-

Here's 1024x768x32, what most people have.

............
........1...
......111...
.....1..1...
...1........
.1..........
........1...
.11111111111
........1...
........1...
............
............
............
.11111111111
............
............
............
.11111111111
...........1
............
.11111.....1
.1...1.....1
...........1
.....1.....1
.....1.....1
.....11...1.
......1111..
............
............
.....1111...
....11...11.
..1.......1.
...........1
.1.........1
...........1
.....1......
.....11...1.
.......11...
............

41156

Here's the kind of log it makes normally (not debuglog)

89356-99480-08492-31271-698,ioetyoorippiroweqwuqyoi 07/23/2006 02:36 saved in 143.544 ms from Warcraft III setting=1024x768x32 window=1024x768
21383-93609-16093-28698-704,wqeieoeypoqypoewiyoiupr 07/23/2006 02:51 saved in 157.066 ms from Warcraft III setting=1024x768x32 window=1024x768
12058-61507-21481-25722-711,qwptiyqtpuwqriqwtuwwuqq 07/23/2006 03:23 saved in 161.814 ms from Warcraft III setting=1024x768x32 window=1024x768

150 milliseconds average on 1024x768x32 resolution is not bad for an ocr method with Warcraft III running.

It's even faster on screenshots with nothing running. Like 75 ms.

It pinpoints the section where this color is and isolates it and begins running through the vertical lines of pixels till it identifies a character according to the keys. Which is usually the first or second line.

Then it skips ahead so many lines according to the character found so it doesn't scan pixels unnecessarily. It won't begin trying to identify a new character till it finds what is interpreted as a space after the skipped lines.

It does this till it begins getting nothing but spaces.

It works so great. Flawlessly.

I can use this method for any Warcraft III game that gives you a code where it's a pain to write it down and enter it in.

Cause those codes are huge, like cd-keys, cause the map maker doesn't want anyone to ever be able to figure it out to cheat.

And finally here's a link to the latest version, 1.09b.

http://www.rush4hire.com/files/ddcodes.exe

And the latest code.

;===============================================================================================
;  Save and enter codes from Warcraft 3 custom map Dark Deeds 6
;
;  Hotkeys are:
;  F5 to save
;  F6 to enter code
;
;  Notes:
;  If code is not entered when you attempt to retrieve, code is gotten from file.
;  Getting code from screen takes about 200 ms on my computer.
;  Will probably work on other Dark Deeds version, as long as the code is pink..
;
;  Author: rush4hire
;  Version: 1.09b
;================================================================================================
;TODO
;options to put stuff to clipboard.
; eleminate need to set resolution.

If WinExists("Dark Deeds Codes") Then Exit ; It's already running
;~ AutoItWinSetTitle($g_szVersion)

FileInstall ("gamma_setting.jpg", @scriptDir&"\")

Global $current_code
Global $current_number_code
Global $backupcode = 0
Global $sendkeys[10] = ["p","q","w","e","r","t","y","u","i","o"]
Opt("PixelCoordMode", 0)
;~ AutoItSetOption ( "option" [, param] )

Func initini()
If not fileExists ("ddcodes.ini") Then
    $text =""
    For $i = 0 to 11
        $text &= "numbers"& $i &"="& @crlf
    Next
    $text &= @crlf
    For $i = 0 to 10
        $text &= "cdspaces"& $i &"="& @crlf
    Next

FileWrite ( "ddcodes.ini", "[Main]"& @CRLF & _
"delay1=180"& @CRLF & _
"delay2=120"& @CRLF & _
"debuglog=0"& @CRLF & _
"numbersfromini=0"& @CRLF & _
"hotkey0=F5"& @CRLF & _
"hotkey1=F6"& @CRLF & _
"hotkey2=F7"& @CRLF & _
"resmode=1"& @CRLF & _
"colormode=1"& @CRLF & @CRLF & _
"[CustomNumbers]"& @CRLF & _
";Here you can customize codes that represent numbers."& @CRLF & _
";Read more about this in the readme."& @CRLF & _
"letterhight=12"& @CRLF & _
$text)
EndIf
EndFunc
initini()

;Stuff from ini
Global $set_delays[2]
$set_delays[0] = Number( IniRead ( "ddcodes.ini", "Main", "delay1", "180" ) )
$set_delays[1] = Number( IniRead ( "ddcodes.ini", "Main", "delay2", "120" ) )
Global $set_debuglog = Number( IniRead ( "ddcodes.ini", "Main", "debuglog", "0" ) )
Global $set_NumbersFromIni = Number( IniRead ( "ddcodes.ini", "Main", "numbersfromini", "0" ) )
Global $set_hotkeys[3]
$set_hotkeys[0] = IniRead ( "ddcodes.ini", "Main", "hotkey0", "F5" )
$set_hotkeys[1] = IniRead ( "ddcodes.ini", "Main", "hotkey1", "F6" )
$set_hotkeys[2] = IniRead ( "ddcodes.ini", "Main", "hotkey2", "F7" )
Global $def_hotkeys[3] = [ "F5", "F6", "F7" ]
Global $hotfunc[3] = [ "HotKey_GetCode", "enterDDcode", "initManEnter" ]
Global $set_resmode = Number( IniRead ( "ddcodes.ini", "Main", "resmode", "1" ) )
Global $set_colormode = Number( IniRead ( "ddcodes.ini", "Main", "colormode", "1" ) )

Global $debug_file

; Available keys
Global $avakeys = StringSplit("F2,F3,F4,F5,F6,F7,F8,F9,F10,F11,F12", ",")

Global $numbers[12]
Global $cdspaces[11]
Global $letterhight

; GUI vars
Global $boxes[2]
Global $sliders[2]
Global $fakes[2]
$fakes[0] = int($set_delays[0]/5)
$fakes[1] = int($set_delays[1]/5)
Global $hkeyopts[3]
Global $radios[3]
Global $resopts
Global $coloropts

;~ 640x480x16
;~ 640x480x32
;~ 800x600x16
;~ 800x600x32
;~ 1024x768x16
;~ 1024x768x32
;~ 1152x864x16
;~ 1152x864x32
;~ 1280x960x16
;~ 1280x960x32
;~ 1280x1024x16
;~ 1280x1024x32

Global $resolution_strings[5]
$resolution_strings[0]="800x600"
$resolution_strings[1]="1024x768"
$resolution_strings[2]="1152x864"
$resolution_strings[3]="1280x960"
$resolution_strings[4]="1280x1024"
;1280x960 or 1152x864
Global $color_strings[2]
$color_strings[0]="x16"
$color_strings[1]="x32"

Global $letter_hights[5]
$letter_hights[0]=9
$letter_hights[1]=12
$letter_hights[2]=14
$letter_hights[3]=15
$letter_hights[4]=17


; 0-9, 10 is -, 11 is space
Func setResMode()
If $set_resmode == 0 Then
    If $set_colormode Then
        $numbers[0]="|..11111.."
        $numbers[1]="|.11111111"
        $numbers[2]="|1......11"
        $numbers[3]="|1.......1"
        $numbers[4]="|......1.."
        $numbers[5]="|11.1....1|1..1....1"
        $numbers[6]="|...11111.|...1111.."
        $numbers[7]="|1........"
        $numbers[8]="|.11..111."
        $numbers[9]="|.1111....|..111....|.111....."
        $numbers[10]="|.....1..."
        $numbers[11]="|.........|........1"
    Else
        ; x16
        $numbers[0]="|..11111.."
        $numbers[1]="|.11111111"
        $numbers[2]="|1......11"
        $numbers[3]="|1.......1"
        $numbers[4]="|......1.."
        $numbers[5]="|1..1....1"
        $numbers[6]="|...11111.|...1111.."
        $numbers[7]="|1........"
        $numbers[8]="|.11..111."
        $numbers[9]="|.1111....|..111....|.111....."
        $numbers[10]="|.....1..."
        $numbers[11]="|.........|........1"
    EndIf
    
    $cdspaces[0]=5
    $cdspaces[1]=0
    $cdspaces[2]=5
    $cdspaces[3]=4
    $cdspaces[4]=5
    $cdspaces[5]=4
    $cdspaces[6]=5
    $cdspaces[7]=4
    $cdspaces[8]=5
    $cdspaces[9]=5
    $cdspaces[10]=1

ElseIf $set_resmode == 1 then
    If $set_colormode Then
    $numbers[0]="|...111111..."
    $numbers[1]="|.1111111111.|.11111111111"
    $numbers[2]="|..........1.|..........11"
    $numbers[3]="|1..........1"
    $numbers[4]="|........1..."
    $numbers[5]="|.11111.....1"
    $numbers[6]="|.....1111..."
    $numbers[7]="|.........11.|.........111"
    $numbers[8]="|........11..|..1....111.."
    $numbers[9]="|...111......"
    $numbers[10]="|.......1...."
    $numbers[11]="|............|...........1"
    Else
    $numbers[0]="|...111111..."
    $numbers[1]="|.1111111111.|.11111111111"
    $numbers[2]="|..........1.|..........11"
    $numbers[3]="|1..........1"
    $numbers[4]="|........1..."
    $numbers[5]="|.11111.....1"
    $numbers[6]="|.....1111..."
    $numbers[7]="|.........11.|.........111"
    $numbers[8]="|........11..|..1....111.."
    $numbers[9]="|...111......"
    $numbers[10]="|.......1...."
    $numbers[11]="|............|...........1"
    EndIf
    $cdspaces[0]=8
    $cdspaces[1]=0
    $cdspaces[2]=6
    $cdspaces[3]=5
    $cdspaces[4]=8
    $cdspaces[5]=6
    $cdspaces[6]=7
    $cdspaces[7]=4
    $cdspaces[8]=7
    $cdspaces[9]=8
    $cdspaces[10]=2
ElseIf $set_resmode == 4 Then
    $numbers[0]="|.......1111......"
    $numbers[1]="|..111111111111111"
    $numbers[2]="|.1............111"
    $numbers[3]="|...............1."
    $numbers[4]="|............1...."
    $numbers[5]="|.1111111........1|.1111111.......11"
    $numbers[6]="|......11111111..."
    $numbers[7]="|.1..............."
    $numbers[8]="|............11..."
    $numbers[9]="|...111111........"
    $numbers[10]="|..........1......"
    $numbers[11]="|.................|................1|.........11......"

    $cdspaces[0]=12
    $cdspaces[1]=1
    $cdspaces[2]=9
    $cdspaces[3]=10
    $cdspaces[4]=12
    $cdspaces[5]=9
    $cdspaces[6]=11
    $cdspaces[7]=9
    $cdspaces[8]=12
    $cdspaces[9]=11
    $cdspaces[10]=4

EndIf
$letterhight = $letter_hights[$set_resmode]

    ; number codes adjustable from ini
    If $set_NumbersFromIni Then
        $temp = IniRead ( "ddcodes.ini", "CustomNumbers", "letterhight", "" )
        If $temp == "" Then
            IniWrite ( "ddcodes.ini", "CustomNumbers", "letterhight", $letterhight )
        Else
            $letterhight = number($temp)
        EndIf
        For $i = 0 to 11
            $temp = IniRead ( "ddcodes.ini", "CustomNumbers", "numbers"&$i, "" )
            If $temp == "" Then
                IniWrite ( "ddcodes.ini", "CustomNumbers", "numbers"&$i, $numbers[$i] )
            Else
                $numbers[$i] = $temp
            EndIf
        Next
        For $i = 0 to 10
            $temp = IniRead ( "ddcodes.ini", "CustomNumbers", "cdspaces"&$i, "" )
            If $temp == "" Then
                IniWrite ( "ddcodes.ini", "CustomNumbers", "cdspaces"&$i, $cdspaces[$i] )
            Else
                $cdspaces[$i] = number($temp)
            EndIf
        Next
    EndIf

EndFunc
setResMode()

Func join($arr, $frog = " ", $start=0)
    $o=""
    For $i = $start to UBound($arr)-1
        $o &= $frog & $arr[$i]
    Next
    Return StringMid($o, StringLen($frog)+1)
EndFunc


Func inArray($arr, $e)
For $i = 0 to ubound($arr)
        If $arr[$i] == $e Then Return 1
Next
Return 0
EndFunc

Func inithkeys()
For $i = 0 to 2
        If not inArray($avakeys, $set_hotkeys[$i]) Then
                $set_hotkeys[$i] = $def_hotkeys[$i]
        EndIf
Next
EndFunc
inithkeys()

HotKeySet ( "{"& $set_hotkeys[0] &"}", $hotfunc[0] )
HotKeySet ( "{"& $set_hotkeys[1] &"}", $hotfunc[1] )
HotKeySet ( "{"& $set_hotkeys[2] &"}", $hotfunc[2] )


Func ddResponseSound($e)
        If $e Then
                SoundPlay(@WindowsDir & "\media\tada.wav")
        Else
                SoundPlay(@WindowsDir & "\media\chord.wav")
        EndIf
EndFunc


Func getLastCodeFromFile($e)
        $size = FileGetSize ("savedDDcodes.txt")
        If @error Then Return ""
        If $size = 0 Then Return ""
        $f = FileOpen ("savedDDcodes.txt", 0)
        $text = FileRead($f, $size)
        FileClose ($f)
        $arr = stringSplit($text, @CRLF, 1)
        If @error Then Return ""
        For $i = $arr[0] to 1 Step -1
                If StringLen($arr[$i]) > 0 Then
                        $x = stringSplit($arr[$i-$backupcode], " ")
                        If @error Then Return ""
                        $x = stringSplit($x[1], ",")
                        $current_number_code = $x[1]
                        Return $x[2]
                EndIf
        Next
        Return ""
EndFunc

Func enterDDcode()
        $len = StringLen($current_code)
        If $len < 18 Then
                $current_code = getLastCodeFromFile(0)
                $len = StringLen($current_code)
                If $len < 18 Then
                        ddResponseSound(0)
                        Return
                EndIf
        EndIf
        ddResponseSound(1)
        ClipPut($current_number_code)
        Local $ll
        Local $l
        send("{F1}")
        sleep($set_delays[0]*2)
        For $i = 1 to $len
                $l = StringMid($current_code,$i,1)
                sleep($set_delays[0])
                If $l = $ll Then sleep($set_delays[1])
                $ll = $l
                send($l)
        Next
        send("x")
EndFunc

Func HotKey_GetCode()
        ddResponseSound(getDDcode())
EndFunc


Func getDDcode()
; TEMP
;~ If fileExists("000") Then $letterhight = 18
; TEMP

$otext = ""
If WinActive ( "Warcraft III" ) Then
    $otext = " from Warcraft III"
    $arr = WinGetClientSize ("Warcraft III", "")
Else
    $otext = " from Screenshot"
;~  $tarr = WinList ()
;~  $cname = ""
;~  For $i = 1 to $tarr[0][0]
;~      $cname = $tarr[$i][0]
;~      If $cname <> "" Then
;~          If WinActive ( $cname ) Then ExitLoop
;~      EndIf
;~  Next
;~  If $cname = "" Then Return 0
;~  $arr = WinGetClientSize( $cname, "" )
    $arr = WinGetClientSize(""); huh
EndIf
$width = $arr[0]
$hight = $arr[1]

$begin = TimerInit()

If $set_debuglog Then
    $debug_file = FileOpen("ddcodes_debuglog.txt", 1)
  FileWriteLine ( $debug_file, @crlf & StringTrimLeft($otext,1) & @crlf &"res="& $resolution_strings[$set_resmode] & $color_strings[$set_colormode] & @crlf & $width &"x"& $hight)
EndIf

$widthstart1 = round($width * .1, 0)
$widthstart2 = round($width * .2, 0)
$widthend = round($width * .6, 0)
$hightend = round($width * .75, 0)
$codelength = round($width * .3, 0)
        ;find about where the pink text is.
$xvar = PixelSearch ( $widthstart1, 30, $widthend, $hightend, 0xF720F7, 40 )
If @error Then Return 0
    
        ; There may be some pink text comming first that's too far over to the left.
        ; so start search again below that text.
While $xvar[0] < $widthstart2
    $xvar = PixelSearch ( $widthstart1, $xvar[1]+$letterhight+(round($letterhight/3)+1), $widthend, $hightend, 0xF720F7, 40 )
    If @error Then Return 0
WEnd


; narrow stuff down
;~ While 1
;~      $arr = PixelSearch ( $xstart, $ystart, $maxx, $ystart, 0xF720F7, 40)
;~      If not @error Then ExitLoop
;~      $ystart+=1
;~      $maxy+=1
;~ WEnd
;~     FileWriteLine($file, "2 loops" )
$xstart = $xvar[0] - 10

$ystart= $xvar[1]; - 10
$maxx = $xstart + $codelength
$maxy = $ystart + $letterhight - 1

While 1
        $arr = PixelSearch ( $xstart, $ystart, $xstart, $maxy, 0xF720F7, 40)
        If Not @error Then ExitLoop
        $xstart+=1
WEnd


Dim $temp[$letterhight]
For $i = 0 to Ubound($temp)-1
    $temp[$i]="."
Next
Dim $cd = 0; count lines till done with a letter
Dim $cs = 0; count spaces
Dim $IsDone = 0
Dim $savestr1 = ""
Dim $savestr2 = ""
Dim $lastnum = 0
;~ FileWriteLine("debuglog.txt", @HOUR & ":" & @MIN)

For $i = $xstart to $maxx
    $start = $ystart
        $x = $temp
    While 1
        ;PixelSearch ( left, top, right, bottom, color [, shade-variation] [, step]] )
        $arr = PixelSearch ( $i, $start, $i, $maxy, 0xF720F7, 20)
        If @error Then ExitLoop
        $x[$arr[1]-$ystart] = 1
        $start = $arr[1]+1
        If $start = $maxy Then ExitLoop
        WEnd
    $t = getnumber($x)
        If $cd > 0 Then
            $cd -= 1
            ContinueLoop
        EndIf
        If $t==11 Then $cs +=1
        If $cs > 6 Then ExitLoop; bunch of spaces = we're done
        If $IsDone Then
                ;lookin for a blank colum to start a new letter.
                If $t == 11 Then;or ( $lastnum == 1 And $t == 12 ) Then
                        $IsDone = 0
                EndIf       
    ElseIf $t > -1 and $t < 11 Then
                $IsDone = 1
                If $t == 10 Then
                        $savestr1 &= "-"
                Else
                        $savestr1 &= $t
                        $savestr2 &= $sendkeys[$t]
                EndIf
                $lastnum = $t
            If $set_debuglog Then
                    $cd = $cdspaces[$t]
                Else
                    $i += $cdspaces[$t]
                EndIf
                $cs=0
        EndIf
    Next
$current_code = $savestr2
ClipPut($savestr1)
$current_number_code = $savestr1
FileWriteLine("savedDDcodes.txt", $savestr1 &","& $savestr2 &" "& @MON & "/" & @MDAY & "/" & @YEAR & " " & @HOUR & ":" & @MIN &" saved in "& TimerDiff($begin) &" ms"& $otext &" setting="& $resolution_strings[$set_resmode] & $color_strings[$set_colormode] &" window="& $width &"x"& $hight )
If $set_debuglog Then FileClose($debug_file)
GUICtrlSetState ( $radios[0], 1 )
$backupcode = 0
Return 1

EndFunc


Func getnumber($arr)
        Local $x = "|"
        For $i = 0 to $letterhight-1
                $x &= $arr[$i]
        Next
    If $set_debuglog Then FileWriteLine($debug_file, $x )
        For $i = 11 to 0 Step -1
            If StringInStr($numbers[$i], $x, 1) Then Return $i
;~              If $x == $numbers[$i] Then Return $i
        Next
        Return -1
EndFunc


Func saveChanges()
        IniWrite ( "ddcodes.ini", "Main", "delay1", $set_delays[0] )
        IniWrite ( "ddcodes.ini", "Main", "delay2", $set_delays[1] )
        IniWrite ( "ddcodes.ini", "Main", "debuglog", $set_debuglog )
        IniWrite ( "ddcodes.ini", "Main", "numbersfromini", $set_NumbersFromIni )
        IniWrite ( "ddcodes.ini", "Main", "hotkey0", $set_hotkeys[0] )
        IniWrite ( "ddcodes.ini", "Main", "hotkey1", $set_hotkeys[1] )
        IniWrite ( "ddcodes.ini", "Main", "hotkey2", $set_hotkeys[2] )
        IniWrite ( "ddcodes.ini", "Main", "resmode", $set_resmode )
        IniWrite ( "ddcodes.ini", "Main", "colormode", $set_colormode )
EndFunc


; keep sliders and input boxes in sinc
Func checkSliders($e)
$x = GUICtrlRead ( $sliders[$e] )
If $fakes[$e] <> $x Then
    $fakes[$e] = $x
        $set_delays[$e] = $fakes[$e]*5
    GUICtrlSetData ( $boxes[$e], $set_delays[$e] )
        Return 1
Else
        Return 0
EndIf
EndFunc


Func checkBoxes($e)
$x = Number ( GUICtrlRead ( $boxes[$e] ) )
If $x > 0 and $x < 601 Then
        $set_delays[$e] = $x
        $fakes[$e] = int($x/5)
        GUICtrlSetData ( $sliders[$e], $fakes[$e] )
Else
        GUICtrlSetData ( $boxes[$e], $set_delays[$e] )
EndIf
EndFunc


Func ResetHotkeys($e)
$x = GUICtrlRead ( $hkeyopts[$e] )
local $t
local $u
If $e == 0 Then
        $t = 1
        $u = 2
ElseIf $e == 1 Then
        $t = 0
        $u = 2
Else
        $t = 0
        $u = 1
EndIf
If $x = $set_hotkeys[$t] or $x = $set_hotkeys[$u] Then
        GUICtrlSetData ( $hkeyopts[$e], $set_hotkeys[$e] )
        Return
EndIf
HotKeySet ( "{"& $set_hotkeys[$e] &"}" )
HotKeySet ( "{"& $x &"}", $hotfunc[$e] )
$set_hotkeys[$e] = $x
EndFunc


Global $code_string

Func initManEnter()
    $code_string = ""
HotKeySet("{NUMPADENTER}","ManEnterKey")
HotKeySet("{ENTER}","ManEnterKey")
HotKeySet("{BS}","ManEnterKey")
HotKeySet("-","ManEnterKey")
HotKeySet("{NUMPADSUB}","ManEnterKey")
For $i = 0 to 9
    HotKeySet(String($i), "ManEnterKey")
    HotKeySet("{NUMPAD"&$i&"}", "ManEnterKey")
Next
SoundPlay(@WindowsDir & "\media\ding.wav")
EndFunc

Func ManEnterKey()
$x = @HotKeyPressed
HotKeySet($x)
Send($x)
HotKeySet($x, "ManEnterKey")
If $x == "{NUMPADENTER}" or $x == "{ENTER}" Then
    HotKeySet("{NUMPADENTER}")
    HotKeySet("{ENTER}")
    HotKeySet("{BS}")
    HotKeySet("-")
    HotKeySet("{NUMPADSUB}")
    For $i = 0 to 9
        HotKeySet(String($i))
        HotKeySet("{NUMPAD"&$i&"}")
    Next
    ddResponseSound(manEnterCode( $code_string ))
Else
    If StringLen($x) == 1 Then
    ElseIf $x == "{BS}" Then
        If $code_string == "" Then
            SoundPlay(@WindowsDir & "\media\chord.wav")
            Return
        Else
            $code_string = StringLeft($code_string, StringLen($code_string)-1)
            $x = ""
        EndIf
    ElseIf $x == "{NUMPADSUB}" Then
        $x = "-"
    Else
        $x = StringMid($x,8,1)
    EndIf
    $code_string &= $x
    Beep(350, 8)
;   SoundPlay(@WindowsDir & "\media\start.wav")
EndIf
    
EndFunc


Func manEnterCode($code)
    $begin = TimerInit()
    $len = StringLen($code)
    If $len < 19 Then return 0
    $temp = ""
    For $i = 1 to $len
        $l = StringMid($code,$i,1)
        If $l = "0" Then
            $temp &= $sendkeys[0]
        ElseIf $l = "-" Then
        Else
            $x = number($l)
            If $x = 0 Then Return 0
            $temp &= $sendkeys[$x]
        EndIf
    Next
    $current_code = $temp
  $current_number_code = $code
    ClipPut($code)
  FileWriteLine("savedDDcodes.txt", $code &","& $temp &" "& @MDAY & "/" & @MON & "/" & @YEAR & " " & @HOUR & ":" & @MIN &" saved manualy from GUI in "& TimerDiff($begin) &" ms")
    GUICtrlSetState ( $radios[0], 1 )
    $backupcode = 0
    Return 1
EndFunc

Func fixResMode()
    $text = GUICtrlRead ( $resopts )
    $no = StringInStr ( $text, "x", 1, 2 ) -1
    $res = StringLeft($text, $no)
    If StringRight($text, 1) == "2" Then
        $set_colormode = 1
    Else
        $set_colormode = 0
    EndIf

For $i = 0 to Ubound($resolution_strings)-1
    If $resolution_strings[$i] == $res Then
        $set_resmode = $i
        ExitLoop
    EndIf
Next

    setResMode()
EndFunc
;~ $resolution_strings[0]="800x600"
;~ $resolution_strings[1]="1024x768"
;~ $resolution_strings[2]="1152x864"
;~ $resolution_strings[3]="1280x960"
;~ $resolution_strings[4]="1280x1024"
;~ ;1280x960 or 1152x864
;~ Global $color_strings[2]
;~ $color_strings[0]="x16"
;~ $color_strings[1]="x32"

; Events and messages from guiconstants.au3
Global Const $GUI_EVENT_CLOSE           = -3
Global Const $GUI_EVENT_MINIMIZE        = -4
Global Const $GUI_EVENT_RESTORE         = -5
Global Const $GUI_EVENT_MAXIMIZE        = -6
Global Const $GUI_EVENT_PRIMARYDOWN     = -7
Global Const $GUI_EVENT_PRIMARYUP       = -8
Global Const $GUI_EVENT_SECONDARYDOWN   = -9
Global Const $GUI_EVENT_SECONDARYUP     = -10
Global Const $GUI_EVENT_MOUSEMOVE       = -11
Global Const $GUI_EVENT_RESIZED         = -12
Global Const $GUI_EVENT_DROPPED         = -13

$GUItext = "Dark Deeds Codes."& @CRLF& _
"Version 1.09b"&@CRLF& _
"Author: rush4hire"&@CRLF& _
"Latest Version Found at: http://www.rush4hire.com/files/ddcodes.exe"&@CRLF& _
"Last updated: July 24, 2006"&@CRLF& _
""&@CRLF& _
"This is a utility to save and enter your codes from the Warcraft III custom map"&@CRLF& _
"Dark Deeds 6."&@CRLF& _
""&@CRLF& _
"[Instructions]"&@CRLF& _
""&@CRLF& _
"To save your code:"&@CRLF& _
"Press "& $set_hotkeys[0] &" when your code is given at the end of the game,"&@CRLF& _
"  or when you have a valid screenshot open preferably in full screen mode."&@CRLF& _
""&@CRLF& _
"To enter your last saved code:"&@CRLF& _
"Press "& $set_hotkeys[1] &" at the beginning of the game."&@CRLF& _
""&@CRLF& _
"You can also manually enter a code in this window"&@CRLF& _
"or from the game screen by hitting "& $set_hotkeys[2] &" and typing in the code there."&@CRLF& _
"Codes are saved in savedDDcodes.txt in this folder."&@CRLF& _
""&@CRLF& _
"[Other stuff]"&@CRLF& _
"To change delays between punching in the keys:"&@CRLF& _
"Use these controls here."&@CRLF& _
"These are in milliseconds. So 250 milliseconds is 1/4 of a second."&@CRLF& _
""&@CRLF& _
"You can use debug mode to find out what is being saved from screen."&@CRLF& _
"Text is logged in ddcodes_debuglog.txt"&@CRLF& _
"This is useful if your code is not being saved properly."&@CRLF& _
"In this case post the results at rush4hire.com/forums/?topic=111"&@CRLF& _
""&@CRLF& _
"If none of these resolution modes work for you, check the NumbersFromIni box and"&@CRLF& _
"Set those under [CustomNumbers] according to what you find in ddcodes_debuglog.txt"&@CRLF& _
"The ""numbers1=....1.11.."" lines are the unique thing that identifies the digits comming"&@CRLF& _
"  at the start of each section from the screen."&@CRLF& _
"The ""cdspaces0=5"" part are the number of lines to skip after the digit has been identified."&@CRLF& _
""&@CRLF& _
"But the resolution modes should work, if your resolution matches the mode selected here."&@CRLF& _
"These are the ones most people use."&@CRLF& _
"I don't think Gamma matters, but I've included gamma_setting.jpg in case it does."&@CRLF& _
""&@CRLF& _
"[Changelog]"&@CRLF& _
"July 24, 2006 - 1.09b"&@CRLF& _
" - started making this changelog.  I'll try to fix it to include everything.. I guess.."&@CRLF& _
" - added folder to files to open"&@CRLF& _
""&@CRLF& _
""

If not FileExists ( "ddcodes_readme.txt" ) Then FileWrite ( "ddcodes_readme.txt", $GUItext )
;~ $GUI_DOCKAUTO 1 resize and reposition according to new window size 
;~ $GUI_DOCKLEFT 2 Left side 
;~ $GUI_DOCKRIGHT 4 Right side 
;~ $GUI_DOCKHCENTER 8 Position will not move relative to horizontal center 
;~ $GUI_DOCKTOP 32 Top side 
;~ $GUI_DOCKBOTTOM 64 Bottom side 
;~ $GUI_DOCKVCENTER 128 Position will not move relative to vertical center 
;~ $GUI_DOCKWIDTH 256 Width will not change 
;~ $GUI_DOCKHEIGHT 512 Height will not change 
;~ $GUI_DOCKSIZE 768 Size will not change (256+512) 
;~ $GUI_DOCKMENUBAR 544 512+32 so the control will stay on the top of window with no changing Height 
;~ $GUI_DOCKSTATEBAR 576 512+64 so the control stay at the bottom of the window with no changing Height 
;~ $GUI_DOCKALL 802 2+32+256+512 so the control will not move during resizing 
;~ $GUI_DOCKBORDERS 102 2+4+32+64 so the control will grow as the window 
Opt("GUIResizeMode", 802)

$gui = GUICreate ( "Dark Deeds Codes", 440, 495, -1, -1, 0x00040000 + 0x00010000 + 0x00020000 )
$GUIbox1 = GUICtrlCreateEdit($GUItext, 8, 8, 425, 220 )
GUICtrlSetResizing (-1, 512)
GUICtrlCreateLabel ( "Delay between keystrokes.", 5, 235 )
GUICtrlCreateLabel ( "Hotkey to save code.", 290, 235 )

$sliders[0] = GUICtrlCreateSlider(5, 250, 200, 20)
GUICtrlSetLimit(-1, 120, 0)
GUICtrlSetData(-1, $fakes[0])

$boxes[0] = GUICtrlCreateInput($set_delays[0], 210, 250, 40)

$hkeyopts[0] = GUICtrlCreateCombo ("F2", 290, 250, 45)
GUICtrlSetData ( -1, "F3|F4|F5|F6|F7|F8|F9|F10|F11|F12", $set_hotkeys[0] ) ; add other item snd set a new default

;----
GUICtrlCreateLabel ( "Extra delay when numbers are the same.", 5, 275 )
GUICtrlCreateLabel ( "Hotkey to load code.", 290, 275 )
GUICtrlCreateLabel ( "Hotkey to manually save code.", 290, 315 )
GUICtrlSetTip(-1,"Where you manually type in code from the game screen.")

$sliders[1] = GUICtrlCreateSlider(5, 290, 200, 20)
GUICtrlSetLimit(-1, 120, 0)
GUICtrlSetData(-1, $fakes[1])

$boxes[1] = GUICtrlCreateInput($set_delays[1], 210, 290, 40)
;GUICtrlCreateInput ( "text", left, top [, width [, height [, style [, exStyle]]]] )

$hkeyopts[1] = GUICtrlCreateCombo ("F2", 290, 290, 45)
GUICtrlSetData ( -1, "F3|F4|F5|F6|F7|F8|F9|F10|F11|F12", $set_hotkeys[1] )

$hkeyopts[2] = GUICtrlCreateCombo ("F2", 290, 330, 45)
GUICtrlSetData ( -1, "F3|F4|F5|F6|F7|F8|F9|F10|F11|F12", $set_hotkeys[2] )


$debug_box = GUICtrlCreateCheckbox ( "Debug Log Mode", 7, 322 )
GUICtrlSetTip(-1,"Puts what you get off the screen in ddcodes_debuglog.txt. And it's a bit slower")
GUICtrlSetState ( -1, $set_debuglog )

$NumbersFromIni_box = GUICtrlCreateCheckbox ( "NumbersFromIni", 7, 342 )
GUICtrlSetTip(-1,"Only use this if none of these resolution modes work and you know what you're doing!")
GUICtrlSetState ( -1, $set_NumbersFromIni )

GUICtrlCreateGroup ("Use old code?", 120, 322, 157, 43)
$radios[0] = GUICtrlCreateRadio ("Current", 130, 338)
$radios[1] = GUICtrlCreateRadio ("Old", 185, 338)
$radios[2] = GUICtrlCreateRadio ("Older", 225, 338)
GUICtrlCreateGroup ("",-99,-99,1,1)  ;close group
GUICtrlSetState ( $radios[0], 1 )

GUICtrlCreateGroup ("Resolution mode.", 297, 362, 116, 50)
$resopts = GUICtrlCreateCombo ( "800x600x16", 312, 380, 90)
GUICtrlSetData ( -1, "800x600x32|1024x768x16|1024x768x32|1280x1024x32", $resolution_strings[$set_resmode] & $color_strings[$set_colormode] )
GUICtrlCreateGroup ("",-99,-99,1,1)  ;close group

$saveini_button = GUICtrlCreateButton ( " Save to ini ", 315, 430 )
GUICtrlSetTip(-1,"Save to ini."& @LF &"Changes will apply to current session without this.")
$exit = GUICtrlCreateButton ( " Exit ", 385, 430 )

GUICtrlCreateLabel ( "Manually enter a code.", 8, 370 )
GUICtrlSetTip(-1,"This will be saved as soon as you hit Enter or exit from this field.")
$manEnterCode = GUICtrlCreateInput("", 8, 388, 200)
GUICtrlSetTip(-1,"This will be saved as soon as you hit Enter or exit from this field.")

GUICtrlCreateLabel ( "Show files.", 8, 415 )
$showfiles = GUICtrlCreateCombo ("ddcodes_readme.txt", 8, 430, 120)
GUICtrlSetData ( -1, "gamma_setting.jpg|ddcodes.ini|savedDDcodes.txt|ddcodes_debuglog.txt|folder" )

GUISetState()
Global $okbut = 9999
Global $picgui = 9999

Func showfiles($file)
    switch $file
        Case "gamma_setting.jpg"
            If not WinExists ("Gamma Setting") Then
                $picgui = GUICreate("Gamma Setting", 520, 240,-1,-1,-1,-1,$gui)
                GUICtrlCreatePic ( "gamma_setting.jpg", 8, 8, 506, 189 )
                $okbut = GUICtrlCreateButton ("  Ok  ", 250, 210)
                GUISetState()
            EndIf
        Case "folder"
            Run(@comspec & ' /c start ' & @ScriptDir &'\', '', @SW_HIDE)
        Case Else
            If $file == "ddcodes_readme.txt" Then
                GUICtrlSetData ( $GUIbox1, $GUItext)
            Else
                GUICtrlSetData ( $GUIbox1, FileRead($file, FileGetSize ( $file )) )
            EndIf
            If WinExists ( $file ) Then
                WinActivate ( $file )
            Else
                Run(@comspec & ' /c start ' & @ScriptDir &'\'& $file, '', @SW_HIDE)
            EndIf
;~          Run(@comspec & ' /c start ' & $file, '', @SW_HIDE)
;~          Run('"' & @SystemDir & '\Notepad.exe" "' & @ScriptDir &'\'& $file & '"')
;~          Run(@comspec & ' /c start ' & $file)
    EndSwitch
EndFunc


While 1
        $msg = GUIGetMsg()
        Switch $msg
        Case $GUI_EVENT_PRIMARYDOWN, $GUI_EVENT_PRIMARYUP, $GUI_EVENT_SECONDARYDOWN, $GUI_EVENT_SECONDARYUP, $GUI_EVENT_MOUSEMOVE
        Case $GUI_EVENT_CLOSE
                GUISetState ( @SW_MINIMIZE )
        Case $debug_box
                If GUICtrlRead ($debug_box) = 1 Then
                   $set_debuglog = 1
              Else
                     $set_debuglog = 0
            EndIf
        Case $NumbersFromIni_box
                If GUICtrlRead ($NumbersFromIni_box) = 1 Then
                   $set_NumbersFromIni = 1
              Else
                     $set_NumbersFromIni = 0
                EndIf
                 setResMode()
        Case $boxes[0]
                checkBoxes(0)
        Case $boxes[1]
                checkBoxes(1)
        Case $hkeyopts[0]
                ResetHotkeys(0)
        Case $hkeyopts[1]
                ResetHotkeys(1)
        Case $hkeyopts[2]
                ResetHotkeys(2)
        Case $radios[0]
                $backupcode=0
                $current_code = ""
        Case $radios[1]
                $backupcode=1
                $current_code = ""
        Case $radios[2]
                $backupcode=2
                $current_code = ""
        Case $resopts
                fixResMode()
        Case $manEnterCode
                ddResponseSound(manEnterCode(GUICtrlRead ( $manEnterCode )))
      Case $saveini_button
                saveChanges()
      Case $exit
                ExitLoop
        Case $showfiles
            showfiles(GUICtrlRead($showfiles))
        Case $okbut
            GUIDelete($picgui)
        Case Else
                If not checkSliders(0) Then
                        checkSliders(1)
                EndIf
        EndSwitch
WEnd
Edited by rush4hire

Share this post


Link to post
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
Sign in to follow this  
Followers 0