#Region ;**** Directives created by AutoIt3Wrapper_GUI ****
#AutoIt3Wrapper_Icon=Kurven-Spiel.ico
#AutoIt3Wrapper_Outfile=Kurven-Spiel.exe
#AutoIt3Wrapper_Compression=4
#AutoIt3Wrapper_Res_Comment=Thanks to www.autoit.de
#AutoIt3Wrapper_Res_Description=Kurven-Spiel
#AutoIt3Wrapper_Res_Fileversion=1.4.4.0
#AutoIt3Wrapper_Res_LegalCopyright=funkey
#AutoIt3Wrapper_Res_Language=3079
#AutoIt3Wrapper_Res_Field=Author|funkey
#AutoIt3Wrapper_Res_Field=Author eMail|5tao (at) gmx.at
#AutoIt3Wrapper_Res_Field=Orginaldateiname|Kurven-Spiel.exe
#AutoIt3Wrapper_Res_Field=Produktname|Kurven-Spiel
#EndRegion ;**** Directives created by AutoIt3Wrapper_GUI ****

#include <StaticConstants.au3>
#include <WinAPI.au3>
#include <GUIConstantsEx.au3>
#include <GDIPlus.au3>
#include <WindowsConstants.au3>
#include <Misc.au3>
#include <ScreenCapture.au3>
#include <Array.au3>

#cs

Verbesserungen seit Version 1.4
	* Screensaver-Modus
	* Label (hoffentlich) immer sichtbar für alle Bildschirmauflösungen
	* Aero-Abschaltung auch für Windows7
	* Leicht besseres Design
	* Minimalen Abstand für die Anfangspunkte der Kurven hinzugefügt
	* Battle-Punktezählung für Single- und Multiplayer-Modus
	* Runde starten durch Drücken beider Maustasten
	* Geschwindigkeit der übrigen Kurven erhöht nach Ausfall (Singleplayer-Modus)

Soll für Version 2.0
	* Bildschirmschoner-Einstellungen Optionen Ende und Geschwindigkeit
	* Highscore-Modus
	* Optionen: Level (Geschwindigkeit), Geschwindigkeit nach Ausfall, Anzahl Runden
	* PC-Gegner Verhalten bzw. KI verbessern
	* Nach Game Over wieder ins Hauptmenü
	* Neuer Singleplayer-Modus mit Zeit und Highscore

Soll für Version 2.1 oder darüber
	* LAN-fähig
	* Sprachen: deutsch / englisch
#ce

Opt("GuiOnEventMode", 1)
Opt("TrayIconDebug", 1)
_GDIPlus_Startup()

Global $Titel = "Kurven-Spiel von funkey"
Global $Version = "1.4.4 Beta"
Global $IniFile = @ScriptDir & "\Kurven-Spiel.ini"
Global $Min_Player = IniRead($IniFile, "Screensaver", "RoundEnd", 2) ; Es müssen mind. x Player spielen (Default = 2, Testbetrieb = 1)
Global $Speed = 5, $Modus = 0, $SinglePlayerSel = 0, $Stop = 0, $HighScore = 0, $Runde = 1, $Max_Runden = 4, $Min_Distance = 100
Global $Rahmenbreite = 10, $Linienbreite = 7, $LinienLen = 7, $Randabstand = 100, $Labelbreite = 100, $Seitenabstand = $Labelbreite + ($Rahmenbreite * 1.5)
Global $Aktiv[6] = [0, 0, 0, 0, 0, 0], $Alive[6] = [0, 0, 0, 0, 0, 0], $Punkte[6] = [0, 0, 0, 0, 0, 0], $Sieg = 0
Global $Farbe[6] = ['FF0000', '00FF00', '0000FF', 'FFFF00', 'F47117', '34BCEE']
Global $hPen[6], $Winkel[6], $Pos[6][2]
Global $Winkelweite = 0.12 ;je größer, desto engere Kurven ;)
Global $Luecke = 3, $Luecken[6], $LueckenCounter = 0, $Max_Punkte
Global $dll = DllOpen("user32.dll")
Global $ScrnSvr = 0, $Battle = 0, $Possible, $iPlayer, $AccelDeath = 1
Global $Label_Punkte[6], $Label_Player[6], $Pause[6]
Global $Label_Text[6][3] = [["Player 1: 1+q", "Player 1: 1+q			Bereit", "Player 1: 1+q			PC-Gegner"], _
		["Player 2: Strg+Alt", "Player 2: Strg+Alt		Bereit", "Player 2: Strg+Alt		PC-Gegner"], _
		["Player 3: m+,", "Player 3: m+,			Bereit", "Player 3: m+,			PC-Gegner"], _
		["Player 4: links+unten", "Player 4: links+unten		Bereit", "Player 4: links+unten		PC-Gegner"], _
		["Player 5: Numpad " & Chr(247) & " + " & Chr(215), "Player 5: Numpad " & Chr(247) & " + " & Chr(215) & "		Bereit", "Player 5: Numpad " & Chr(247) & " + " & Chr(215) & "		PC-Gegner"], _
		["Player 6: Maus links + rechts", "Player 6: Maus links + rechts	Bereit", "Player 6: Maus links + rechts	PC-Gegner"]]
Global $aOptionen[4][4] =	[["Anzahl der Runden", "Mehr", "Weniger"], _
							["Kurven nach eigenem Ausfall beschleunigen", "Ja", "Nein"], _
							["Geschwindigkeits-Level", "Schneller", "Langsamer"], _
							["Gegner-KI", "Besser", "Schlechter"]]
Global $Taste[6][2] = [['31', '51'],['a2', '12'],['4d', 'bc'],['25', '28'],['6f', '6a'],['01', '02']]
Global $Settings[6][2] = [['Singleplayer-Standard'],['Singleplayer-Battle'],['Multiplayer-Standard'],['Multiplayer-Battle'],['Optionen'],['Ende']]
Local $HoverArray[1], $ControlID, $Global_I = 0, $__ControlID, $HoverActive = 0, $Temp_Found = 0, $szTemp_Array[2]
Local $hBrush, $hFormat, $hFamily, $hFont, $tLayout, $aInfo

#Region Aero
Global Const $hDwmApiDll = DllOpen("dwmapi.dll") ; Für Aero Aktivierung/Deaktivierung
If @OSBuild >= 5048 Then
	If _IsAeroEnable() = 0 Then _EnableDisableAero(False) ; Aero Deaktivierung
EndIf
#EndRegion

#Region Screensaver
Global $CommandLine
Global $VirtualDesktopWidth = DllCall("user32.dll", "int", "GetSystemMetrics", "int", 78);sm_virtualwidth
$VirtualDesktopWidth = $VirtualDesktopWidth[0]
Global $VirtualDesktopHeight = DllCall("user32.dll", "int", "GetSystemMetrics", "int", 79);sm_virtualheight
$VirtualDesktopHeight = $VirtualDesktopHeight[0]

If $CmdLine[0] > 0 Then
	$CommandLine = StringLeft($CmdLine[1], 2)
Else
	$CommandLine = ""
EndIf

If $CommandLine = "/s" Then
	$ScrnSvr = 1
	_StartScrnSvr()
ElseIf $CommandLine = "/c" Then
	Opt("GuiOnEventMode", 0)
	Local $msg, $SettingPos = WinGetPos("[Class:#32770]", "Bildschirmschoner")
	Local $hWndSetting = GUICreate("Einstellungen Kurven-Spiel", 350, 60, $SettingPos[0] + 24, $SettingPos[1] + 230);, -1, -1, HWnd($CmdLine[2])
	Local $Setting1 = GUICtrlCreateRadio("Bildschirmschoner neu starten, wenn vorletzte Kurve kollidiert", 10, 10, 350)
	Local $Setting2 = GUICtrlCreateRadio("Bildschirmschoner neu starten, wenn alle Kurven kollidiert", 10, 30, 350)
	If $Min_Player = 1 Then
		GUICtrlSetState($Setting2, $GUI_CHECKED)
	Else
		GUICtrlSetState($Setting1, $GUI_CHECKED)
	EndIf
	GUISetState()
	While 1
		$msg = GUIGetMsg()
		If $msg = $Setting1 Then
			$Min_Player = 2
			IniWrite($IniFile, "Screensaver", "RoundEnd", $Min_Player)
		ElseIf $msg = $Setting2 Then
			$Min_Player = 1
			IniWrite($IniFile, "Screensaver", "RoundEnd", $Min_Player)
		ElseIf $msg = -3 Then
			_GDIPlus_Shutdown()
			Exit
		EndIf
	WEnd
;~     MsgBox(64, $Titel, "Dieser Bildschirmschoner hat keine Einstellungen" & @CRLF & @CRLF & _
;~             "© funkey November 2009 ", 10)
;~ 	Opt("GuiOnEventMode", 1)
ElseIf $CommandLine = "/p" Then		;thx UEZ
    Local $USER32 = DllOpen("user32.dll")
	Local $hParent = HWnd($CmdLine[2])
    Local $x = 152
    Local $y = 112
    Local $hGuiPV = GUICreate($Titel, $x, $y, 0, 0, 0x80000000)
    GUISetBkColor(0x000000)
    $hWnd = WinGetHandle($hGuiPV)
	GUICtrlCreateLabel("Kurven-Spiel", 0, 0, $x, $y, 0x201)
	GUICtrlSetColor(-1, 0xFF0000)
	GUICtrlSetFont(-1, 15, 1000, 2, "Arial")
    DllCall($USER32, "int", "SetParent", "hwnd", $hGuiPV, "hwnd", $hParent) ;set preview window
    DllClose($USER32)
    GUISetState()
	Local $parent_PID = _ProcessGetParent(@AutoItPID)
	Local $child_PID
	WinActivate($hParent)
    While 1
        If Not WinExists($hWnd) Then _ExitPreview()
        $child_PID = _ProcessGetChildren($parent_PID)
        If $child_PID[0] > 1 Then _ExitPreview() ;if another screensaver is selected in ComboBox close ss
    WEnd
EndIf
#EndRegion

Global $hGUI = GUICreate($Titel, @DesktopWidth, @DesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
GUISetBkColor(0x0)
;~ GUISetOnEvent($GUI_EVENT_CLOSE, "_Exit")
Global $hPenRahmen = _GDIPlus_PenCreate(0xA0FFFFFF, $Rahmenbreite)

$Welcome = GUICtrlCreateLabel("Willkommen beim", $Rahmenbreite + $Seitenabstand, $Rahmenbreite + 20, @DesktopWidth - 2 * $Seitenabstand, 60, $SS_CENTER)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 40)

$hBrush = _GDIPlus_BrushCreateSolid(0x0FFF0000)
$hFormat = _GDIPlus_StringFormatCreate()
$hFamily = _GDIPlus_FontFamilyCreate("Arial")
$hFont = _GDIPlus_FontCreate($hFamily, 45, 2)
$tLayout = _GDIPlus_RectFCreate(@DesktopWidth/2 - 650 / 2, $Rahmenbreite + 80, 800, 70)
$aInfo = _GDIPlus_GraphicsMeasureString($hGraphic, $Titel, $hFont, $tLayout, $hFormat)

$Pause_Label = GUICtrlCreateLabel("Pause", @DesktopWidth - $Seitenabstand + $Rahmenbreite/2, $Rahmenbreite, $Seitenabstand - 1.5*$Rahmenbreite, 30, 0x201)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 20, 1000)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetCursor(-1, 0)
GUICtrlSetTip(-1, "Hier klicken oder Escape drücken um das Spiel zu beenden!"&@CRLF&@CRLF&"Drücken Sie Pause um mit dem Spiel wieder fortzufahren.")
GUICtrlSetOnEvent(-1, '_Exit')

$Status_Label = GUICtrlCreateLabel("Runde" & @CR & "1 / "&$Max_Runden&""&@CR&"0 %", @DesktopWidth - $Seitenabstand + $Rahmenbreite/2, $Rahmenbreite + 30, $Seitenabstand - 1.5*$Rahmenbreite, 80, $SS_CENTER)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetState(-1, $GUI_HIDE)
GUICtrlSetFont(-1, 15)

$Label_Auswahl = GUICtrlCreateLabel("Wählen Sie die Farbe für ihren Player aus"&@CRLF&"Dieser wird dann mit der Maus gesteuert", $Rahmenbreite + $Seitenabstand, $Rahmenbreite, @DesktopWidth - 2 * $Seitenabstand, 70, $SS_CENTER)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 22)
GUICtrlSetState(-1, $GUI_HIDE)

For $i = 0 To UBound($Settings, 1) - 1
	$Settings[$i][1] = GUICtrlCreateLabel($Settings[$i][0], $Rahmenbreite + 50, @DesktopHeight / 22 + (@DesktopHeight / 11 * ($i + 4)), 520, 50, $SS_CENTERIMAGE)
	GUICtrlSetColor(-1, '0xFFFFFF')
	GUICtrlSetFont(-1, 25)
	GUICtrlSetCursor(-1, 0)
	GUICtrlSetOnEvent(-1, '_Modus')
	_HoverAddCtrl($Settings[$i][1])
Next

For $i = 0 To 5
	$Label_Punkte[$i] = GUICtrlCreateLabel($Punkte[$i], @DesktopWidth - $Labelbreite - $Rahmenbreite, @DesktopHeight / 18 + (@DesktopHeight / 9 * $i + 100), $Labelbreite, @DesktopHeight / 9, 0x201)
	GUICtrlSetColor(-1, '0x' & $Farbe[$i])
	GUICtrlSetFont(-1, 40)
	GUICtrlSetState(-1, $GUI_HIDE)
	$Label_Player[$i] = GUICtrlCreateLabel($Label_Text[$i][0], $Rahmenbreite + 50, @DesktopHeight / 18 + (@DesktopHeight / 9 * $i + 100), @DesktopWidth, @DesktopHeight / 11, $SS_CENTERIMAGE)
	GUICtrlSetColor(-1, '0x' & $Farbe[$i])
	GUICtrlSetFont(-1, 25)
	GUICtrlSetCursor(-1, 0)
	GUICtrlSetState(-1, $GUI_HIDE)
	$hPen[$i] = _GDIPlus_PenCreate('0xFF' & $Farbe[$i], $Linienbreite)
	$Winkel[$i] = Random(170, 190) ;)
Next

GUISetState()
Sleep(100)
AdlibRegister("_ProcessHover", 50)

For $f = 1 To 40
	_GDIPlus_GraphicsDrawStringEx($hGraphic, $Titel, $hFont, $aInfo[0], $hFormat, $hBrush)
	Sleep(30)
Next
_GDIPlus_BrushDispose ($hBrush)
$hBrush = _GDIPlus_BrushCreateSolid(0xFFFF0000)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $Titel, $hFont, $aInfo[0], $hFormat, $hBrush)

$Ver = GUICtrlCreateLabel("Version " & $Version, $Rahmenbreite + $Seitenabstand, $Rahmenbreite + 150, @DesktopWidth - 2 * $Seitenabstand, 60, $SS_CENTER)
GUICtrlSetColor(-1, 0xFFFFFF)
GUICtrlSetFont(-1, 25)

HotKeySet('p', '_Screen_Capture')
HotKeySet('{Esc}', '_Exit')

Local $accel[18][2] = [["1"],["q"],["^"],["!"],["m"],[","],["^m"],["^,"],["^q"],["^1"],["!m"],["!,"],["!q"],["!1"], _
					   ["{LEFT}"],["{DOWN}"],["{NUMPADDIV}"],["{NUMPADMULT}"]]
GUISetAccelerators($accel)

Do
	Sleep(50)
Until $Modus > 0

AdlibUnRegister()

For $i = 0 To UBound($Settings, 1) - 1
	GUICtrlSetState($Settings[$i][1], $GUI_HIDE)
Next

GUICtrlSetState($Welcome, $GUI_HIDE)
GUICtrlSetState($Ver, $GUI_HIDE)

_GDIPlus_BrushDispose($hBrush)
$hBrush = _GDIPlus_BrushCreateSolid(0x0F000000)
For $f = 1 To 40
	_GDIPlus_GraphicsDrawStringEx($hGraphic, $Titel, $hFont, $aInfo[0], $hFormat, $hBrush)
	Sleep(10)
Next
_GDIPlus_BrushDispose ($hBrush)
$hBrush = _GDIPlus_BrushCreateSolid(0xFF000000)
_GDIPlus_GraphicsDrawStringEx($hGraphic, $Titel, $hFont, $aInfo[0], $hFormat, $hBrush)

_GDIPlus_FontDispose ($hFont)
_GDIPlus_FontFamilyDispose ($hFamily)
_GDIPlus_StringFormatDispose ($hFormat)
_GDIPlus_BrushDispose($hBrush)
Sleep(500)


Switch $Modus
	Case 1, 2
		GUICtrlSetState($Label_Auswahl, $GUI_SHOW)
		For $i = 0 To 5
			GUICtrlSetData($Label_Player[$i], 'Player ' & $i + 1)
			GUICtrlSetOnEvent($Label_Player[$i], '_SetSinglePlayer')
			_HoverAddCtrl($Label_Player[$i])
			GUICtrlSetState($Label_Player[$i], $GUI_SHOW)
			AdlibRegister("_ProcessHover", 50)
		Next
		Do
			Sleep(50)
		Until $SinglePlayerSel > 0
		GUICtrlSetState($Label_Auswahl, $GUI_HIDE)
		GUISetCursor(16, 1)
		AdlibUnRegister("_ProcessHover")
	Case 3,4
		GUISetCursor(16, 1)
		For $i = 0 To 5
			GUICtrlSetCursor($Label_Player[$i], 16)
			GUICtrlSetState($Label_Player[$i], $GUI_SHOW)
		Next
		Do
			For $i = 0 To 5
				If ($Aktiv[$i] = 0 Or $Aktiv[$i] = 1) And _IsPressed($Taste[$i][0], $dll) And Not $Pause[$i] Then _OnOff($i, 1)
				If $Aktiv[$i] > 0 And _IsPressed($Taste[$i][1], $dll) And Not $Pause[$i] Then _OnOff($i, 0)
				If Not _IsPressed($Taste[$i][0], $dll) And Not _IsPressed($Taste[$i][1], $dll) Then $Pause[$i] = 0
			Next
			Sleep(20)
		Until _IsPressed('20', $dll) And _ArraySum($Alive) >= $Min_Player ;mit Space weiter wenn mind. x Player bereit sind

		If _ArraySum($Alive) > 1 Then $Min_Player = 2
EndSwitch

For $i = 0 To 5
	GUICtrlSetState($Label_Player[$i], $GUI_HIDE)
Next

_DrawRahmen()
_Set_Pos()
_DrawStart()
_Luecken()

$Max_Punkte = _MaxPoints()
HotKeySet('{Pause}', '_Pause')
HotKeySet("{Esc}", "_Pause")
If $Modus = 1 Or $Modus = 2 Then GUICtrlSetState($Status_Label, $GUI_SHOW)
Sleep(1000)
AdlibRegister("_Zyklus", 35)

While 1
	Sleep(30000)
WEnd

Func _Zyklus()
	For $i = 0 To 5
		Switch $Aktiv[$i]
			Case 2
				If $Alive[$i] Then
					_Curve($i, _AutoScan($Pos[$i][0], $Pos[$i][1], $Winkel[$i]))
					If Not _DrawLine_Angle($Pos[$i][0], $Pos[$i][1], $Winkel[$i], $hPen[$i]) Then
						$Alive[$i] = 0
						If $Alive[$iPlayer] = 0 Then $Possible -= 1
						If $Battle = 0 Then
							For $j = 0 To 5
								If $j <> $i Then
									If $Alive[$j] And $Aktiv[$j] Then $Punkte[$j] += 1
								EndIf
							Next
						Else
							Local $CrashCol = @error, $Got = 0
							For $c = 0 To 5
								If $CrashCol = "0x" & $Farbe[$c] And $CrashCol <> "0x" & $Farbe[$i] Then
									$Punkte[$c] += 1
									$Got = 1
								EndIf
							Next
							If $Got = 0 And $Punkte[$i] > 0 Then $Punkte[$i] -= 1
						EndIf
						_UpDate_Points()
					EndIf
				EndIf
			Case 1
				If _IsPressed($Taste[$i][0], $dll) Then _Curve($i, 1)
				If _IsPressed($Taste[$i][1], $dll) Then _Curve($i, 2)
				If $Alive[$i] Then
					If Not _DrawLine_Angle($Pos[$i][0], $Pos[$i][1], $Winkel[$i], $hPen[$i]) Then
						$Alive[$i] = 0
						$Possible -= 1
						If ($Modus = 1 Or $Modus = 2) And $AccelDeath Then AdlibRegister("_Zyklus", 10)
						If $Battle = 0 Then
							For $j = 0 To 5
								If $j <> $i Then
									If $Alive[$j] And $Aktiv[$j] Then $Punkte[$j] += 1
								EndIf
							Next
						Else
							Local $CrashCol = @error, $Got = 0
							For $c = 0 To 5
								If $CrashCol = "0x" & $Farbe[$c] And $CrashCol <> "0x" & $Farbe[$i] Then
									$Punkte[$c] += 1
									$Got = 1
								EndIf
							Next
							If $Got = 0 And $Punkte[$i] > 0 Then $Punkte[$i] -= 1
						EndIf
						_UpDate_Points()
					EndIf
				EndIf
		EndSwitch
	Next
	$LueckenCounter += 1
	Switch $LueckenCounter
		Case $Luecken[0] + $Luecke
			_GDIPlus_PenSetColor($hPen[0], '0xFF' & $Farbe[0])
		Case $Luecken[1] + $Luecke
			_GDIPlus_PenSetColor($hPen[1], '0xFF' & $Farbe[1])
		Case $Luecken[2] + $Luecke
			_GDIPlus_PenSetColor($hPen[2], '0xFF' & $Farbe[2])
		Case $Luecken[3] + $Luecke
			_GDIPlus_PenSetColor($hPen[3], '0xFF' & $Farbe[3])
		Case $Luecken[4] + $Luecke
			_GDIPlus_PenSetColor($hPen[4], '0xFF' & $Farbe[4])
		Case $Luecken[5] + $Luecke
			_GDIPlus_PenSetColor($hPen[5], '0xFF' & $Farbe[5])
		Case $Luecken[0]
			_GDIPlus_PenSetColor($hPen[0], 0xFF000000)
		Case $Luecken[1]
			_GDIPlus_PenSetColor($hPen[1], 0xFF000000)
		Case $Luecken[2]
			_GDIPlus_PenSetColor($hPen[2], 0xFF000000)
		Case $Luecken[3]
			_GDIPlus_PenSetColor($hPen[3], 0xFF000000)
		Case $Luecken[4]
			_GDIPlus_PenSetColor($hPen[4], 0xFF000000)
		Case $Luecken[5]
			_GDIPlus_PenSetColor($hPen[5], 0xFF000000)
		Case 50
			$LueckenCounter = 0
			_Luecken()
	EndSwitch
	If _ArraySum($Alive) < $Min_Player Then
		If $ScrnSvr = 0 Then
			_Restart()
		Else
			_RestartSS()
		EndIf
	EndIf
EndFunc   ;==>_Zyklus

Func _Restart()
	HotKeySet('{Pause}')
	HotKeySet("{Esc}", "_Exit")
	AdlibUnRegister()
	For $i = 0 To 5
		If $Punkte[$i] >= $Max_Punkte Then $Sieg = 1	;Multiplayer - Bis der erste mind. 50 Punkte hat (6 Player)
	Next
	If ($Modus = 1 Or $Modus = 2) And $Runde = $Max_Runden Then $Sieg = 1		;Singleplayer und Battle - 10 Runden
	_Wait()
	If $Sieg Then
		_DrawRahmen()
		GUICtrlSetData($Welcome, 'Game Over')
		If $Modus = 1 Or $Modus = 2 Then GUICtrlSetData($Welcome, 'Game Over'&@CRLF&@CRLF&$HighScore&" %")
		GUICtrlSetState($Welcome, $GUI_SHOW)
		Sleep(1000)
		_Wait()
		_Exit()
	EndIf
	_DrawRahmen()
	_Set_Pos()
	$LueckenCounter = 0
	For $i = 0 To 5
		_GDIPlus_PenSetColor($hPen[$i], '0xFF' & $Farbe[$i])
		$Winkel[$i] = Random(170, 190) ;)
		If $Aktiv[$i] > 0 Then
			$Alive[$i] = 1
		Else
			$Alive[$i] = 0
		EndIf
	Next
	$Runde += 1
	_Highscore()
	_DrawStart()
	_Luecken()
	Sleep(1000)
	AdlibRegister("_Zyklus", 35)
	HotKeySet('{Pause}', '_Pause')
	HotKeySet("{Esc}", "_Pause")
EndFunc   ;==>_Restart

Func _RestartSS()
	AdlibUnRegister()
	Sleep(2000)
	_DrawRahmen()
	_Set_Pos()
	$LueckenCounter = 0
	For $i = 0 To 5
		_GDIPlus_PenSetColor($hPen[$i], '0xFF' & $Farbe[$i])
		$Winkel[$i] = Random(170, 190) ;)
		$Alive[$i] = 1
	Next
	_DrawSSStart()
	_Luecken()
	Sleep(1000)
	AdlibRegister("_Zyklus", 35)
EndFunc   ;==>_RestartSS

Func _Wait()
	HotKeySet('o', '_Minimize')
	Do
		Sleep(20)
	Until _IsPressed('20', $dll) Or (_IsPressed('01', $dll) And _IsPressed('02', $dll))
	HotKeySet('o')
EndFunc   ;==>_Wait

Func _Modus()
	Switch @GUI_CtrlId
		Case $Settings[0][1]
			$Modus = 1
		Case $Settings[1][1]
			$Modus = 2
			$Battle = 1
		Case $Settings[2][1]
			$Modus = 3
		Case $Settings[3][1]
			$Modus = 4
			$Battle = 1
		Case $Settings[4][1]
			For $i = 0 To UBound($Settings, 1) - 1
				GUICtrlSetState($Settings[$i][1], $GUI_HIDE)
			Next
			Sleep(2000)
			For $i = 0 To UBound($Settings, 1) - 1
				GUICtrlSetState($Settings[$i][1], $GUI_SHOW)
			Next
		Case $Settings[5][1]
			_Exit()
	EndSwitch
EndFunc   ;==>_Modus

Func _SetSinglePlayer()
	$SinglePlayerSel = 1
	For $i = 0 To 5
		$Aktiv[$i] = 2
		$Alive[$i] = 1
		If @GUI_CtrlId = $Label_Player[$i] Then
			GUICtrlSetBkColor($Label_Punkte[$i], '0x' & $Farbe[$i])
			GUICtrlSetColor($Label_Punkte[$i], 0x000000)
			$Taste[$i][0] = '01'
			$Taste[$i][1] = '02'
			$Aktiv[$i] = 1
			$iPlayer = $i
		EndIf
	Next
EndFunc   ;==>_SetSinglePlayer

Func _Highscore()
	If $Modus <> 1 And $Modus <> 2 Then Return 	;Keinen Highscore beim Multiplayer-Modus
	For $i = 0 To 5
		If $Aktiv[$i] = 1 Then ExitLoop
	Next
;~ 	$HighScore = StringFormat("%.0f / %.0f", ($Punkte[$iPlayer] / ($Max_Runden * 5)) * 100, $Possible / $Max_Punkte * 100)
	$HighScore = StringFormat("%.0f %%", $Punkte[$iPlayer] / $Max_Punkte * 100)
	GUICtrlSetData($Status_Label, "Runde"&@CR & $Runde&" / "&$Max_Runden&@CR&$HighScore)
EndFunc

Func _OnOff($Player, $Switch)
	If $Switch Then
		$Aktiv[$Player] += 1
		GUICtrlSetData($Label_Player[$i], $Label_Text[$Player][$Aktiv[$Player]])
	Else
		$Aktiv[$Player] -= 1
		GUICtrlSetData($Label_Player[$i], $Label_Text[$Player][$Aktiv[$Player]])
	EndIf
	$Pause[$Player] = 1
	If $Aktiv[$Player] > 0 Then
		$Alive[$Player] = 1
	Else
		$Alive[$Player] = 0
	EndIf
EndFunc   ;==>_OnOff

Func _Curve($Player, $Direction)
	Switch $Direction
		Case 1
			$Winkel[$Player] -= $Winkelweite
		Case 2
			$Winkel[$Player] += $Winkelweite
	EndSwitch
EndFunc   ;==>_Curve

Func _UpDate_Points()
	For $i = 0 To 5
		GUICtrlSetData($Label_Punkte[$i], $Punkte[$i])
	Next
	_Highscore()
EndFunc   ;==>_UpDate_Points

Func _Check_Crash($Pos)
	Local $Pixel_Match = 0, $aMatch[9], $Col = 0
	$aMatch[0] = PixelGetColor($Pos[0] - 1, $Pos[1] - 1)
	$aMatch[1] = PixelGetColor($Pos[0] - 1, $Pos[1])
	$aMatch[2] = PixelGetColor($Pos[0] - 1, $Pos[1] + 1)
	$aMatch[3] = PixelGetColor($Pos[0], $Pos[1] - 1)
	$aMatch[4] = PixelGetColor($Pos[0], $Pos[1])
	$aMatch[5] = PixelGetColor($Pos[0], $Pos[1] + 1)
	$aMatch[6] = PixelGetColor($Pos[0] + 1, $Pos[1] - 1)
	$aMatch[7] = PixelGetColor($Pos[0] + 1, $Pos[1])
	$aMatch[8] = PixelGetColor($Pos[0] + 1, $Pos[1] + 1)
	If $aMatch[0] <> '0x000000' Then $Col = $aMatch[0]
	If $aMatch[1] <> '0x000000' Then $Col = $aMatch[1]
	If $aMatch[2] <> '0x000000' Then $Col = $aMatch[2]
	If $aMatch[3] <> '0x000000' Then $Col = $aMatch[3]
	If $aMatch[4] <> '0x000000' Then $Col = $aMatch[4]
	If $aMatch[5] <> '0x000000' Then $Col = $aMatch[5]
	If $aMatch[6] <> '0x000000' Then $Col = $aMatch[6]
	If $aMatch[7] <> '0x000000' Then $Col = $aMatch[7]
	If $aMatch[8] <> '0x000000' Then $Col = $aMatch[8]
	If $Col <> 0 Then $Pixel_Match = 1
	Return SetError($Pixel_Match, 0, $Col)
EndFunc   ;==>_Check_Crash

Func _Luecken()
	For $i = 0 To 5
		$Luecken[$i] = Random(0, 45, 1)
	Next
EndFunc   ;==>_Luecken

Func _MaxPoints()
	Local $Summe = _ArraySum($Alive)
	$Summe = ($Summe - 1) * $Max_Runden
	If $Battle = 1 And $Modus = 4 Then $Summe /= 2		; Es sind nur die halben Punkte nötig um im Multiplayer-Battle-Modus zu gewinnen
	$Possible = $Summe
	Return $Summe
EndFunc   ;==>_MaxPoints

Func _DrawLine_Angle(ByRef $aPos_x, ByRef $aPos_y, $Angle, $hPen, $Len = $Speed)
	Local $Alive = 1, $Col
	Local $arrayPos[2]
	$arrayPos[0] = $Len * Cos($Angle) + $aPos_x
	$arrayPos[1] = $Len * Sin($Angle) + $aPos_y
	$Col = _Check_Crash($arrayPos)
	If @error Then $Alive = 0
	_GDIPlus_GraphicsDrawLine($hGraphic, $aPos_x, $aPos_y, $arrayPos[0], $arrayPos[1], $hPen)
	$aPos_x = $arrayPos[0]
	$aPos_y = $arrayPos[1]
	Return SetError($Col, 0, $Alive)
EndFunc   ;==>_DrawLine_Angle

Func _AutoScan($aPos_x, $aPos_y, $Angle, $Len = $Speed)
	Local $ScanFaktor = 40
	Local $ScanStreuung = 3
	Local $ScanIntensity = 3
	Local $Chance
	Local $arrayPos[2]
	Local $Pixel_Match_l = 0, $Pixel_Match_r = 0, $Pixel_Match_m = 0;, $Pixel_Match_ql = 0, $Pixel_Match_qr = 0
	For $i = 1 To $ScanFaktor
		$arrayPos[0] = $Len / $ScanIntensity * $i * Cos($Angle + $Winkelweite * $ScanStreuung) + $aPos_x
		$arrayPos[1] = $Len / $ScanIntensity * $i * Sin($Angle + $Winkelweite * $ScanStreuung) + $aPos_y
		If PixelGetColor($arrayPos[0], $arrayPos[1]) <> '0x000000' Then $Pixel_Match_l += ($ScanFaktor + 1 - $i)
		$arrayPos[0] = $Len / $ScanIntensity * $i * Cos($Angle - $Winkelweite * $ScanStreuung) + $aPos_x
		$arrayPos[1] = $Len / $ScanIntensity * $i * Sin($Angle - $Winkelweite * $ScanStreuung) + $aPos_y
		If PixelGetColor($arrayPos[0], $arrayPos[1]) <> '0x000000' Then $Pixel_Match_r += ($ScanFaktor + 1 - $i)
		$arrayPos[0] = $Len / ($ScanIntensity / 2) * $i * Cos($Angle) + $aPos_x
		$arrayPos[1] = $Len / ($ScanIntensity / 2) * $i * Sin($Angle) + $aPos_y
		If PixelGetColor($arrayPos[0], $arrayPos[1]) <> '0x000000' Then $Pixel_Match_m += ($ScanFaktor + 1 - $i)
	Next
	Select
		Case $Pixel_Match_m > $Pixel_Match_l And $Pixel_Match_l >= $Pixel_Match_r
			Return 1
		Case $Pixel_Match_m > $Pixel_Match_r And $Pixel_Match_r >= $Pixel_Match_l
			Return 2
		Case $Pixel_Match_l > 0 And $Pixel_Match_l > $Pixel_Match_r
			Return 1
		Case $Pixel_Match_r > 0 And $Pixel_Match_r > $Pixel_Match_l
			Return 2
		Case $Pixel_Match_l > 0
			Return 1
		Case $Pixel_Match_r > 0
			Return 2
		Case Else
			$Chance = Random(0, 2, 1)
			If $Chance > 0 Then $Chance = Random(0, 2, 1)
			Return $Chance
	EndSelect
EndFunc   ;==>_AutoScan

Func _AutoScanPro($aPos_x, $aPos_y, $Angle, $Len = $Speed)
	Local $ScanFaktor = 40
	Local $ScanStreuung = 3
	Local $ScanIntensity = 3
	Local $Chance
	Local $arrayPos[2]
	Local $Pixel_Match_l = 0, $Pixel_Match_r = 0, $Pixel_Match_m = 0, $Pixel_Match_wl = 0, $Pixel_Match_wr = 0
	For $i = 1 To $ScanFaktor
		$arrayPos[0] = $Len / $ScanIntensity * $i * Cos($Angle + $Winkelweite * $ScanStreuung) + $aPos_x
		$arrayPos[1] = $Len / $ScanIntensity * $i * Sin($Angle + $Winkelweite * $ScanStreuung) + $aPos_y
		If PixelGetColor($arrayPos[0], $arrayPos[1]) <> '0x000000' Then $Pixel_Match_l += ($ScanFaktor + 1 - $i)
		$arrayPos[0] = $Len / $ScanIntensity * $i * Cos($Angle - $Winkelweite * $ScanStreuung) + $aPos_x
		$arrayPos[1] = $Len / $ScanIntensity * $i * Sin($Angle - $Winkelweite * $ScanStreuung) + $aPos_y
		If PixelGetColor($arrayPos[0], $arrayPos[1]) <> '0x000000' Then $Pixel_Match_r += ($ScanFaktor + 1 - $i)
		$arrayPos[0] = $Len / ($ScanIntensity / 2) * $i * Cos($Angle) + $aPos_x
		$arrayPos[1] = $Len / ($ScanIntensity / 2) * $i * Sin($Angle) + $aPos_y
		If PixelGetColor($arrayPos[0], $arrayPos[1]) <> '0x000000' Then $Pixel_Match_m += ($ScanFaktor + 1 - $i)

		$arrayPos[0] = $Len / $ScanIntensity * $i * Cos($Angle + $Winkelweite * $ScanStreuung*3) + $aPos_x
		$arrayPos[1] = $Len / $ScanIntensity * $i * Sin($Angle + $Winkelweite * $ScanStreuung*3) + $aPos_y
		If PixelGetColor($arrayPos[0], $arrayPos[1]) <> '0x000000' Then $Pixel_Match_wl += ($ScanFaktor + 1 - $i)
		$arrayPos[0] = $Len / $ScanIntensity * $i * Cos($Angle - $Winkelweite * $ScanStreuung*3) + $aPos_x
		$arrayPos[1] = $Len / $ScanIntensity * $i * Sin($Angle - $Winkelweite * $ScanStreuung*3) + $aPos_y
		If PixelGetColor($arrayPos[0], $arrayPos[1]) <> '0x000000' Then $Pixel_Match_wr += ($ScanFaktor + 1 - $i)

	Next
	Select
		Case $Pixel_Match_m > $Pixel_Match_l And $Pixel_Match_l >= $Pixel_Match_r
			Return 1
		Case $Pixel_Match_m > $Pixel_Match_r And $Pixel_Match_r >= $Pixel_Match_l
			Return 2
		Case $Pixel_Match_wl > 0 And $Pixel_Match_wl > $Pixel_Match_wr And $Pixel_Match_wl > $Pixel_Match_r
			Return 1
		Case $Pixel_Match_wr > 0 And $Pixel_Match_wr > $Pixel_Match_wl And $Pixel_Match_wr > $Pixel_Match_l
			Return 2
		Case $Pixel_Match_wl > 0 And $Pixel_Match_wl > $Pixel_Match_r
			Return 1
		Case $Pixel_Match_wr > 0 And $Pixel_Match_wr > $Pixel_Match_l
			Return 2
		Case $Pixel_Match_l > 0 And $Pixel_Match_l > $Pixel_Match_r
			Return 1
		Case $Pixel_Match_r > 0 And $Pixel_Match_r > $Pixel_Match_l
			Return 2
		Case $Pixel_Match_l > 0
			Return 1
		Case $Pixel_Match_r > 0
			Return 2
		Case Else
;~ 			$Chance = Random(0, 2, 1)
;~ 			If $Chance > 0 Then $Chance = Random(0, 2, 1)
;~ 			Return $Chance
			Return -1
	EndSelect
EndFunc   ;==>_AutoScanPro

Func _Set_Pos()
	Local $Width = @DesktopWidth, $Height = @DesktopHeight
	If $ScrnSvr Then
		$Width = $VirtualDesktopWidth
		$Height = $VirtualDesktopHeight
	EndIf
	For $i = 0 To 5
		Do
			$Pos[$i][0] = Random($Randabstand + $Rahmenbreite, $Width - $Randabstand - $Seitenabstand, 1)
			$Pos[$i][1] = Random($Randabstand + $Rahmenbreite, $Height - $Randabstand - $Rahmenbreite, 1)
		Until _isAway($i)
	Next
EndFunc   ;==>_Set_Pos

Func _isAway($iPosIndex)
	If $iPosIndex = 0 Then Return 1
	For $z = 0 To $iPosIndex - 1
		If Sqrt(($Pos[$iPosIndex][0] - $Pos[$z][0])^2 + ($Pos[$iPosIndex][1] - $Pos[$z][1])^2) < $Min_Distance Then Return 0
	Next
	Return 1
EndFunc   ;==>_isAway

Func _DrawStart()
	_GDIPlus_GraphicsDrawLine($hGraphic, @DesktopWidth - $Seitenabstand, 0, @DesktopWidth - $Seitenabstand, @DesktopHeight, $hPenRahmen)
	For $i = 0 To 5
		If $Aktiv[$i] Then
			_DrawLine_Angle($Pos[$i][0], $Pos[$i][1], $Winkel[$i], $hPen[$i], $LinienLen)
			GUICtrlSetState($Label_Punkte[$i], $GUI_SHOW)
			Sleep(700)
		EndIf
	Next
EndFunc   ;==>_DrawStart

Func _DrawSSStart()
	For $i = 0 To 5
		If $Aktiv[$i] Then
			_DrawLine_Angle($Pos[$i][0], $Pos[$i][1], $Winkel[$i], $hPen[$i], $LinienLen)
			GUICtrlSetState($Label_Punkte[$i], $GUI_SHOW)
;~ 			Sleep(700)
		EndIf
	Next
EndFunc   ;==>_DrawSSStart

Func _DrawRahmen($Redraw = 1)
	If $Redraw = 1 Then _WinAPI_RedrawWindow($hGUI)
	Local $Width = @DesktopWidth, $Height = @DesktopHeight
	If $ScrnSvr Then
		$Width = $VirtualDesktopWidth
		$Height = $VirtualDesktopHeight
	EndIf
	_GDIPlus_GraphicsDrawLine($hGraphic, $Rahmenbreite / 2, 0, $Rahmenbreite / 2, $Height, $hPenRahmen)
	_GDIPlus_GraphicsDrawLine($hGraphic, 0, $Rahmenbreite / 2, $Width, $Rahmenbreite / 2, $hPenRahmen)
	_GDIPlus_GraphicsDrawLine($hGraphic, $Width - $Rahmenbreite / 2, 0, $Width - $Rahmenbreite / 2, $Height, $hPenRahmen)
	_GDIPlus_GraphicsDrawLine($hGraphic, 0, $Height - $Rahmenbreite / 2, $Width, $Height - $Rahmenbreite / 2, $hPenRahmen)
EndFunc   ;==>_DrawRahmen

Func _ArraySum($array)
	;by funkey für µit-November
	If (Not IsArray($array)) Then
		SetError(1)
		Return 0
	EndIf
	Local $iSum = 0
	For $i = 0 To UBound($array) - 1
		If StringIsFloat($array[$i]) Or StringIsInt($array[$i]) Then $iSum += $array[$i]
	Next
	Return $iSum
EndFunc   ;==>_ArraySum

Func _Screen_Capture()
	If Not FileExists(@ScriptDir & '\ScreenShots Kurven-Spiel') Then DirCreate(@ScriptDir & '\ScreenShots Kurven-Spiel')
	Local $Width = @DesktopWidth, $Height = @DesktopHeight
	If $ScrnSvr Then
		$Width = $VirtualDesktopWidth
		$Height = $VirtualDesktopHeight
	EndIf
	_ScreenCapture_CaptureWnd(@ScriptDir & '\ScreenShots Kurven-Spiel\Kurven-Spiel_' & @YEAR & @MON & @MDAY & @HOUR & @MIN & @SEC & '.jpg', $hGUI, 0, 0, $Width, $Height, 0)
EndFunc   ;==>_Screen_Capture

Func _Minimize()
	GUISetState(@SW_MINIMIZE)
EndFunc   ;==>_Minimize

Func _BlinkPause()
	If GUICtrlRead($Pause_Label) = "Pause" Then
		GUICtrlSetData($Pause_Label, " ")
	ElseIf GUICtrlRead($Pause_Label) = " " Then
		GUICtrlSetData($Pause_Label, "Ende?")
	ElseIf GUICtrlRead($Pause_Label) = "Ende?" Then
		GUICtrlSetData($Pause_Label, "")
	ElseIf GUICtrlRead($Pause_Label) = "" Then
		GUICtrlSetData($Pause_Label, "Pause")
	EndIf
EndFunc

Func _Pause()
	$Stop = Not $Stop
	If $Stop Then
		AdlibUnRegister("_Zyklus")
		AdlibRegister("_BlinkPause", 700)
		GUISetCursor(2, 1)
		GUICtrlSetState($Pause_Label, $GUI_SHOW)
		HotKeySet("{Esc}", "_Exit")
	Else
		GUICtrlSetState($Pause_Label, $GUI_HIDE)
		GUISetCursor(16, 1)
		AdlibUnRegister("_BlinkPause")
		AdlibRegister("_Zyklus", 35)
		HotKeySet("{Esc}", "_Pause")
	EndIf
EndFunc

Func _StartScrnSvr()
	Global $new, $last = _IdleTicks()
	Global $hGUI = GUICreate($Titel, $VirtualDesktopWidth, $VirtualDesktopHeight, 0, 0, $WS_POPUP, $WS_EX_TOPMOST)
	Global $hGraphic = _GDIPlus_GraphicsCreateFromHWND($hGUI)
	GUISetBkColor(0x0)
	Global $hPenRahmen = _GDIPlus_PenCreate(0xA0FFFFFF, $Rahmenbreite)
	GUISetState()
	GUISetCursor(16, 1)
	Sleep(500)
	For $i = 0 To 5
		$Aktiv[$i] = 2
		$Alive[$i] = 1
		$hPen[$i] = _GDIPlus_PenCreate('0xFF' & $Farbe[$i], $Linienbreite)
		$Winkel[$i] = Random(170, 190) ;)
	Next
	_Set_Pos()
	_DrawRahmen()
	_DrawSSStart()
	_Luecken()
	AdlibRegister("_Zyklus", 35)

    While 1
        $new = _IdleTicks()
        If $new < $last Then
            ExitLoop
        EndIf
        $last = $new
		Sleep(100)
    WEnd
	_Exit()
EndFunc

Func _IdleTicks() ; thanks to erifash for the routine
    Local $aTSB = DllCall("kernel32.dll", "long", "GetTickCount")
    Local $ticksSinceBoot = $aTSB[0]
    Local $struct = DllStructCreate("uint;dword")
    DllStructSetData($struct, 1, DllStructGetSize($struct))
    DllCall("user32.dll", "int", "GetLastInputInfo", "ptr", DllStructGetPtr($struct))
    Local $ticksSinceIdle = DllStructGetData($struct, 2)
    Return ($ticksSinceBoot - $ticksSinceIdle)
EndFunc   ;==>_IdleTicks

Func _ProcessGetParent($i_pid) ;get PID from parent process done by SmOke_N
    Local $TH32CS_SNAPPROCESS = 0x00000002

    Local $a_tool_help = DllCall("Kernel32.dll", "long", "CreateToolhelp32Snapshot", "int", $TH32CS_SNAPPROCESS, "int", 0)
    If IsArray($a_tool_help) = 0 Or $a_tool_help[0] = -1 Then Return SetError(1, 0, $i_pid)

    Local $tagPROCESSENTRY32 = _
            DllStructCreate( _
            "dword dwsize;" & _
            "dword cntUsage;" & _
            "dword th32ProcessID;" & _
            "uint th32DefaultHeapID;" & _
            "dword th32ModuleID;" & _
            "dword cntThreads;" & _
            "dword th32ParentProcessID;" & _
            "long pcPriClassBase;" & _
            "dword dwFlags;" & _
            "char szExeFile[260]" _
            )
    DllStructSetData($tagPROCESSENTRY32, 1, DllStructGetSize($tagPROCESSENTRY32))

    Local $p_PROCESSENTRY32 = DllStructGetPtr($tagPROCESSENTRY32)

    Local $a_pfirst = DllCall("Kernel32.dll", "int", "Process32First", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32)
    If IsArray($a_pfirst) = 0 Then Return SetError(2, 0, $i_pid)

    Local $a_pnext, $i_return = 0
    If DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") = $i_pid Then
        $i_return = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID")
        DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0])
        If $i_return Then Return $i_return
        Return $i_pid
    EndIf

    While @error = 0
        $a_pnext = DllCall("Kernel32.dll", "int", "Process32Next", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32)
        If DllStructGetData($tagPROCESSENTRY32, "th32ProcessID") = $i_pid Then
            $i_return = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID")
            If $i_return Then ExitLoop
            $i_return = $i_pid
            ExitLoop
        EndIf
    WEnd

    DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0])
    Return $i_return
EndFunc   ;==>_ProcessGetParent

Func _ProcessGetChildren($i_pid) ; First level children processes only done by SmOke_N
    Local Const $TH32CS_SNAPPROCESS = 0x00000002

    Local $a_tool_help = DllCall("Kernel32.dll", "long", "CreateToolhelp32Snapshot", "int", $TH32CS_SNAPPROCESS, "int", 0)
    If IsArray($a_tool_help) = 0 Or $a_tool_help[0] = -1 Then Return SetError(1, 0, $i_pid)

    Local $tagPROCESSENTRY32 = _
            DllStructCreate _
            ( _
            "dword dwsize;" & _
            "dword cntUsage;" & _
            "dword th32ProcessID;" & _
            "uint th32DefaultHeapID;" & _
            "dword th32ModuleID;" & _
            "dword cntThreads;" & _
            "dword th32ParentProcessID;" & _
            "long pcPriClassBase;" & _
            "dword dwFlags;" & _
            "char szExeFile[260]" _
            )
    DllStructSetData($tagPROCESSENTRY32, 1, DllStructGetSize($tagPROCESSENTRY32))

    Local $p_PROCESSENTRY32 = DllStructGetPtr($tagPROCESSENTRY32)

    Local $a_pfirst = DllCall("Kernel32.dll", "int", "Process32First", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32)
    If IsArray($a_pfirst) = 0 Then Return SetError(2, 0, $i_pid)

    Local $a_pnext, $a_children[11] = [10], $i_child_pid, $i_parent_pid, $i_add = 0
    $i_child_pid = DllStructGetData($tagPROCESSENTRY32, "th32ProcessID")
    If $i_child_pid <> $i_pid Then
        $i_parent_pid = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID")
        If $i_parent_pid = $i_pid Then
            $i_add += 1
            $a_children[$i_add] = $i_child_pid
        EndIf
    EndIf

    While 1
        $a_pnext = DllCall("Kernel32.dll", "int", "Process32Next", "long", $a_tool_help[0], "ptr", $p_PROCESSENTRY32)
        If IsArray($a_pnext) And $a_pnext[0] = 0 Then ExitLoop
        $i_child_pid = DllStructGetData($tagPROCESSENTRY32, "th32ProcessID")
        If $i_child_pid <> $i_pid Then
            $i_parent_pid = DllStructGetData($tagPROCESSENTRY32, "th32ParentProcessID")
            If $i_parent_pid = $i_pid Then
                If $i_add = $a_children[0] Then
                    ReDim $a_children[$a_children[0] + 10]
                    $a_children[0] = $a_children[0] + 10
                EndIf
                $i_add += 1
                $a_children[$i_add] = $i_child_pid
            EndIf
        EndIf
    WEnd

    If $i_add <> 0 Then
        ReDim $a_children[$i_add + 1]
        $a_children[0] = $i_add
    EndIf

    DllCall("Kernel32.dll", "int", "CloseHandle", "long", $a_tool_help[0])
    If $i_add Then Return $a_children
    Return SetError(3, 0, 0)
EndFunc   ;==>_ProcessGetChildren

Func _Exit()
	For $e = 0 To 5
		_GDIPlus_PenDispose($hPen[$e])
	Next
	_GDIPlus_PenDispose($hPenRahmen)
	_GDIPlus_GraphicsDispose($hGraphic)
	_GDIPlus_Shutdown()
	GUIDelete($hGUI)
	Exit
EndFunc   ;==>_Exit

Func _ExitPreview()
	_GDIPlus_Shutdown()
	GUIDelete($hGuiPV)
	Exit
EndFunc   ;==>_Exit

#Region _MouseHover.au3
;====================================================================================================================================
;	UDF Name: _MouseHover.au3
;	Author: marfdaman (Marvin)
;	Contributions: RazerM (adding SetText parameter to _HoverFound and _HoverUndo).
;	email: marfdaman at gmail dot com
;	Use: Enable hover events for controls
;	Note(s): If you want to use this i.c.w. an AdlibEnable in your current script, make your Adlib call "_HoverCheck()" as well.
;	In this case, _HoverOn must NOT be called.
;====================================================================================================================================

;===============================================================================
; Description:			_HoverAddCtrl
; Parameter(s):		$___ControlID -> Control ID of control to be hoverchecked
; Requirement:			Array.au3
; Return Value(s):	None
;===============================================================================
Func _HoverAddCtrl($___ControlID)
	_ArrayAdd($HoverArray, $___ControlID)
EndFunc   ;==>_HoverAddCtrl
;===============================================================================
; Description:			Checks whether the mousecursor is hovering over any of the defined controls.
; Parameter(s):		None
; Requirement:			None
; Return Value(s):	If a control has matched, an array will be returned, with $array[1] being either
;					"AcquiredHover" or "LostHover". $array[2] will contain the control ID.
;					It is recommended that you put this function in an AdlibEnable, since it's EXTREMELY
;					resource friendly.
;===============================================================================
Func _HoverCheck()
	$HoverData = GUIGetCursorInfo()
	If Not IsArray($HoverData) Then Return
	$Temp_Found = 0
	For $i = 1 To UBound($HoverArray) - 1
		If $HoverData[4] = $HoverArray[$i] Then
			$Temp_Found = $i
		EndIf
	Next
	Select
		Case $Temp_Found = 0 And $HoverActive = 1 Or $Temp_Found <> 0 And $Temp_Found <> $Global_I And $HoverActive = 1
			$HoverActive = 0
			$Temp_Found = 0
			$szTemp_Array[0] = "LostHover"
			$szTemp_Array[1] = $HoverArray[$Global_I]
			Return $szTemp_Array
		Case $Temp_Found > 0 And $HoverActive = 0
			$Global_I = $Temp_Found
			$HoverActive = 1
			$Temp_Found = 0
			$szTemp_Array[0] = "AcquiredHover"
			$szTemp_Array[1] = $HoverArray[$Global_I]
			Return $szTemp_Array
	EndSelect
EndFunc   ;==>_HoverCheck
#EndRegion _MouseHover.au3

Func _ProcessHover()
	$ControlID = _HoverCheck()
	If IsArray($ControlID) Then
		If $ControlID[0] = "AcquiredHover" Then
			_HoverFound($ControlID[1])
		Else
			_HoverLost($ControlID[1])
		EndIf
	EndIf
EndFunc   ;==>_ProcessHover

Func _HoverLost($ControlID)
	For $z = 29 To 25 Step -1
		GUICtrlSetFont($ControlID, $z)
		Sleep(10)
	Next
	If StringLeft(GUICtrlRead($ControlID), 6) <> "Player" Then GUICtrlSetColor($ControlID, 0xFFFFFF)
EndFunc   ;==>_HoverLost

Func _HoverFound($ControlID)
	If StringLeft(GUICtrlRead($ControlID), 6) <> "Player" Then GUICtrlSetColor($ControlID, 0x00FF00)
	For $z = 26 To 30
		GUICtrlSetFont($ControlID, $z)
		Sleep(10)
	Next
EndFunc   ;==>_HoverFound

#Region dwmAPI.au3
;===============================================================================
; Function Name:   _EnableDisableAero()
; Description:    Enables or Disables the Aero design from Vista to the default design.
; Parameter(s):    $bEnable [BOOLEAN]: True enables the Aero, False disables it.
; Requirement(s):  dwmapi.dll, Windows Vista
; Return Value(s): Returnvals of DLLCall
; Author(s):       GtaSpider
;===============================================================================
Func _EnableDisableAero($bEnable = True) ;True/False
	Local $aDll = DllCall($hDwmApiDll, "int", "DwmEnableComposition", "int", $bEnable)
	If @error Then Return SetError(@error, 0, 0)
	Return $aDll[0]
EndFunc   ;==>_EnableDisableAero
;===============================================================================
; Function Name:   _IsAeroEnable
; Description:    Checks if aero is enable
; Parameter(s):    None
; Requirement(s):  dwmapi.dll, Windows Vista
; Return Value(s): 0 If disabeld, 1 if enabled
; Author(s):       GtaSpider
;===============================================================================
Func _IsAeroEnable()
	Local $asDll = DllCall($hDwmApiDll, "int", "DwmIsCompositionEnabled", "str", "")
	If @error Then Return SetError(@error, 0, 0)
	Return StringReplace(StringReplace(Asc($asDll[1]), "1", True), "0", False)
EndFunc   ;==>_IsAeroEnable

Func OnAutoItExit()
	DllClose($hDwmApiDll);Close dwmapi
EndFunc   ;==>OnAutoItExit
#EndRegion dwmAPI.au3
