Advertisement
Guest User

AHK AIMBOT

a guest
Jun 8th, 2016
2,301
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #SingleInstance, force
  2. #NoEnv
  3. WindowTitle := "GTA:SA:MP"
  4. gta := new memory(WindowTitle)
  5. Gui, Add, Text, vsize w150 h50 x73, Poor Aim by Dworkin
  6. Gui, Font, s10
  7. GuiControl, Font, size
  8. Gui, Show, w264 h25, Poor Aim by Dworkin
  9. return
  10. GuiClose:
  11. ExitApp
  12. ~$vk01::
  13. While GetKeyState("vk01", "P")
  14. {
  15. Targetped := gta.read(0xB6F5F0, "UInt", 0x79c)
  16. if (Targetped = 0)
  17. {
  18. }
  19. else
  20. {
  21. sleep 1
  22. MyPosX := gta.read(0xB6F5F0, "float", 0x14, 0x30)
  23. MyPosY := gta.read(0xB6F5F0, "float", 0x14, 0x34)
  24. MyPosZ := gta.read(0xB6F5F0, "float", 0x14, 0x38)
  25. RotAngle := gta.read(0xB6F5F0, "float", 0x558)
  26. Xwping := MyPosX + 2*cos(RotAngle + 1.48353)
  27. Ywping := MyPosY + 2*sin(RotAngle + 1.48353)
  28. Zwping := MyPosZ + 0.2
  29. EnemyXpos := gta.write(0xB6F5F0, Xwping,"float", 0x79c, 0x14, 0x30)
  30. EnemyYpos := gta.write(0xB6F5F0, Ywping,"float", 0x79c, 0x14, 0x34)
  31. EnemyZpos := gta.write(0xB6F5F0, Zwping,"float", 0x79c, 0x14, 0x38)
  32. }
  33. }
  34. return
  35. class memory
  36. {
  37. static baseAddress, hProcess
  38. , insertNullTerminator := True
  39. , readChunkSize := 128
  40. , aTypeSize := {    "UChar": 1, "Char":    1
  41. , "UShort":    2, "Short":    2
  42. , "UInt": 4, "Int": 4
  43. , "UFloat": 4, "Float": 4
  44. ,    "Int64": 8, "Double": 8}
  45. __new(program, dwDesiredAccess := "", byRef handle := "", windowMatchMode := 3)
  46. {
  47. if !(handle := this.openProcess(program, dwDesiredAccess, windowMatchMode))
  48. return ""
  49. this.BaseAddress := this.getProcessBaseAddress(program, windowMatchMode)
  50. return this
  51. }
  52. __delete()
  53. {
  54. this.closeProcess(this.hProcess)
  55. return
  56. }
  57. "Starcraft II"
  58. openProcess(program, dwDesiredAccess := "", windowMatchMode := 3)
  59. {
  60. handle is fine i.e. wont cause an issue)
  61. if dwDesiredAccess is not integer
  62. dwDesiredAccess := (PROCESS_QUERY_INFORMATION := 0x0400) | (PROCESS_VM_OPERATION := 0x8) | (PROCESS_VM_READ := 0x10) |
  63. (PROCESS_VM_WRITE := 0x20)
  64. if windowMatchMode
  65. {
  66. mode := A_TitleMatchMode
  67. SetTitleMatchMode, %windowMatchMode%
  68. }
  69. WinGet, pid, pid, % this.currentProgram := program
  70. if windowMatchMode
  71. SetTitleMatchMode, %mode%
  72. if !pid
  73. return this.hProcess := 0
  74. return this.hProcess := DllCall("OpenProcess", "UInt", dwDesiredAccess, "Int", False, "UInt", pid)
  75. to open process for some reason
  76. }
  77. closeProcess(hProcess)
  78. {
  79. if hProcess
  80. return DllCall("CloseHandle", "UInt", hProcess)
  81. return
  82. }
  83. requirements.
  84. read(address, type := "UInt", aOffsets*)
  85. {
  86. VarSetCapacity(buffer, bytes := this.aTypeSize[type])
  87. if !DllCall("ReadProcessMemory","UInt", this.hProcess, "UInt", aOffsets.maxIndex() ? this.getAddressFromOffsets(address,
  88. aOffsets*) : address, "Ptr", &buffer, "UInt", bytes, "Ptr",0)
  89. return !this.hProcess ? "Handle Is closed: " this.hProcess : "Fail"
  90. return numget(buffer, 0, Type)
  91. }
  92. ReadRawMemory(address, byref buffer, bytes := 4, aOffsets*)
  93. {
  94. VarSetCapacity(buffer, bytes)
  95. if !DllCall("ReadProcessMemory", "UInt", this.hProcess, "UInt", aOffsets.maxIndex() ? this.getAddressFromOffsets(address,
  96. aOffsets*) : address, "Ptr", &buffer, "UInt", bytes, "Ptr*", bytesRead)
  97. return !this.hProcess ? "Handle Is closed: " this.hProcess : "Fail"
  98. return bytesRead
  99. }
  100. readString(address, length := 0, encoding := "utf-8", aOffsets*)
  101. {
  102. size := (encoding ="utf-16" || encoding = "cp1200") ? 2 : 1
  103. VarSetCapacity(buffer, length ? length * size : (this.readChunkSize < size ? this.readChunkSize := size :
  104. this.readChunkSize), 0)
  105. if aOffsets.maxIndex()
  106. address := this.getAddressFromOffsets(address, aOffsets*)
  107. if !length
  108. {
  109. VarSetCapacity(string, this.readChunkSize * 2)
  110. memory
  111. Loop
  112. {
  113. success := DllCall("ReadProcessMemory", "UInt", this.hProcess, "UInt", address + (A_index - 1) * this.readChunkSize,
  114. "Ptr", &buffer, "Uint", this.readChunkSize, "Ptr", 0)
  115. if (ErrorLevel || !success)
  116. {
  117. if (A_Index = 1 && !this.hProcess)
  118. return "Handle Is closed: " this.hProcess
  119. else if (A_index = 1 && this.hProcess)
  120. return "Fail"
  121. else
  122. break
  123. }
  124. loop, % this.readChunkSize / size
  125. {
  126. if ("" = char := StrGet(&buffer + (A_Index -1) * size, 1, encoding))
  127. break, 2
  128. string .= char
  129. }
  130. gets broken anyway
  131. }
  132. }
  133. Else
  134. {
  135. if !DllCall("ReadProcessMemory", "UInt", this.hProcess, "UInt", address, "Ptr", &buffer, "Uint", length * size, "Ptr", 0)
  136. return !this.hProcess ? "Handle Is closed: " this.hProcess : "Fail"
  137. string := StrGet(&buffer, length, encoding)
  138. }
  139. return string
  140. }
  141. writeString(address, string, encoding := "utf-8", aOffsets*)
  142. {
  143. encodingSize := (encoding = "utf-16" || encoding = "cp1200") ? 2 : 1
  144. requiredSize := StrPut(string, encoding) * encodingSize - (this.insertNullTerminator ? 0 : encodingSize)
  145. VarSetCapacity(buffer, requiredSize)
  146. StrPut(string, &buffer, this.insertNullTerminator ? StrLen(string) : StrLen(string) + 1, encoding)
  147. DllCall("WriteProcessMemory", "UInt", this.hProcess, "UInt", aOffsets.maxIndex() ? this.getAddressFromOffsets(address,
  148. aOffsets*) : address, "Ptr", &buffer, "Uint", requiredSize, "Ptr*", BytesWritten)
  149. return BytesWritten
  150. }
  151. write(address, value, type := "Uint", aOffsets*)
  152. {
  153. if !bytes := this.aTypeSize[type]
  154. return "Non Supported data type"
  155. VarSetCapacity(buffer, bytes)
  156. NumPut(value, buffer, 0, type)
  157. return DllCall("WriteProcessMemory", "UInt", this.hProcess, "UInt", aOffsets.maxIndex() ? this.getAddressFromOffsets
  158. (address, aOffsets*) : address, "Ptr", &buffer, "Uint", bytes, "Ptr", 0)
  159. }
  160. pointer(base, finalType := "UInt", offsets*)
  161. {
  162. For index, offset in offsets
  163. {
  164. if (index = offsets.maxIndex() && A_index = 1)
  165. pointer := offset + this.Read(base)
  166. Else
  167. {
  168. IF (A_Index = 1)
  169. pointer := this.Read(offset + this.Read(base))
  170. Else If (index = offsets.MaxIndex())
  171. pointer += offset
  172. Else pointer := this.Read(pointer + offset)
  173. }
  174. }
  175. Return this.Read(offsets.maxIndex() ? pointer : base, finalType)
  176. }
  177. getAddressFromOffsets(address, aOffsets*)
  178. {
  179. lastOffset := aOffsets.Remove()
  180. last offset)
  181. return    this.pointer(address, "UInt", aOffsets*) + lastOffset
  182. }
  183. SC2.exe),
  184. getProcessBaseAddress(WindowTitle, windowMatchMode := 3)
  185. {
  186. if windowMatchMode
  187. {
  188. mode := A_TitleMatchMode
  189. SetTitleMatchMode, %windowMatchMode%
  190. }
  191. WinGet, hWnd, ID, %WindowTitle%
  192. if windowMatchMode
  193. SetTitleMatchMode, %mode%
  194. if !hWnd
  195. return
  196. BaseAddress := DllCall(A_PtrSize = 4
  197. ? "GetWindowLong"
  198. : "GetWindowLongPtr", "Ptr", hWnd, "Uint", -6, "UInt")
  199. return BaseAddress
  200. }
  201. getBaseAddressOfModule(module := "")
  202. {
  203. if !this.hProcess
  204. return -2
  205. if (A_PtrSize = 4)
  206. {
  207. DllCall("IsWow64Process", "Ptr", this.hProcess, "Int*", result)
  208. if !result
  209. return -4
  210. }
  211. if !module
  212. {
  213. VarSetCapacity(mainExeNameBuffer, 2048 * (A_IsUnicode ? 2 : 1))
  214. DllCall("psapi\GetModuleFileNameEx", "Ptr", this.hProcess, "Uint", 0
  215. , "Ptr", &mainExeNameBuffer, "Uint", 2048 / (A_IsUnicode ? 2 : 1))
  216. mainExeName := StrGet(&mainExeNameBuffer)
  217. }
  218. size := VarSetCapacity(lphModule, 4)
  219. loop
  220. {
  221. DllCall("psapi\EnumProcessModules", "Ptr", this.hProcess, "Ptr", &lphModule
  222. , "Uint", size, "Uint*", reqSize)
  223. if ErrorLevel
  224. return -3
  225. else if (size >= reqSize)
  226. break
  227. else
  228. size := VarSetCapacity(lphModule, reqSize)
  229. }
  230. VarSetCapacity(lpFilename, 2048 * (A_IsUnicode ? 2 : 1))
  231. loop % reqSize / A_PtrSize
  232. {
  233. DllCall("psapi\GetModuleFileNameEx", "Ptr", this.hProcess, "Uint", numget(lphModule, (A_index - 1) * A_PtrSize)
  234. , "Ptr", &lpFilename, "Uint", 2048 / (A_IsUnicode ? 2 : 1))
  235. if (!module && mainExeName = StrGet(&lpFilename) || module && instr(StrGet(&lpFilename), module))
  236. {
  237. VarSetCapacity(MODULEINFO, A_PtrSize = 4 ? 12 : 24)
  238. DllCall("psapi\GetModuleInformation", "Ptr", this.hProcess, "UInt", numget(lphModule, (A_index - 1) * A_PtrSize)
  239. , "Ptr", &MODULEINFO, "UInt", A_PtrSize = 4 ? 12 : 24)
  240. return numget(MODULEINFO, 0, "Ptr")
  241. }
  242. }
  243. return -1
  244. }
  245. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement