Jump to content

All Activity

This stream auto-updates

  1. Past hour
  2. Today
  3. Assembly. I usually use FASM but you can use whatever flavor you like. 8B 74 24 04 mov esi, [esp+4] ; ESI = pointer to the data struct 8B 4C 24 08 mov ecx, [esp+8] ; ECX = number of items in the struct 8B 54 24 0C mov edx, [esp+12] ; EDX = value to be deleted :next AD lodsd ; Load dword at address DS:ESI into EAX. ESI is incremented by 4. 39 D0 cmp eax, edx ; Compare data loaded in EAX with the value that you intend to delete 75 07 jne skip ; If is different then skip the overwrite operation (with default value) C7 46 FC FF FF FF FF mov DWORD PTR [esi-4], 0xffffffff ; Otherwise overwrite previously compared data with default value :skip E2 F2 loop next ; Loop the process until every item in the struct is verified C2 0C 00 ret 12 ; Return from function This is possible but it won't break the original functionality, since you tried to dinamically obtain a new minimum (and distinct) value that was not allocated yet? Global $tData = DllStructCreate('int Data[20]') FillStruct($tData) DllStructSetData($tData, 'Data', 22, 6) DllStructSetData($tData, 'Data', 23, 9) DllStructSetData($tData, 'Data', 25, 11) DllStructSetData($tData, 'Data', 25, 17) ConsoleWrite("Items containing the value 25: " & CountValue($tData, 25) & @CRLF) ConsoleWrite("Empty items: " & CountValue($tData, -1) & @CRLF) Func FillStruct($tStruct) Local $Code = Binary('0x8B7424048B4C2408C706FFFFFFFF83C604E2F5C20800') Local $iSize = BinaryLen($Code) Local $tCode = DllStructCreate('byte Code[' & $iSize & ']') DllStructSetData($tCode, 'Code', $Code) Local $aCall = DllCallAddress('int', DllStructGetPtr($tCode), 'ptr', DllStructGetPtr($tStruct), 'int', DllStructGetSize($tStruct) / 4) EndFunc Func CountValue($tStruct, $iValue) Local $Code = Binary('0x8B7424048B4C24088B54240C31DBAD39D0750143E2F889D8C20C00') Local $iSize = BinaryLen($Code) Local $tCode = DllStructCreate('byte Code[' & $iSize & ']') DllStructSetData($tCode, 'Code', $Code) Local $aCall = DllCallAddress('int', DllStructGetPtr($tCode), 'ptr', DllStructGetPtr($tStruct), 'int', DllStructGetSize($tStruct) / 4, 'int', $iValue) Return $aCall[0] EndFunc And here is the ASM code and the corresponding binary data from my Real Time Assembler.
  4. Yes, that's it exactly thanks. One more another thing...I tried to figure it out myself, but I don't understand how this is working...particularly how the Binary $Code is created in the first place, where does that string come from. Or what to search for exactly to figure this out. Anyway, can you give me a search function to search for how many of a particular value are in the structure (I've expanded the use of this)? And also tell me what exactly I can read up on, or what to search for, to try and learn about this and coming up binary strings necessary to do things I want? Thanks
  5. I could verify your restore parameters (and syntax etc.) @Nine and could test it successfully on Chrome, Firefox and MSEdge. I also created (a few minutes ago) an GitHub Issue and PR for this topic that can be reviewed by @Danp2 when he have the time for it. I believe _WD_Window($sSession, 'restore') should be more intuitive or for some even more familiar like in other frameworks like Selenium or WebdriverIO. Let's see what will happen 😇 . ----------------- @MWIProd I guess this thread can be closed, right? Best regards Sven
  6. Salutations @teodoric666. Here how I would do it : #include <File.au3> Local $sDate = @MDAY & "-" & @MON Local $sSource = "C:\Users\" & @UserName & "\AppData\" Local $sBackupPath = "D:\" & $sDate & '\Backup\' Local $aList = _FileListToArrayRec($sSource, "*||LocalLow", $FLTAR_FILES, $FLTAR_RECUR, $FLTAR_NOSORT, $FLTAR_RELPATH) ProgressOn("Backup " & $sDate, "0% completed") Local $nProgress, $nPrec For $i = 1 To $aList[0] FileCopy($sSource & $aList[$i], $sBackupPath & $aList[$i], $FC_OVERWRITE + $FC_CREATEPATH) $nProgress = Int($i / $aList[0] * 100) If $nProgress = $nPrec Then ContinueLoop ProgressSet($nProgress, $nProgress & "% completed") $nPrec = $nProgress Next ProgressSet(100, "Backup completed") Sleep(2000) ProgressOff()
  7. Hello Sven, I was a little busy, sorry if I have not contacted you before, I did not try a thing unfortunately, I will try in these days if time will allow it, thx very much
  8. I made an exe to save the AppData directory it works quite well I would like to add a progress bar but I am unable to, I don't have the level can anyone help me if not is not too complicated for you of course Thanks a lot #include <FileConstants.au3> #include <File.au3> #include <Date.au3> $date = @MDAY & "-" & @MON Local $AppDataPath = @AppDataDir Local $LocalAppDataPath = @LocalAppDataDir Local $BackupPath = "D:\" & $date & '.\Backup' Local $Search = FileFindFirstFile($AppDataPath & "\*.*") FileClose($Search) ; Copie récursive des fichiers et dossiers Func CopyFolder($SourcePath, $DestPath) Local $Search = FileFindFirstFile($SourcePath & "\*.*") If $Search = -1 Then Return Local $CopiedFiles = 0 While 1 Local $File = FileFindNextFile($Search) If @error Then ExitLoop If Not @extended Then ; Fichier trouvé, copie vers le répertoire de sauvegarde FileCopy($SourcePath & "\" & $File, $DestPath & "\" & $File, $FC_OVERWRITE) $CopiedFiles += 1 ElseIf StringInStr(FileGetAttrib($SourcePath & "\" & $File), "D") Then ; Dossier trouvé, récursion If $File <> "." And $File <> ".." Then DirCreate($DestPath & "\" & $File) CopyFolder($SourcePath & "\" & $File, $DestPath & "\" & $File) EndIf EndIf WEnd FileClose($Search) EndFunc ; Début de la copie des répertoires AppData, Local et Roaming CopyFolder($AppDataPath, $BackupPath &"\AppData\Roaming") CopyFolder($LocalAppDataPath, $BackupPath &"\AppData\Local") ; Affichage du message à la fin de la copie MsgBox(64, "Copie terminée", "La sauvegarde des répertoires Roaming , Local est terminée.")
  9. Another way less hacky maybe : #include <GUIConstantsEx.au3> #include <Misc.au3> If Not _Singleton("MyGui", 1) Then Exit WinSetState("gui V1.1.1", "", @SW_SHOW) + WinSetState("gui V1.1.1", "", @SW_RESTORE) $gui = GUICreate("gui V1.1.1", 445, 262, -1, -1, -1, -1) $button = GUICtrlCreateButton("Button", 60, 20, 100, 30, -1, -1) $bHide = GUICtrlCreateButton("Hide", 60, 60, 100, 30, -1, -1) $label = GUICtrlCreateLabel("My Text", 80, 100, 50, 15, -1, -1) $label2 = GUICtrlCreateLabel("My Text", 80, 130, 50, 15, -1, -1) GUISetState(@SW_SHOWMINIMIZED) WinSetState($gui, "", @SW_HIDE) $counter = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit Case $button $counter += 1 GUICtrlSetData($label, $counter) Case $bHide WinSetState($gui, "", @SW_HIDE) EndSwitch WEnd Yes, it made me laugh too...
  10. #include <GUIConstantsEx.au3> #include <Misc.au3> If WinExists("[TITLE:gui V1.1.1; CLASS:AutoIt v3 GUI]") Then WinActivate("[TITLE:gui V1.1.1; CLASS:AutoIt v3 GUI]") Send("+^h") Exit EndIf $beHide = False HotKeySet("+^h", "GuiHider") $gui = GUICreate("gui V1.1.1", 445, 262, -1, -1, -1, -1) $button = GUICtrlCreateButton("Button", 60, 20, 100, 30, -1, -1) $bHide = GUICtrlCreateButton("Hide", 60, 60, 100, 30, -1, -1) $label = GUICtrlCreateLabel("My Text", 80, 100, 50, 15, -1, -1) GUISetState(@SW_HIDE) $counter = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete() ; this should be here too Exit Case $button $counter += 1 GUICtrlSetData($label, $counter) Case $bHide GuiHider() EndSwitch WEnd Func GuiHider() ConsoleWrite("$beHide=" & $beHide & @CRLF) If $beHide = True Then GUISetState(@SW_HIDE) $beHide = False Else GUISetState(@SW_SHOW) $beHide = True EndIf EndFunc ;==>GuiHider
  11. Yes, I came up with this idea earlier. Look a few posts above It seems that there is no other way to do it. But thank you for your help
  12. #include <GUIConstantsEx.au3> #include <Misc.au3> If Not _Singleton("MyGui", 1) Then WinSetState("gui V1.1.1", "", @SW_SHOW) WinActivate("gui V1.1.1") ; easier to see when you "click click" the script Exit 5 EndIf Global $gui = GUICreate("gui V1.1.1",445,262,-1,-1,-1,-1) Global $button = GUICtrlCreateButton("Button",60,20,100,30,-1,-1) Global $bHide = GUICtrlCreateButton("Hide",60,60,100,30,-1,-1) Global $label = GUICtrlCreateLabel("My Text",80,100,50,15,-1,-1) WinSetTrans($gui, "", 0) ; fake not there GUISetState(@SW_SHOW) ; display the GUI WinSetState($gui, "", @SW_HIDE) ; hide WinSetTrans($gui, "", 255) ; restore tranparency back to solid $counter = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete() ; this should be here too Exit case $button $counter +=1 guictrlsetdata($label, $counter) case $bHide ConsoleWrite('case $bHide' & @CRLF) WinSetState($gui, "", @SW_HIDE) EndSwitch WEnd .. is a bit hacky but, if that does what you describe, then you are good. The GUIGetMsg() not working is either a bug or a caveat of win32.
  13. Hi Argumentum No, I didn't forget to add GUISetState() By design, the script is not supposed to show the window on startup. The window is supposed to show only after starting again the exe. The application will be started automatically at Windows startup and will be hidden. The application is an address book. The application is to have an option to be invoked (show main window) in three ways: 1. keyboard shortcut 3. clicking on the systray icon 4. running a shortcut on the desktop Yes, at first I thought that Nine's solution would be ok but unfortunately not in the case when we do not want to show the window at the start of the script.
  14. All, sorry for the long delay, work took over. The script is: #include <WinAPIShellEx.au3> Local $PhotosPath = @UserProfileDir & "\Pictures\iCloud Photos\Photos\" Local $PhotosPathBackup = @UserProfileDir & "\Pictures\iCloudPhotosBackUp\" If not FileExists($PhotosPathBackup) Then DirCreate($PhotosPathBackup) ShellExecute($PhotosPath) Sleep(500) If @UserName = "Raziel" Then Send("^e") Else Send("^a") EndIf Sleep(500) Send("{LSHIFT}+{F10}") Sleep(200) Send("{DOWN 14}") Sleep(100) Send("{ENTER}") Sleep(30000) ;one second just for testing change to (1000*60*30) for wait 30 minutes ;some bug here it seems to be always overwrite file ;~ _WinAPI_ShellFileOperation( $PhotosPath & "*.*", $PhotosPathBackup, $FO_COPY,BitOR( $FOF_NOCONFIRMMKDIR, $FOF_NOCONFIRMATION , $FOF_NOERRORUI, $FOF_NO_UI)) Local $hSearch = FileFindFirstFile($PhotosPath & "*.*") While 1 $sFileName = FileFindNextFile($hSearch) If @error Then ExitLoop If not FileExists($PhotosPathBackup & $sFileName) Then FileCopy($PhotosPath & $sFileName, $PhotosPathBackup) WEnd FileClose($hSearch) MsgBox(0,"Information","Process Finsihed" & @CRLF & "Script will be closed in 5 Seconds...",5) This works in principle, but - for whatever reason, not all photos are downloaded, and clicking the menu item "keep on computer" toggles the command, so every other time it un-sets what I want to achieve. But it's the closest I have. Thanks to @Danyfirex
  15. 'cause you forgot to add GUISetState() ; display the GUI No big deal #include <GUIConstantsEx.au3> #include <Misc.au3> If Not _Singleton("MyGui", 1) Then WinSetState("gui V1.1.1", "", @SW_SHOW) WinActivate("gui V1.1.1") ; easier to see when you "click click" the script Exit 5 EndIf $gui = GUICreate("gui V1.1.1",445,262,-1,-1,-1,-1) $button = GUICtrlCreateButton("Button",60,20,100,30,-1,-1) $bHide = GUICtrlCreateButton("Hide",60,60,100,30,-1,-1) $label = GUICtrlCreateLabel("My Text",80,100,50,15,-1,-1) GUISetState() ; display the GUI $counter = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE GUIDelete() ; this should be here too Exit case $button $counter +=1 guictrlsetdata($label, $counter) case $bHide WinSetState($gui, "", @SW_HIDE) EndSwitch WEnd Edit: ..read the whole post and still believe that this code should have no problem. Edit 2: I see that you marked yourself as solving the problem. Genieal ?
  16. Thank you for your reply. I'm just not sure we understand each other. Use the code below and see if the button works for you after you run the exe a second time. The conditions that must be met are that the window after the startup must be hidden. The window is to appear only after the second launch of the exe. #include <GUIConstantsEx.au3> #include <Misc.au3> If Not _Singleton("MyGui", 1) Then Exit WinSetState("gui V1.1.1", "", @SW_SHOW) $gui = GUICreate("gui V1.1.1",445,262,-1,-1,-1,-1) $button = GUICtrlCreateButton("Button",60,20,100,30,-1,-1) $bHide = GUICtrlCreateButton("Hide",60,60,100,30,-1,-1) $label = GUICtrlCreateLabel("My Text",80,100,50,15,-1,-1) $counter = 0 While 1 $nMsg = GUIGetMsg() Switch $nMsg Case $GUI_EVENT_CLOSE Exit case $button $counter +=1 guictrlsetdata($label, $counter) case $bHide WinSetState($gui, "", @SW_HIDE) EndSwitch WEnd
  17. EDIT : I've added a pause feature for the snake. You can now press the S key to put the game on hold and take a coffee break.
  18. I've come up with a simplified version of the code where I've addressed the issue of the snake's self-collision. Additionally, you have the freedom to choose the color of the snake. This showcases the versatility of the tool I'm using. #include-once #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; #INDEX# ======================================================================================================================= ; Title .........: Snake Game ; AutoIt Version : 3.3 ; AutoItObject Version : v1.2.8.2 ; Language ......: English ; Description ...: A simple Snake game implementation using AutoIt->AutoItObject.au3. ; Dependencies ..: AutoItObject.au3 ; Author ........: Numeric ; =============================================================================================================================== #include <GUIConstantsEx.au3> #include "AutoItObject.au3" #include <GDIPlus.au3> #include <Misc.au3> Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") _GDIPlus_Startup() _AutoItObject_Startup() Func Snake($iBgColor = 0xFF0000FF) Local $dx = Random(-1, 1, 1) Local $dy = Random(-1, 1, 1) Local $aMap[] MapAppend($aMap, Point(Random(10, 380, 1), Random(10, 380, 1))) ;food MapAppend($aMap, Point(Random(10, 380, 1), Random(10, 380, 1))) ; head Local $Board = GUICreate("Snake", 400, 400) GUISetState() Local $aBoardPos = WinGetClientSize($Board) Local $iBoardWidth = $aBoardPos[0] Local $iBoardHeight = $aBoardPos[1] Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($Board) Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iBoardWidth, $iBoardHeight, $hGraphics) Local $hGraphicsCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGraphicsCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) Local $hBrush = _GDIPlus_BrushCreateSolid($iBgColor) Local $hFoodBrush = _GDIPlus_BrushCreateSolid(0xFF00FF00) ;(0x00FF00) Local $aGDIMap[] $aGDIMap["hGraphics"] = $hGraphics $aGDIMap["hBitmap"] = $hBitmap $aGDIMap["hGraphicsCtxt"] = $hGraphicsCtxt $aGDIMap["hBrush"] = $hBrush $aGDIMap["hFoodBrush"] = $hFoodBrush Local $sClass = _AutoItObject_Class() With $sClass .Create() .AddProperty("dx", $ELSCOPE_PUBLIC, $dx) .AddProperty("dy", $ELSCOPE_PUBLIC, $dy) .AddProperty("speedLevel", $ELSCOPE_PUBLIC, 100) .AddProperty("foodCounter", $ELSCOPE_PUBLIC, 0) .AddProperty("Map", $ELSCOPE_PUBLIC, $aMap) .AddProperty("gdiMap", $ELSCOPE_PUBLIC, $aGDIMap) .AddProperty("Board", $ELSCOPE_PUBLIC, $Board) .AddProperty("iBoardWidth", $ELSCOPE_PUBLIC, $iBoardWidth) .AddProperty("iBoardHeight", $ELSCOPE_PUBLIC, $iBoardHeight) .AddMethod("move", "_move") .AddMethod("drawStage", "_drawStage") .AddMethod("resetGame", "_resetGame") .AddMethod("runGameLoop", "_runGameLoop") .AddMethod("cleanUpResources", "_cleanUpResources") .AddDestructor("_cleanUpResources") EndWith Return $sClass.Object EndFunc ;==>Snake Func _runGameLoop($this) While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop If _IsPressed(25) Then $this.dx = -1 $this.dy = 0 EndIf If _IsPressed(27) Then $this.dx = 1 $this.dy = 0 EndIf If _IsPressed(26) Then $this.dx = 0 $this.dy = -1 EndIf If _IsPressed(28) Then $this.dx = 0 $this.dy = 1 EndIf If _IsPressed(53) Then While 1 If _IsPressed(25) Or _IsPressed(26) Or _IsPressed(27) Or _IsPressed(28) Then ExitLoop Sleep(100) WEnd EndIf $this.drawStage() Sleep($this.speedLevel) WEnd EndFunc ;==>_runGameLoop Func _move($this) Local $aMap = $this.Map Local $head = $aMap[1] Local $newX = $head.getXPos() + $this.dx * 10 Local $newY = $head.getYPos() + $this.dy * 10 Local $hW = $newX + 10 Local $hH = $newY + 10 If $newX <= 0 Or $newX >= 390 Or $newY <= 0 Or $newY >= 390 Then MsgBox(64, "Game Over", "Collision! Game Over.") Local $iResponse = MsgBox(36, "Restart Game", "Do you want to restart the game?") If $iResponse = 6 Then $this.resetGame() Return True Else $this.cleanUpResources() _GDIPlus_Shutdown() _AutoItObject_Shutdown() Exit EndIf EndIf For $i = 2 To UBound($aMap) - 1 Local $cX = $aMap[$i].getXPos() Local $cY = $aMap[$i].getYPos() Local $cW = $cX + 10 Local $cH = $cY + 10 If $newX < $cW And $hW > $cX And $newY < $cH And $hH > $cY Then MsgBox(64, "Game Over", " SELF!!! Collision! Game Over.") $iResponse = MsgBox(36, "Restart Game", "Do you want to restart the game?") If $iResponse = 6 Then $this.resetGame() Return True Else $this.cleanUpResources() _GDIPlus_Shutdown() _AutoItObject_Shutdown() Exit EndIf EndIf Next Local $food = $aMap[0] Local $fX = $food.getXPos() Local $fY = $food.getYPos() Local $fW = $fX + 10 Local $fH = $fY + 10 If $newX < $fW And $hW > $fX And $newY < $fH And $hH > $fY Then ;generate food $aMap[0].setXPos(Random(10, 390, 1)) $aMap[0].setYPos(Random(10, 390, 1)) Local $lastSegment = $aMap[UBound($aMap) - 1] Local $lastX = $lastSegment.getXPos() + $this.dx() * 10 Local $lastY = $lastSegment.getYPos() + $this.dy() * 10 MapAppend($aMap, Point($lastX, $lastY)) $this.Map = $aMap $this.foodCounter += 1 If $this.foodCounter = 4 Then $this.speedLevel -= 20 If $this.speedLevel < 0 Then $this.speedLevel = 1 EndIf $this.foodCounter = 0 EndIf EndIf $head.setXPos($newX) $head.setYPos($newY) For $i = UBound($aMap) - 1 To 2 Step -1 $aMap[$i].setXPos($aMap[$i - 1].getXPos()) $aMap[$i].setYPos($aMap[$i - 1].getYPos()) Next EndFunc ;==>_move Func _drawStage($this) Local $gdiMap = $this.gdiMap Local $aMap = $this.Map Local $hGraphics = $gdiMap["hGraphics"] Local $hBrush = $gdiMap["hBrush"] Local $hFoodBrush = $gdiMap["hFoodBrush"] $this.move() _GDIPlus_GraphicsClear($hGraphics, 0xFF000000) _GDIPlus_GraphicsFillRect($hGraphics, $aMap[0].getXPos(), $aMap[0].getYPos(), 10, 10, $hFoodBrush) For $i = 1 To UBound($aMap) - 1 _GDIPlus_GraphicsFillRect($hGraphics, $aMap[$i].getXPos(), $aMap[$i].getYPos(), 10, 10, $hBrush) Next EndFunc ;==>_drawStage Func _resetGame($this) For $item In $this.Map $item = 0 Next $this.Map = 0 Local $aNewMap[] MapAppend($aNewMap, Point(Random(10, $this.iBoardWidth - 10), Random(10, $this.iBoardHeight - 10))) MapAppend($aNewMap, Point(Random(10, $this.iBoardWidth - 10), Random(10, $this.iBoardHeight - 10))) $this.Map = $aNewMap $this.dx = Random(-1, 1, 1) $this.dy = Random(-1, 1, 1) $this.speedLevel = 100 $this.foodCounter = 0 $this.drawStage() EndFunc ;==>_resetGame Func _cleanUpResources($this) Local $gdiMap = $this.gdiMap Local $hGraphics = $gdiMap["hGraphics"] Local $hBrush = $gdiMap["hBrush"] Local $hFoodBrush = $gdiMap["hFoodBrush"] _GDIPlus_GraphicsDispose($hGraphics) _GDIPlus_BrushDispose($hBrush) _GDIPlus_BrushDispose($hFoodBrush) _GDIPlus_Shutdown() For $gdih In $gdiMap $gdih = 0 Next $this.gdiMap = 0 For $oPoint In $this.Map $oPoint = 0 Next $this.Map = 0 _AutoItObject_Shutdown() EndFunc ;==>_cleanUpResources Func Point($X = 0, $Y = 0) Local $cPoint = _AutoItObject_Class() With $cPoint .Create() .AddProperty("X", $ELSCOPE_PRIVATE, $X) .AddProperty("Y", $ELSCOPE_PRIVATE, $Y) .AddMethod("setXPos", "_setXPos") .AddMethod("setYPos", "_setYPos") .AddMethod("getXPos", "_getXPos") .AddMethod("getYPos", "_getYPos") EndWith Return $cPoint.Object EndFunc ;==>Point Func _setXPos($this, $iX) $this.X = $iX EndFunc ;==>_setXPos Func _setYPos($this, $iY) $this.Y = $iY EndFunc ;==>_setYPos Func _getXPos($this) Return $this.X EndFunc ;==>_getXPos Func _getYPos($this) Return $this.Y EndFunc ;==>_getYPos Func _ErrFunc($oError) ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc ;***************************************************************************************************************************************** Global $sNake = Snake(0xFF8B4513) $sNake.runGameLoop() $sNake = 0 ;***************************************************************************************************************************************** _AutoItObject_Shutdown()
  19. Yesterday
  20. Congrats, it works way better. The double buffering fixed the flickers and border collisions works now but self collision still doesn't work. Look what snake I managed to create.
  21. Thank you very much, Andreik, for your constructive feedback. Indeed, the adoption of GDI+ has significantly improved the fluidity of the snake's movements in its eternal quest for food. This major change was accomplished in record time (including a 5-minute coffee break) thanks to the flexibility of the object-oriented paradigm offered by the AutoItObject.au3 UDF. With this tool, you can literally build an empire, brick by brick. Now, you have the freedom to adjust the snake's speed, change its color on the fly, even during gameplay, and even generate fake prey of different colors to try to trap "Kaa," Mowgli's old companion. In other words, you can unleash your imagination and push the boundaries of what's possible. #include-once #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 ; #INDEX# ======================================================================================================================= ; Title .........: Snake Game ; AutoIt Version : 3.3 ; AutoItObject Version : v1.2.8.2 ; Language ......: English ; Description ...: A simple Snake game implementation using AutoIt->AutoItObject.au3. ; Dependencies ..: AutoItObject.au3 ; Author ........: Numeric ; =============================================================================================================================== #include <GUIConstantsEx.au3> #include "AutoItObject.au3" #include <Misc.au3> #include <GDIPlus.au3> #include <GUIConstantsEx.au3> #include <WinAPIGdi.au3> Global $oErrorHandler = ObjEvent("AutoIt.Error", "_ErrFunc") _GDIPlus_Startup() _AutoItObject_Startup() Func Snake($oPoint = 0, $Board = Default, $iBgColor = 0xFF0000FF) Local $aRandomDirectionTab = [-1, 0, 1] Local $dx = $aRandomDirectionTab[Int(Random(0, 2, 1))] Local $dy = $aRandomDirectionTab[Int(Random(0, 2, 1))] Local $iLowSpeed = 100 Local $foodCounter = 0 If $Board = Default Then $Board = GUICreate("Snake", 400, 400) GUISetBkColor(0x303030) GUISetState() Local $aBoardPos = WinGetClientSize($Board) If @error Then Return SetError(1, 0, False) ; window not found Local $iBoardWidth = $aBoardPos[0] Local $iBoardHeight = $aBoardPos[1] Local $X = Random(10, $iBoardWidth - 10, 1) Local $Y = Random(10, $iBoardHeight - 10, 1) Local $aMap[] Local $oFood = Point(Random(10, $iBoardWidth - 10), Random(10, $iBoardHeight - 10)) MapAppend($aMap, $oFood) If $oPoint = 0 Then $oPoint = Point($X, $Y) MapAppend($aMap, $oPoint) Local $hGraphics = _GDIPlus_GraphicsCreateFromHWND($Board) Local $hBitmap = _GDIPlus_BitmapCreateFromGraphics($iBoardWidth, $iBoardHeight, $hGraphics) Local $hGraphicsCtxt = _GDIPlus_ImageGetGraphicsContext($hBitmap) _GDIPlus_GraphicsSetSmoothingMode($hGraphicsCtxt, $GDIP_SMOOTHINGMODE_HIGHQUALITY) Local $hBrush = _GDIPlus_BrushCreateSolid($iBgColor) Local $hFoodBrush = _GDIPlus_BrushCreateSolid(0xFF00FF00) ;(0x00FF00) Local $sClass = _AutoItObject_Class() With $sClass .Create() .AddProperty("hGraphics", $ELSCOPE_PRIVATE, $hGraphics) .AddProperty("hBitmap", $ELSCOPE_PRIVATE, $hBitmap) .AddProperty("hGraphicsCtxt", $ELSCOPE_PRIVATE, $hGraphicsCtxt) .AddProperty("hBrush", $ELSCOPE_PRIVATE, $hBrush) .AddProperty("iColor", $ELSCOPE_PRIVATE, 0xFF8080FF) .AddProperty("hFoodBrush", $ELSCOPE_PRIVATE, $hFoodBrush) .AddProperty("head", $ELSCOPE_PRIVATE, $oPoint) .AddProperty("aMap", $ELSCOPE_PRIVATE, $aMap) .AddProperty("food", $ELSCOPE_PRIVATE, $oFood) .AddProperty("foodCounter", $ELSCOPE_PRIVATE, $foodCounter) .AddProperty("dx", $ELSCOPE_PRIVATE, $dx) .AddProperty("dy", $ELSCOPE_PRIVATE, $dy) .AddProperty("Board", $ELSCOPE_PRIVATE, $Board) .AddProperty("speedLevel", $ELSCOPE_PRIVATE, $iLowSpeed) .AddProperty("iBoardWidth", $ELSCOPE_PRIVATE, $iBoardWidth) .AddProperty("iBoardHeight", $ELSCOPE_PRIVATE, $iBoardHeight) .AddMethod("getBoard", "_getBoard") .AddMethod("setSpeedLevel", "_setSpeedLevel") .AddMethod("getSpeedLevel", "_getSpeedLevel") .AddMethod("runGameLoop", "_runGameLoop") .AddMethod("getFoodBrush", "_getFoodBrush") .AddMethod("setdx", "_setdx") .AddMethod("setdy", "_setdy") .AddMethod("getdx", "_getdx") .AddMethod("getdy", "_getdy") .AddMethod("sleepW", "_sleepW") .AddMethod("getMap", "_getMap") .AddMethod("setMap", "_setMap") .AddMethod("getHead", "_getHead") .AddMethod("getBoardHeight", "_getBoardHeight") .AddMethod("getBoardWidth", "_getBoardWidth") .AddMethod("getFoodCounter", "_getFoodCounter") .AddMethod("setFoodCounter", "_setFoodCounter", True) .AddMethod("move", "_move", True) .AddMethod("generateFood", "_generateFood") .AddMethod("setFood", "_setFood") .AddMethod("getFood", "_getFood") .AddMethod("getSColor", "_getSColor") .AddMethod("setSColor", "_setSColor") .AddMethod("getGraphics", "_getGraphics") .AddMethod("getBitmap", "_getBitmap") .AddMethod("getGraphicsCtxt", "_getGraphicsCtxt") .AddMethod("getBrush", "_getBrush") .AddMethod("drawStage", "_drawStage") .AddMethod("checkBorderCollision", "_checkBorderCollision") .AddMethod("checkSelfCollision", "_checkSelfCollision") .AddMethod("checkFoodCollision", "_checkFoodCollision") .AddMethod("resetGame", "_resetGame") .AddMethod("cleanUpResources", "_cleanUpResources") .AddDestructor("_cleanUpResources") EndWith Return $sClass.Object EndFunc ;==>Snake Func _getFoodBrush($this) Return $this.hFoodBrush EndFunc ;==>_getFoodBrush Func _getGraphics($this) Return $this.hGraphics EndFunc ;==>_getGraphics Func _getBitmap($this) Return $this.hBitmap EndFunc ;==>_getBitmap Func _getGraphicsCtxt($this) Return $this.hGraphicsCtxt EndFunc ;==>_getGraphicsCtxt Func _getBrush($this) Return $this.hBrush EndFunc ;==>_getBrush Func _drawStage($this, $aPoints) Local $hGraphicsCtxt = $this.getGraphicsCtxt() $this.move() ; Effacer l'arrière-plan _GDIPlus_GraphicsClear($hGraphicsCtxt, 0xFF000000) ; Dessiner la nourriture Local $oFood = $this.getMap()[0] _GDIPlus_GraphicsFillRect($hGraphicsCtxt, $oFood.getXPos(), $oFood.getYPos(), $oFood.getWidth(), $oFood.getHeight(), $this.getFoodBrush()) ; Dessiner les segments du serpent For $i = 1 To UBound($aPoints) - 1 Local $oPoint = $aPoints[$i] _GDIPlus_GraphicsFillRect($hGraphicsCtxt, $oPoint.getXPos(), $oPoint.getYPos(), $oPoint.getWidth(), $oPoint.getHeight(), $this.getBrush()) Next ; Mettre à jour l'affichage _GDIPlus_GraphicsDrawImageRect($this.getGraphics(), $this.getBitmap(), 0, 0, $this.getBoardWidth(), $this.getBoardHeight()) EndFunc ;==>_drawStage Func _drawStage2($this, $aPoints) _GDIPlus_GraphicsClear($this.getGraphicsCtxt(), 0xFF000000) $this.move() Local $oFood = $this.getMap()[0] _GDIPlus_GraphicsFillRect($this.getGraphicsCtxt(), $oFood.getXPos(), $oFood.getYPos(), $oFood.getWidth(), $oFood.getHeight(), $this.getFoodBrush()) For $i = 1 To UBound($aPoints) - 1 Local $oPoint = $aPoints[$i] _GDIPlus_GraphicsFillRect($this.getGraphicsCtxt(), $oPoint.getXPos(), $oPoint.getYPos(), $oPoint.getWidth(), $oPoint.getHeight(), $this.getBrush()) Next _GDIPlus_GraphicsDrawImageRect($this.getGraphics(), $this.getBitmap(), 0, 0, $this.getBoardWidth(), $this.getBoardHeight()) EndFunc ;==>_drawStage2 Func _getFoodCounter($this) Return $this.foodCounter EndFunc ;==>_getFoodCounter Func _setFoodCounter($this, $foodCounter) $this.foodCounter = $foodCounter EndFunc ;==>_setFoodCounter Func _setSpeedLevel($this, $iLevel) $this.speedLevel = $iLevel EndFunc ;==>_setSpeedLevel Func _getSpeedLevel($this) Return $this.speedLevel EndFunc ;==>_getSpeedLevel Func _getBoard($this) Return $this.Board EndFunc ;==>_getBoard Func _runGameLoop($this) While 1 If GUIGetMsg() = $GUI_EVENT_CLOSE Then ExitLoop If _IsPressed(25) Then $this.setdx(-1) $this.setdy(0) EndIf If _IsPressed(27) Then $this.setdx(1) $this.setdy(0) EndIf If _IsPressed(26) Then $this.setdx(0) $this.setdy(-1) EndIf If _IsPressed(28) Then $this.setdx(0) $this.setdy(1) EndIf If _IsPressed(53) Then $this.sleepW() EndIf $this.drawStage($this.getMap()) Sleep($this.getSpeedLevel()) WEnd EndFunc ;==>_runGameLoop Func _getBoardWidth($this) Return $this.iBoardWidth EndFunc ;==>_getBoardWidth Func _getBoardHeight($this) Return $this.iBoardHeight EndFunc ;==>_getBoardHeight Func _generateFood($this) Local $aMap = $this.getMap() Local $oFood = $aMap[0] $oFood.setXPos(Random(10, $this.getBoardWidth() - 10)) $oFood.setXPos(Random(10, $this.getBoardHeight() - 10)) $this.setMap($aMap) EndFunc ;==>_generateFood Func _setFood($this, $oFood) $this.food = $oFood EndFunc ;==>_setFood Func _getFood($this) Return $this.food EndFunc ;==>_getFood Func _getHead($this) Return $this.head EndFunc ;==>_getHead Func _setdx($this, $dx) $this.dx = $dx EndFunc ;==>_setdx Func _setdy($this, $dy) $this.dy = $dy EndFunc ;==>_setdy Func _getdx($this) Return $this.dx EndFunc ;==>_getdx Func _getdy($this) Return $this.dy EndFunc ;==>_getdy Func _getMap($this) Return $this.aMap EndFunc ;==>_getMap Func _setMap($this, $aMap) $this.aMap = $aMap EndFunc ;==>_setMap Func _checkBorderCollision($this) Local $aMap = $this.getMap() Local $head = $aMap[1] Local $hX = $head.getXPos() + $this.getdx() * 10 Local $hY = $head.getYPos() + $this.getdy() * 10 If $hX <= 0 Or $hX >= $this.getBoardWidth() - 10 Or $hY <= 0 Or $hY >= $this.getBoardHeight() - 10 Then Return True EndIf Return False EndFunc ;==>_checkBorderCollision Func _checkSelfCollision($this) Local $aMap = $this.getMap() Local $head = $aMap[1] Local $hX = $head.getXPos() Local $hY = $head.getYPos() Local $hW = $hX + $this.getdx() * 10 Local $hH = $hY + $this.getdy() * 10 For $i = 2 To UBound($aMap) - 1 Local $segment = $aMap[$i] Local $segX = $segment.getXPos() Local $segY = $segment.getYPos() Local $segW = $segX + $segment.getWidth() Local $segH = $segY + $segment.getHeight() If $hX < $segW And $hW > $segX And $hY < $segH And $hH > $segY Then Return True EndIf Next Return False EndFunc ;==>_checkSelfCollision Func _checkFoodCollision($this) Local $aMap = $this.getMap() Local $head = $aMap[1] Local $hX = $head.getXPos() + $this.getdx() * 10 Local $hY = $head.getYPos() + $this.getdy() * 10 Local $hW = $hX + $head.getWidth() Local $hH = $hY + $head.getHeight() Local $food = $aMap[0] Local $fX = $food.getXPos() Local $fY = $food.getYPos() Local $fW = $fX + $food.getWidth() Local $fH = $fY + $food.getHeight() If $hX < $fW And $hW > $fX And $hY < $fH And $hH > $fY Then $this.generateFood() Local $lastSegment = $aMap[UBound($aMap) - 1] Local $lastX = $lastSegment.getXPos() + $this.getdx() * 10 Local $lastY = $lastSegment.getYPos() + $this.getdy() * 10 MapAppend($aMap, Point($lastX, $lastY)) $this.setMap($aMap) Return True EndIf Return False EndFunc ;==>_checkFoodCollision Func _resetGame($this) Local $aMap = $this.getMap() For $e In $aMap $e = 0 Next $aMap = 0 Local $aNewMap[] MapAppend($aNewMap, Point()) $this.setMap($aNewMap) $this.generateFood() MapAppend($aNewMap, Point(Random(10, $this.getBoardWidth() - 10), Random(10, $this.getBoardHeight() - 10))) $this.setMap($aNewMap) Local $aRandomDirectionTab = [-1, 0, 1] Local $dx = $aRandomDirectionTab[Int(Random(0, 2, 1))] Local $dy = $aRandomDirectionTab[Int(Random(0, 2, 1))] $this.setdx($dx) $this.setdy($dy) $this.setSpeedLevel(100) $this.setFoodCounter(0) $this.drawStage($aNewMap) EndFunc ;==>_resetGame Func _move($this) Local $aMap = $this.getMap() Local $head = $aMap[1] Local $newX = $head.getXPos() + $this.getdx() * 10 Local $newY = $head.getYPos() + $this.getdy() * 10 If $this.checkBorderCollision() Or $this.checkSelfCollision() Then MsgBox(64, "Game Over", "Collision! Game Over.") Local $iResponse = MsgBox(36, "Restart Game", "Do you want to restart the game?") If $iResponse = 6 Then _resetGame($this) Return True Else $this.cleanUpResources() _GDIPlus_Shutdown() _AutoItObject_Shutdown() Exit EndIf EndIf If $this.checkFoodCollision() Then $this.setFoodCounter($this.getFoodCounter() + 1) Local $lastSegment = $aMap[UBound($aMap) - 1] Local $lastX = $lastSegment.getXPos() + $this.getdx() * 10 Local $lastY = $lastSegment.getYPos() + $this.getdy() * 10 MapAppend($aMap, Point($lastX, $lastY)) If $this.getFoodCounter() = 4 Then Local $newSpeedLevel = $this.getSpeedLevel() - 20 If $newSpeedLevel < 0 Then $newSpeedLevel = 1 $this.setSpeedLevel($newSpeedLevel) $this.setFoodCounter(0) EndIf $this.generateFood() EndIf $head.setXPos($newX) $head.setYPos($newY) For $i = UBound($aMap) - 1 To 2 Step -1 $aMap[$i].setXPos($aMap[$i - 1].getXPos()) $aMap[$i].setYPos($aMap[$i - 1].getYPos()) Next $this.setMap($aMap) EndFunc ;==>_move ; #FUNCTION# ==================================================================================================================== ; Name ..........: _sleepW ; Description ...: Waits for keyboard input to change the direction of movement in the Snake game. ; Syntax ........: _sleepW(ByRef $this) ; Parameters ....: $this - [in/out] A reference to the Snake object. ; Return values .: None ; Modified ......: ; Remarks .......: This function is triggered when the player presses the 'S' key in the Snake game. It waits for directional input ; (arrow keys) to change the movement direction of the snake. The function updates the movement direction properties ; of the Snake object accordingly. Note: There seems to be a crashing issue with this function that needs further investigation. ; Related .......: Snake ; Link ..........: ; Example .......: No ; =============================================================================================================================== Func _sleepW($this) Do Do Sleep(100) Until _IsPressed(25) Or _IsPressed(26) Or _IsPressed(27) Or _IsPressed(28) If _IsPressed(25) Then $this.setdx(-1) $this.setdy(0) EndIf If _IsPressed(27) Then $this.setdx(1) $this.setdy(0) EndIf If _IsPressed(26) Then $this.setdx(0) $this.setdy(-1) EndIf If _IsPressed(28) Then $this.setdx(0) $this.setdy(1) EndIf Until _IsPressed(25) Or _IsPressed(26) Or _IsPressed(27) Or _IsPressed(28) EndFunc ;==>_sleepW ; #FUNCTION# ==================================================================================================================== ; Name ..........: _cleanUpResources ; Description ...: Cleans up all resources used in the Snake game. ; Syntax ........: _cleanUpResources() ; Parameters ....: None ; Return values .: None ; Remarks .......: This function deallocates all resources used in the Snake game, including graphics resources, objects, and variables. ; Related .......: Snake ; =============================================================================================================================== Func _cleanUpResources($this) ConsoleWrite("cleanUpRessources" & @CRLF) Local $aMap = $this.getMap() For $oPoint In $aMap $oPoint = 0 Next $aMap = 0 $this.setMap(0) ; Deallocate GDI+ resources _GDIPlus_GraphicsDispose($this.getGraphicsCtxt()) _GDIPlus_BrushDispose($this.getBrush()) _GDIPlus_BrushDispose($this.getFoodBrush()) _GDIPlus_BitmapDispose($this.getBitmap()) _GDIPlus_Shutdown() EndFunc ;==>_cleanUpResources ; #FUNCTION# ==================================================================================================================== ; Name ..........: Point ; Description ...: Creates a Point object used in the Snake game to represent coordinates. ; Syntax ........: Point([$X = 0[, $Y = 0]]) ; Parameters ....: $X - [optional] The X coordinate value. Default is 0. ; $Y - [optional] The Y coordinate value. Default is 0. ; Return values .: Returns a Point object with specified coordinates. ; Remarks .......: This function is used to create a Point object representing coordinates on the game board for the Snake game. ; It is used to manage positions of the snake segments and the food items. ; Related .......: Snake, _AutoItObject_Class ; =============================================================================================================================== Func Point($X = 0, $Y = 0) Local $cPoint = _AutoItObject_Class() Local Const $iWidth = 10 Local Const $iHeight = 10 With $cPoint .Create() .AddProperty("X", $ELSCOPE_PRIVATE, $X) .AddProperty("Y", $ELSCOPE_PRIVATE, $Y) .AddProperty("iWidth", $ELSCOPE_PRIVATE, $iWidth) .AddProperty("iHeight", $ELSCOPE_PRIVATE, $iHeight) .AddMethod("setXPos", "_setXPos") .AddMethod("setYPos", "_setYPos") .AddMethod("getXPos", "_getXPos") .AddMethod("getYPos", "_getYPos") .AddMethod("setWidth", "_setWidth", True) .AddMethod("setHeight", "_setHeight", True) .AddMethod("getWidth", "_getWidth") .AddMethod("getHeight", "_getHeight") .AddDestructor("_pointDestructor") EndWith Return $cPoint.Object EndFunc ;==>Point Func _setXPos($this, $iX) $this.X = $iX EndFunc ;==>_setXPos Func _setYPos($this, $iY) $this.Y = $iY EndFunc ;==>_setYPos Func _getXPos($this) Return $this.X EndFunc ;==>_getXPos Func _getYPos($this) Return $this.Y EndFunc ;==>_getYPos Func _getWidth($this) Return $this.iWidth EndFunc ;==>_getWidth Func _getHeight($this) Return $this.iHeight EndFunc ;==>_getHeight Func _setColor($this, $iClolor) $this.iColor = $iClolor EndFunc ;==>_setColor Func _getColor($this) Return $this.iColor EndFunc ;==>_getColor Func _ErrFunc($oError) ConsoleWrite(@ScriptName & " (" & $oError.scriptline & ") : ==> COM Error intercepted !" & @CRLF & _ @TAB & "err.number is: " & @TAB & @TAB & "0x" & Hex($oError.number) & @CRLF & _ @TAB & "err.windescription:" & @TAB & $oError.windescription & @CRLF & _ @TAB & "err.description is: " & @TAB & $oError.description & @CRLF & _ @TAB & "err.source is: " & @TAB & @TAB & $oError.source & @CRLF & _ @TAB & "err.helpfile is: " & @TAB & $oError.helpfile & @CRLF & _ @TAB & "err.helpcontext is: " & @TAB & $oError.helpcontext & @CRLF & _ @TAB & "err.lastdllerror is: " & @TAB & $oError.lastdllerror & @CRLF & _ @TAB & "err.scriptline is: " & @TAB & $oError.scriptline & @CRLF & _ @TAB & "err.retcode is: " & @TAB & "0x" & Hex($oError.retcode) & @CRLF & @CRLF) EndFunc ;==>_ErrFunc ;***************************************************************************************************************************************** Global $sNake = Snake() $sNake.runGameLoop() $sNake = 0 ;***************************************************************************************************************************************** _AutoItObject_Shutdown()
  22. It's the same problem, GUISetState won't work correctly with WinSetState. If you just remove the GUISetState(), it is like doing a GUISetState(@SW_HIDE). Then it will not work afterward. Use that instead : GUISetState() WinSetState($gui, "", @SW_HIDE)
  1. Load more activity
×
×
  • Create New...