Что нового

требуется оптимизация и чистка кода

winstan

Эксплотатор)
Сообщения
406
Репутация
78
Версия AutoIt: 3.6.6.1

Описание:требуется оптимизация кода для уменьшения его длинный и увеличения быстродействия
Код:
#RequireAdmin
#include <nomadmemory.au3>
#include <GUIConstantsEx.au3>
#include <GuiButton.au3>

Opt("MustDeclareVars", 1)

Global $result, $pointer, $LVLming, $LVLmaxg, $btn[10], $iRand, $menuvalue, $hWnd1, $Process, $memory, $hWnd1, $LVLmax, $LVLmin, $baseadr, $z, $lvlmobac, $baseadrq, $guin
Global $manamin, $beginmana, $resultlvl, $lvlmoba

Global $Process = "Nksp.exe"
Global $hillmin
Global $manamin

Global $a="0"
Global $z="0"

Global $baseadrhil = 0x106AAC40
Global $offsethil = 0x00109320

Global $baseadrmana = 0x106AAC40
Global $offsetmana = 0x00109328

Global $baseadr = 0x106AAC40
Global $baseadrq = 0x00108F58

Global $memory = _MemoryOpen (ProcessExists($Process))
Global $hWnd1 = _ProcessGetWindow($Process)
Global $begin = TimerInit()
;~ ==========================
Global $pointerr = _MemoryRead ($baseadr, $memory)
$lvlmoba = ($pointerr + $baseadrq)

Global $pointerhil = _MemoryRead ($baseadrhil, $memory)
Global $hill = $pointerhil + $offsethil

Global $pointermana = _MemoryRead ($baseadrmana, $memory)
Global $mana = $pointermana + $offsetmana

;~ ==========================
$guin = GUICreate("Buttons", 225, 100)
	$LVLmaxg = GUICtrlCreateEdit("105", 115, 5, 110, 20, 1)
	$LVLming = GUICtrlCreateEdit("103", 5, 5, 110, 20, 1)
Global 	$manaming = GUICtrlCreateEdit("2800", 115, 25, 110, 20, 1)
Global 	$hillming = GUICtrlCreateEdit("3800", 5, 25, 110, 20, 1)
	$btn[0] = GUICtrlCreateButton("Старт", 5, 60, 100, 30)
	$btn[1] = GUICtrlCreateButton("Выход", 120, 60, 100, 30)

	GUISetState()

	While 1
		Switch GUIGetMsg()
			Case $GUI_EVENT_CLOSE
				Exit
			Case $btn[0]
				$LVLmax = GUICtrlRead($LVLmaxg,1)
				$LVLmin = GUICtrlRead($LVLming,1)
				$hillmin = GUICtrlRead($hillming,1)
				$manamin = GUICtrlRead($manaming,1)


				ExitLoop
			Case $btn[1]
				Exit
		EndSwitch
	WEnd
	GUIDelete()
;~ ==========================
While 1
	Sleep(100)
	$resultlvl = _MemoryRead ($lvlmoba, $memory)
	If $LVLmin < $resultlvl Then
		If	$resultlvl < $LVLmax Then
			Sleep(100)
			ControlSend($hWnd1, "", "", "{F9}")
			_point()
			Sleep(100)
            ;~ ==============================================
			if $z="0" Then
				ControlSend($hWnd1, "", "", "{F1}")
				$z="1"
			Else
				ControlSend($hWnd1, "", "", "{F5}")
			EndIf
			;~ ==============================================
			ControlSend($hWnd1, "", "", "{F9}")
			Sleep(1000)
		Else
			ControlSend($hWnd1, "", "", "{TAB}")
			$z="0"
		EndIf
	Else
		ControlSend($hWnd1, "", "", "{TAB}")
		$z="0"
	EndIf
_point()
WEnd
;~ ==============================================
Func _point()
	_hill()
	_Mana()
EndFunc
;~ ==============================================
Func _hill()
	Global $dif = TimerDiff($begin)
	If $dif > "14000" Then
	$result = _MemoryRead ($hill, $memory)
		If $result < $hillmin Then
			
		ControlSend($hWnd1, "", "", "{F7}")
		$begin = TimerInit()
		Else
		EndIf
	Else

	EndIf
EndFunc
Func _Mana()
	Global $difmana = TimerDiff($beginmana)
	If $difmana > "14000" Then
	$result = _MemoryRead ($mana, $memory)
		If $result < $manamin Then
		ControlSend($hWnd1, "", "", "{F8}")
		$beginmana = TimerInit()
		Else
		EndIf
	Else
	EndIf
EndFunc


Func _ProcessGetWindow($iPID, $iRet = 1)
	Local $aWinList = WinList()
	Local $aRet[2]

	If IsString($iPID) Then
		$iPID = ProcessExists($iPID)
	EndIf

	For $i = 1 To UBound($aWinList) - 1
		If WinGetProcess($aWinList[$i][1]) = $iPID Then
			$aRet[0] = $aWinList[$i][0] ;Title
			$aRet[1] = $aWinList[$i][1] ;WinHandle

			If $iRet = 0 Then
				Return $aRet[0]
			EndIf

			If $iRet = 1 Then
				Return $aRet[1]
			EndIf

			Return $aRet
		EndIf
	Next

	Return SetError(1, 0, $aRet)
EndFunc


Примечания:игра Ласт Хаос http://www.lcgame.ru/
P.S. собирал скрипт из справки и примеров ,ключивое слово "собирал" поэтому лишнее есть и не мало
 
Верх