1. ;;Simplest way to make hotkeys can be done other ways, Basically hit the button and it calls the function
  2. HotKeySet("{Numpad6}", "Right")
  3. HotKeySet("{Numpad4}", "Left")
  4. HotKeySet("{Numpad8}", "Forward")
  5. HotKeySet("{Numpad2}", "Backward")
  6. HotKeySet("{Numpad3}", "Down")
  7. HotKeySet("{Numpad9}", "Up")
  8. ;;I think we all know what this is
  9. $PI = 3.14159265358979
  10. ;;Name of character logged into the client you wish to attach to
  11. $Character_Name = "Tagy"
  12. ;;Value for how much to modify each axis
  13. $Magnitude = 1
  14. ;;Offsets for coord pointers
  15. Global $N3_Coord_Offsets[3], $Client_Handles, $Z_PTR, $Y_PTR, $X_PTR, $VectorX_PTR ,$VectorY_PTR
  16. $N3_DLL_Base_Offset = 0x63620
  17. $N3_Coord_Offsets[0] = 0x84
  18. $N3_Coord_Offsets[1] = 0x50
  19. $N3_Coord_Offsets[2] = 0x60
  20.  
  21. ;;call load pointers once at the start which will then update every 2 seconds
  22. Load_Pointers()
  23. ;;Start a timer till refresh
  24. $Refresh_Pointers = TimerInit()
  25. While 1
  26. If Timerdiff($Refresh_Pointers) > 2000 Then
  27. ;;Recalculate offsets every 2 seconds
  28. Load_Pointers()
  29. $Refresh_Pointers = TimerInit()
  30. Endif
  31. ;;Delay to not waste cpu
  32. Sleep(250)
  33. WEnd
  34.  
  35. ;;Calculate my angle from both Vectors
  36. Func Get_Angle()
  37. Return Atan2(_MemoryRead($VectorY_PTR, $Client_Handles[0], "Float"),_MemoryRead($VectorX_PTR, $Client_Handles[0], "Float"))* 180 / $pi
  38. Endfunc
  39.  
  40. ;;Calculate the Vector for the angle specified
  41. Func Angle_To_Vector($Angle)
  42. Local $New_Vector[2]
  43. $Heading = $Pi * $Angle / 180
  44. $New_Vector[0] = $Magnitude * sin($Heading)
  45. $New_Vector[1] = $Magnitude * cos($Heading)
  46. Return $New_Vector
  47. Endfunc
  48.  
  49. ;;Atan2 a math function required for calcs
  50. Func ATan2($x, $y)
  51. If $y < 0 Then
  52. Return -ATan2($x, -$y)
  53. ElseIf $x < 0 Then
  54. Return $Pi - ATan(-$y / $x)
  55. ElseIf $x > 0 Then
  56. Return ATan($y / $x)
  57. ElseIf $y <> 0 Then
  58. Return $Pi / 2
  59. Else
  60. SetError( 1 )
  61. EndIf
  62. EndFunc
  63.  
  64. ;;Load/update pointer data
  65. Func Load_Pointers()
  66. ;;Gets all 3 handles to the client based off of toon name
  67. $Client_Handles = Get_AO_Client($Character_Name)
  68. If $Client_Handles = 0 then Return
  69. ;;Calls Create_Pointer_Path and returns the Z axis address
  70. $Coord_PTR = Create_Pointer_Path("n3.dll", $N3_DLL_Base_Offset, $N3_Coord_Offsets)
  71. ;;Declaring the addresses needed based off the Z axis
  72. $Z_PTR = $Coord_PTR
  73. $Y_PTR = $Coord_PTR + 0x4
  74. $X_PTR = $Coord_PTR - 0x4
  75. $VectorX_PTR = $Coord_PTR + 0x68
  76. $VectorY_PTR = $Coord_PTR + 0x70
  77. Endfunc
  78.  
  79. ;;gets the final address in a pointer from a array of offsets
  80. Func Create_Pointer_Path($DLL_Name, $Dll_Offset,$Offset_Array)
  81. ;;Get the base address of n3.dll
  82. $Address = _MemoryModuleGetBaseAddress($Client_Handles[2], $DLL_Name)+$DLL_Offset
  83. ;;Levels up the pointer
  84. For $I = 0 to UBound($Offset_Array)-1
  85. $Address = _MemoryRead($Address, $Client_Handles[0])+$Offset_Array[$I]
  86. Next
  87. ;;Returns the Z axis address
  88. Return "0x" & Hex($Address)
  89. Endfunc
  90.  
  91. ;It's not required to attach to a client by name it's just a function i like basically give it a toon name and it will attach to it
  92. Func Get_AO_Client($Name)
  93. Local $Client_Handles[3]
  94. ;;makes an array of all processes named Client.exe
  95. $LIST = ProcessList("Client.exe")
  96. ;;makes an array of all Windows named Anarchy Online
  97. $WLIST = WinList("Anarchy Online")
  98. ;;it's messy looking but in this for loop it matches a bunch of data
  99. For $C = 1 to $LIST[0][0]
  100. ;;Opens a temporary memory handle to the client to read it's name
  101. $Temp_Handle = _Memoryopen($LIST[$C][1])
  102. ;;Gets the static address of the name
  103. Global $Name_Addr = _MemoryModuleGetBaseAddress($LIST[$C][1], "Interfaces.dll")+0x2F844
  104. ;;Reads the name
  105. $Name_Check = _MemoryRead($Name_Addr, $Temp_Handle, "Char[14]")
  106. ;;Checks the character name of the current client against the one in the parameters
  107. If $Name_Check = $Name then
  108. ;;Was true so opens the memory handle
  109. $Client_Handles[0] = _Memoryopen($LIST[$C][1])
  110. ;;Process Handle
  111. $Client_Handles[2] = $LIST[$C][1]
  112. For $i = 1 To $WList[0][0]
  113. ;;Makes a for loop then compares the process handle to the window handle until true
  114. If WinGetProcess($WList[$i][1]) = $LIST[$C][1] Then
  115. ;;Got the correct handle end the loop
  116. $Client_Handles[1] = $WList[$i][1]
  117. ExitLoop
  118. EndIf
  119. Next
  120. Endif
  121. ;;close the temporary handle
  122. _MemoryClose($Temp_Handle)
  123. Next
  124. ;;Returns OpenMemory handle/Window handle/Process handle
  125. Return $Client_Handles
  126. Endfunc
  127.  
  128. ;;Calculates the 2 vectors for the direction desired then updates the axis in the memory
  129. Func Forward()
  130. $Vector = Angle_To_Vector(Get_Angle())
  131. _MEMORYWRITE($X_PTR, $Client_Handles[0],_MEMORYREAD($X_PTR, $Client_Handles[0], "Float")+$Vector[0], "Float")
  132. _MEMORYWRITE($Y_PTR, $Client_Handles[0],_MEMORYREAD($Y_PTR, $Client_Handles[0], "Float")+$Vector[1], "Float")
  133. EndFunc
  134.  
  135. ;;Calculates the 2 vectors for the direction desired then updates the axis in the memory
  136. Func Backward()
  137. $Vector = Angle_To_Vector(Get_Angle()+180)
  138. _MEMORYWRITE($X_PTR, $Client_Handles[0],_MEMORYREAD($X_PTR, $Client_Handles[0], "Float")+$Vector[0], "Float")
  139. _MEMORYWRITE($Y_PTR, $Client_Handles[0],_MEMORYREAD($Y_PTR, $Client_Handles[0], "Float")+$Vector[1], "Float")
  140. EndFunc
  141.  
  142. ;;Calculates the 2 vectors for the direction desired then updates the axis in the memory
  143. Func Right()
  144. $Vector = Angle_To_Vector(Get_Angle()+90)
  145. _MEMORYWRITE($X_PTR, $Client_Handles[0],_MEMORYREAD($X_PTR, $Client_Handles[0], "Float")+$Vector[0], "Float")
  146. _MEMORYWRITE($Y_PTR, $Client_Handles[0],_MEMORYREAD($Y_PTR, $Client_Handles[0], "Float")+$Vector[1], "Float")
  147. EndFunc
  148.  
  149. ;;Calculates the 2 vectors for the direction desired then updates the axis in the memory
  150. Func Left()
  151. $Vector = Angle_To_Vector(Get_Angle()-90)
  152. _MEMORYWRITE($X_PTR, $Client_Handles[0],_MEMORYREAD($X_PTR, $Client_Handles[0], "Float")+$Vector[0], "Float")
  153. _MEMORYWRITE($Y_PTR, $Client_Handles[0],_MEMORYREAD($Y_PTR, $Client_Handles[0], "Float")+$Vector[1], "Float")
  154. EndFunc
  155.  
  156. ;;Reads the Z axis and adds the Magnitude variable onto it then rewrites it
  157. Func Up()
  158. _MEMORYWRITE($Z_PTR, $Client_Handles[0],_MEMORYREAD($Z_PTR, $Client_Handles[0], "Float")+$Magnitude, "Float")
  159. EndFunc
  160.  
  161. ;;Reads the Z axis and subtracts the Magnitude variable onto it then rewrites it
  162. Func Down()
  163. _MEMORYWRITE($Z_PTR, $Client_Handles[0],_MEMORYREAD($Z_PTR, $Client_Handles[0], "Float")-$Magnitude, "Float")
  164. EndFunc
  165.  
  166. ;;Opens the processes memory
  167. Func _MemoryOpen($iv_Pid, $iv_DesiredAccess = 0x1F0FFF, $iv_InheritHandle = 1)
  168. If Not ProcessExists($iv_Pid) Then
  169. SetError(1)
  170. Return 0
  171. EndIf
  172. Local $ah_Handle[2] = [DllOpen('kernel32.dll')]
  173. If @Error Then
  174. SetError(2)
  175. Return 0
  176. EndIf
  177. Local $av_OpenProcess = DllCall($ah_Handle[0], 'int', 'OpenProcess', 'int', $iv_DesiredAccess, 'int', $iv_InheritHandle, 'int', $iv_Pid)
  178. If @Error Then
  179. DllClose($ah_Handle[0])
  180. SetError(3)
  181. Return 0
  182. EndIf
  183. $ah_Handle[1] = $av_OpenProcess[0]
  184. Return $ah_Handle
  185. EndFunc
  186.  
  187. ;;Reads the processes memory.
  188. Func _MemoryRead($iv_Address, $ah_Handle, $sv_Type = 'dword')
  189. If Not IsArray($ah_Handle) Then
  190. SetError(1)
  191. Return 0
  192. EndIf
  193. Local $v_Buffer = DllStructCreate($sv_Type)
  194. If @Error Then
  195. SetError(@Error + 1)
  196. Return 0
  197. EndIf
  198. DllCall($ah_Handle[0], 'int', 'ReadProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
  199. If Not @Error Then
  200. Local $v_Value = DllStructGetData($v_Buffer, 1)
  201. Return $v_Value
  202. Else
  203. SetError(6)
  204. Return 0
  205. EndIf
  206. EndFunc
  207.  
  208. ;;Writes to the processes memory
  209. Func _MemoryWrite($iv_Address, $ah_Handle, $v_Data, $sv_Type = 'dword')
  210. If Not IsArray($ah_Handle) Then
  211. SetError(1)
  212. Return 0
  213. EndIf
  214. Local $v_Buffer = DllStructCreate($sv_Type)
  215. If @Error Then
  216. SetError(@Error + 1)
  217. Return 0
  218. Else
  219. DllStructSetData($v_Buffer, 1, $v_Data)
  220. If @Error Then
  221. SetError(6)
  222. Return 0
  223. EndIf
  224. EndIf
  225. DllCall($ah_Handle[0], 'int', 'WriteProcessMemory', 'int', $ah_Handle[1], 'int', $iv_Address, 'ptr', DllStructGetPtr($v_Buffer), 'int', DllStructGetSize($v_Buffer), 'int', '')
  226. If Not @Error Then
  227. Return 1
  228. Else
  229. SetError(7)
  230. Return 0
  231. EndIf
  232. EndFunc
  233.  
  234. ;;Closes a handle to the memory
  235. Func _MemoryClose($ah_Handle)
  236. If Not IsArray($ah_Handle) Then
  237. SetError(1)
  238. Return 0
  239. EndIf
  240. DllCall($ah_Handle[0], 'int', 'CloseHandle', 'int', $ah_Handle[1])
  241. If Not @Error Then
  242. DllClose($ah_Handle[0])
  243. Return 1
  244. Else
  245. DllClose($ah_Handle[0])
  246. SetError(2)
  247. Return 0
  248. EndIf
  249. EndFunc
  250.  
  251. ;;I don't know it wasn't made by me
  252. Func SetPrivilege( $privilege, $bEnable )
  253. Const $TOKEN_ADJUST_PRIVILEGES = 0x0020
  254. Const $TOKEN_QUERY = 0x0008
  255. Const $SE_PRIVILEGE_ENABLED = 0x0002
  256. Local $hToken, $SP_auxret, $SP_ret, $hCurrProcess, $nTokens, $nTokenIndex, $priv
  257. $nTokens = 1
  258. $LUID = DLLStructCreate("dword;int")
  259. If IsArray($privilege) Then $nTokens = UBound($privilege)
  260. $TOKEN_PRIVILEGES = DLLStructCreate("dword;dword[" & (3 * $nTokens) & "]")
  261. $NEWTOKEN_PRIVILEGES = DLLStructCreate("dword;dword[" & (3 * $nTokens) & "]")
  262. $hCurrProcess = DLLCall("kernel32.dll","hwnd","GetCurrentProcess")
  263. $SP_auxret = DLLCall("advapi32.dll","int","OpenProcessToken","hwnd",$hCurrProcess[0], _
  264. "int",BitOR($TOKEN_ADJUST_PRIVILEGES,$TOKEN_QUERY),"int_ptr",0)
  265. If $SP_auxret[0] Then
  266. $hToken = $SP_auxret[3]
  267. DLLStructSetData($TOKEN_PRIVILEGES,1,1)
  268. $nTokenIndex = 1
  269. While $nTokenIndex <= $nTokens
  270. If IsArray($privilege) Then
  271. $priv = $privilege[$nTokenIndex-1]
  272. Else
  273. $priv = $privilege
  274. EndIf
  275. $ret = DLLCall("advapi32.dll","int","LookupPrivilegeValue","str","","str",$priv, _
  276. "ptr",DLLStructGetPtr($LUID))
  277. If $ret[0] Then
  278. If $bEnable Then
  279. DLLStructSetData($TOKEN_PRIVILEGES,2,$SE_PRIVILEGE_ENABLED,(3 * $nTokenIndex))
  280. Else
  281. DLLStructSetData($TOKEN_PRIVILEGES,2,0,(3 * $nTokenIndex))
  282. EndIf
  283. DLLStructSetData($TOKEN_PRIVILEGES,2,DllStructGetData($LUID,1),(3 * ($nTokenIndex-1)) + 1)
  284. DLLStructSetData($TOKEN_PRIVILEGES,2,DllStructGetData($LUID,2),(3 * ($nTokenIndex-1)) + 2)
  285. DLLStructSetData($LUID,1,0)
  286. DLLStructSetData($LUID,2,0)
  287. EndIf
  288. $nTokenIndex += 1
  289. WEnd
  290. $ret = DLLCall("advapi32.dll","int","AdjustTokenPrivileges","hwnd",$hToken,"int",0, _
  291. "ptr",DllStructGetPtr($TOKEN_PRIVILEGES),"int",DllStructGetSize($NEWTOKEN_PRIVILEGES), _
  292. "ptr",DllStructGetPtr($NEWTOKEN_PRIVILEGES),"int_ptr",0)
  293. $f = DLLCall("kernel32.dll","int","GetLastError")
  294. EndIf
  295. $NEWTOKEN_PRIVILEGES=0
  296. $TOKEN_PRIVILEGES=0
  297. $LUID=0
  298. If $SP_auxret[0] = 0 Then Return 0
  299. $SP_auxret = DLLCall("kernel32.dll","int","CloseHandle","hwnd",$hToken)
  300. If Not $ret[0] And Not $SP_auxret[0] Then Return 0
  301. return $ret[0]
  302. EndFunc
  303.  
  304. ;;Calculates the base load address of a dll in a process
  305. Func _MemoryModuleGetBaseAddress($iPID, $sModule)
  306. If Not ProcessExists($iPID) Then Return SetError(1, 0, 0)
  307. If Not IsString($sModule) Then Return SetError(2, 0, 0)
  308. Local $PSAPI = DllOpen("psapi.dll")
  309. Local $hProcess
  310. Local $PERMISSION = BitOR(0x0002, 0x0400, 0x0008, 0x0010, 0x0020)
  311. If $iPID > 0 Then
  312. Local $hProcess = DllCall("kernel32.dll", "ptr", "OpenProcess", "dword", $PERMISSION, "int", 0, "dword", $iPID)
  313. If $hProcess[0] Then
  314. $hProcess = $hProcess[0]
  315. EndIf
  316. EndIf
  317. Local $Modules = DllStructCreate("ptr[1024]")
  318. Local $aCall = DllCall($PSAPI, "int", "EnumProcessModules", "ptr", $hProcess, "ptr", DllStructGetPtr($Modules), "dword", DllStructGetSize($Modules), "dword*", 0)
  319. If $aCall[4] > 0 Then
  320. Local $iModnum = $aCall[4] / 4
  321. Local $aTemp
  322. For $i = 1 To $iModnum
  323. $aTemp = DllCall($PSAPI, "dword", "GetModuleBaseNameW", "ptr", $hProcess, "ptr", Ptr(DllStructGetData($Modules, 1, $i)), "wstr", "", "dword", 260)
  324. If $aTemp[3] = $sModule Then
  325. DllClose($PSAPI)
  326. Return Ptr(DllStructGetData($Modules, 1, $i))
  327. EndIf
  328. Next
  329. EndIf
  330. DllClose($PSAPI)
  331. Return SetError(-1, 0, 0)
  332. EndFunc