Waypoint Script

05/02/2012 14:30 Skatefreaky#1
Hallo Com,

habe jetzt mal ein kleines Waypoint-Script erstellt. Das ganze funktioniert auch soweit, nur dass er in eine total andere Richtung als in die gespeicherte läuft :o.

Jetzt wollte ich euch mal fragen ob ihr kurz drüber gucken könnt und Fehler entdeckt! Danke schonmal.

Code:
#include <ButtonConstants.au3>
#include <EditConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <nomadmemory.au3>
#RequireAdmin


Global $wpField[1000]
Global $i =0
Global $countMax=0
Global $Run = False
Global $openmem = 0
global $status
global $rot_down = "a down"
global $rot_up = "a up"
global $pi = "3.14159265358979323846264338327950"

#Region ### START Koda GUI section ### Form=
$Form1 = GUICreate("Form1", 311, 122, 192, 124)
$WpsaveInput = GUICtrlCreateInput("", 16, 16, 97, 21)
$Button1 = GUICtrlCreateButton("Button1", 16, 40, 97, 25)
$Wpfileinput = GUICtrlCreateInput("", 176, 16, 89, 21)
$Button2 = GUICtrlCreateButton("Button2", 176, 40, 97, 25)
$Button3 = GUICtrlCreateButton("Button3", 104, 96, 73, 25)
$status = GUICtrlCreateLabel("", 8, 64, 244, 25)
GUISetState(@SW_SHOW)
#EndRegion ### END Koda GUI section ###

While 1
	$nMsg = GUIGetMsg()
	Switch $nMsg

		case $Button1
			OpenAionMemory()
			AddWp()

		case $Button2
			readWP()

		case $Button3
			OpenAionMemory()
			$Run = True
			while $Run = True
			walkPoints()
			wend


		Case $GUI_EVENT_CLOSE
			Exit

	EndSwitch
WEnd



Func OpenAionMemory()
	$pid = ProcessExists("AION.bin")
	If $pid == -1 Then
		Return
	EndIf
	$openmem = _MemoryOpen($pid)
	If @error Then
		Return
	EndIf
	$AionRun = True
EndFunc


Func MemReadDLLFloat($offset)
	$StaticOffset = Dec($offset)
	Global $pid
	Global $CUROffset[1]
	$CUROffset[0] = 0
	$baseADDR = _MemoryModuleGetBaseAddress($pid, "Game.dll")
	$finalADDR = "0x" & Hex($baseADDR + $StaticOffset)
	$MemTest = _MemoryRead($finaladdr,$openmem,"float")
	Return $MemTest
EndFunc





Func PlayerXPos()
	return MemReadDLLFloat("BF0A9C")
EndFunc

Func PlayerYPos()
	return MemReadDLLFloat("BF0AA0")
EndFunc

Func PlayerZPos()
	return MemReadDLLFloat("BF0AA4")
EndFunc

Func GetPlayerPos()
	Return MemReadDLLFloat("BECC6C")
EndFunc

Func addWP()

	$playerX = PlayerXPos()
	$playerY = PlayerYPos()
	$playerZ = PlayerZPos()

	$WPFile = "wp"

	$openFile = GuiCtrlRead($wpSaveInput)
	$wpSave = FileOpen($openFile, 1)

	FileWriteLine($wpSave ,Round($playerX,2))
	FileWriteLine($wpSave ,Round($playerY,2))
	FileWriteLine($wpSave ,Round($playerZ,2))
	FileClose($wpSave)
	_toolTip("WayPoint: "&Round($playerX,0)&" - "&Round($playerY,0)&" - "&Round($playerZ,0)&" added")
EndFunc

Func readWP()
	$countMax=0
	$count = 1
	$openFile = GuiCtrlRead($wpFileInput)
	$readWPfile = FileOpen($openFile, 0)

	While 1
		$x1 = FileReadLine($readWPfile,$count)

		if $x1 = "" Then
			$count = 1
			ExitLoop
		EndIf

		If @error = -1 Then	ExitLoop
		$count = $count +1
		$countMax = $countMax +1
		$x2 = FileReadLine($readWPfile,$count)
		$count = $count +1
		$countMax = $countMax +1
		$x3 = FileReadLine($readWPfile,$count)
		$count = $count +1
		$countMax = $countMax +1


	Wend
	FileClose($readWPfile)


	$openFile = GuiCtrlRead($wpFileInput)
	$readWPfile = FileOpen($openFile, 0)

	While 1

		$x1 = FileReadLine($readWPfile,$count)

		if $x1 = "" Then

			$count = 1
			ExitLoop
		EndIf

		If @error = -1 Then	ExitLoop

		$wpField[$count-1] = $x1

		$count = $count +1

		$x2 = FileReadLine($readWPfile,$count)
		$wpField[$count-1] = $x2

		$count = $count +1

		$x3 = FileReadLine($readWPfile,$count)
		$wpField[$count-1] = $x3

		$count = $count +1




	Wend
	_toolTip("Waypoints loaded ... "&$countMax/3&" found" )
	FileClose($readWPfile)

EndFunc

Func walkPoints()
	while $i < ($countMax-1)
		WinActivate("AION Client")
		WinWaitActive("AION Client")
		_toolTip("Move to waypoint "&($i/3)+1)
		$xCoord=$wpField[$i]
		$yCoord=$wpField[$i+1]
		$zCoord=$wpField[$i+2]
		$i=$i+3

		$Distance = calcDist($xCoord,$yCoord)
		while $Distance > 3
			alignRotaion($xCoord, $yCoord, true)
		WEnd

		If $Run = False Then
			Send("{w up}")
			ExitLoop

		EndIf
	WEnd
EndFunc

Func _toolTip($msg)
	GUICtrlSetData($status,$msg)
EndFunc

Func calcDist($xa,$ya)
	$distCalc = sqrt( ($xa-PlayerXPos())^2 + ($ya-PlayerYPos())^2 )
	if($distCalc > 15) Then
	EndIf
	return $distCalc
EndFunc

Func alignRotaion($x, $y, $move = false)
	$playerXcoord = PlayerXPos()
	$playerYcoord = PlayerYPos()

	$diffY = Round($y - $playerYcoord,2)
	$diffX = Round($x - $playerXcoord,2)
	$angle = getAngle($diffX, $diffY)
	$nowAng = getThreeSixty(GetPlayerPos(), true)
	_switchRotate($angle, $nowAng)
	While ($angle + 5) < $nowAng OR ($angle - 5) > $nowAng
		if $move Then
			Send("{w down}")
		EndIf
		Send("{"&$rot_down&"}")
		$nowAng = getThreeSixty(GetPlayerPos(), true)
	WEnd
	if $move Then
		if(($angle + 5) < $nowAng AND ($angle - 5) > $nowAng) Then
			Send("{w up}")
		EndIf
	EndIf
	Send("{"&$rot_up&"}")
EndFunc

Func getAngle($diffX, $diffY)
	$angle = ATan($diffY/$diffX)
	$angle = ($angle * 180.0 )/ $pi
	if $diffX > 0 and $diffY > 0 Then
		return getThreeSixty((180 -$angle),true)
	ElseIf $diffX > 0 and $diffY < 0 Then
		return getThreeSixty((-180 -$angle),true)
	ElseIf $diffX < 0 and $diffY < 0 Then
		return getThreeSixty((0 -$angle),true)
	ElseIf $diffX < 0 and $diffY > 0 Then
		return getThreeSixty((0 -$angle),true)
	EndIf
EndFunc

Func getThreeSixty($angle, $flag = false)
	If($flag) Then
		If($angle < 0) Then
			$angle = (360 - ($angle * -1))
		EndIf
	Else
		If($angle > 360)Then
			$angle = $angle - 360
		ElseIf($angle < 0)Then
			$angle = $angle + 360
		EndIf
	EndIf
	Return $angle
EndFunc

Func _switchRotate($target, $now)
	if($target < $now) Then
		If(($now - $target) > 180) Then
			$rot_down = "a down"
			$rot_up = "a up"
		Else
			$rot_down = "d down"
			$rot_up = "d up"
		EndIf
	Else
		If(($target - $now) > 180) Then
			$rot_down = "d down"
			$rot_up = "d up"
		Else
			$rot_down = "a down"
			$rot_up = "a up"
		EndIf
	EndIf
EndFunc