TakePen

Untitled

Apr 6th, 2025
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
AutoIt 180.11 KB | None | 0 0
  1. ;###########################
  2. ;#  by rheek               #
  3. ;#  modified by mhaendler  #
  4. ;###########################
  5. ; v1.6, source: github.com/rheek123/GwBotApiPatcher
  6. ;
  7. ; This file contains all headers that gwa2 uses to communicate with the gameservers directly.
  8. ;
  9. ; The headers are named variables. The names should indicate what the header is about.
  10. ; The comments give a litte more detail about what the header does.
  11. ;
  12. ; This makes the source code of gwa2 a little better readable. Also it allows to update headers more easily, as they
  13. ; are all now in a small separate place as a list to work yourself through.
  14. ; If you need to update the headers, the comments give hints about what action to trigger while recording CtoGS packets.
  15.  
  16. #include-once
  17. ;=QUEST=
  18. Global Const $HEADER_QUEST_ACCEPT = 0x41    ;Accepts a quest from the NPC
  19. Global Const $HEADER_QUEST_REWARD = 0x41    ;Retrieves Quest reward from NPC
  20. Global Const $HEADER_QUEST_ABANDON = 0x12 ;Abandons the quest
  21.  
  22. ;=HERO= not touched
  23. Global Const $HEADER_HERO_AGGRESSION = 0x17 ;Sets the heroes aggression level
  24. Global Const $HEADER_HERO_LOCK = 0x18   ;Locks the heroes target
  25. Global Const $HEADER_HERO_TOGGLE_SKILL = 0x1C   ;Enables or disables the heroes skill
  26. Global Const $HEADER_HERO_CLEAR_FLAG = 0x1E ;Clears the heroes position flag
  27. Global Const $HEADER_HERO_PLACE_FLAG = 0x1E ;Sets the heroes position flag, hero runs to position
  28. Global Const $HEADER_HERO_ADD = 0x23    ;Adds hero to party
  29. Global Const $HEADER_HERO_KICK = 0x24   ;Kicks hero from party
  30. Global Const $HEADER_HEROES_KICK = 0x24 ;Kicks ALL heroes from party
  31.  
  32. ;=PARTY= not touched
  33. Global Const $HEADER_PARTY_PLACE_FLAG = 0x1F    ;Sets the party position flag, all party-npcs runs to position
  34. Global Const $HEADER_PARTY_CLEAR_FLAG = 0x1F    ;Clears the party position flag
  35. Global Const $HEADER_HENCHMAN_ADD = 0xA6    ;Adds henchman to party
  36. Global Const $HEADER_PARTY_LEAVE = 0xA9 ;Leaves the party
  37. Global Const $HEADER_HENCHMAN_KICK = 0xAD   ;Kicks a henchman from party
  38. Global Const $HEADER_INVITE_TARGET = 0xA6   ;Invite target player to party
  39. Global Const $HEADER_INVITE_CANCEL = 0xA3   ;Cancel invitation of player
  40. Global Const $HEADER_INVITE_ACCEPT = 0xA2   ;Accept invitation to party
  41.  
  42. ;=TARGET (Enemies or NPC)= not touched
  43. Global Const $HEADER_CALL_TARGET = 0x2C ;Calls the target without attacking (Ctrl+Shift+Space)
  44. Global Const $HEADER_ATTACK_AGENT = 0x2C    ;Attacks agent (Space IIRC)
  45. Global Const $HEADER_CANCEL_ACTION = 0x2E   ;Cancels the current action
  46. Global Const $HEADER_AGENT_FOLLOW = 0x39    ;Follows the agent/npc. Ctrl+Click triggers "I am following Person" in chat
  47. Global Const $HEADER_NPC_TALK = 0x3F    ;talks/goes to npc
  48. Global Const $HEADER_SIGNPOST_RUN = 0x57    ;Runs to signpost
  49.  
  50. ;=DROP=
  51. Global Const $HEADER_ITEM_DROP = 0x32   ;Drops item from inventory to ground
  52. Global Const $HEADER_GOLD_DROP = 0x35   ;Drops gold from inventory to ground
  53.  
  54. ;=BUFFS= not touched
  55. Global Const $HEADER_STOP_MAINTAIN_ENCH = 0x2F  ;Drops buff, cancel enchantmant, whatever you call it
  56.  
  57. ;=ITEMS=
  58. Global Const $HEADER_ITEM_EQUIP = 0x36  ;Equips item from inventory/chest/no idea
  59. Global Const $HEADER_ITEM_PICKUP = 0x45 ;Picks up an item from ground
  60. Global Const $HEADER_ITEM_DESTROY = 0x6F    ;Destroys the item
  61. Global Const $HEADER_ITEM_ID = 0x72 ;Identifies item in inventory
  62. Global Const $HEADER_ITEM_MOVE = 0x78   ;Moves item in inventory
  63. Global Const $HEADER_ITEMS_ACCEPT_UNCLAIMED = 0x79  ;Accepts ITEMS not picked up in missions
  64. Global Const $HEADER_ITEM_MOVE_EX = 0x7B    ;Moves an item, with amount to be moved.
  65. Global Const $HEADER_SALVAGE_MATS = 0x80    ;Salvages materials from item
  66. Global Const $HEADER_SALVAGE_MODS = 0x81    ;Salvages mods from item
  67. Global Const $HEADER_ITEM_USE = 0x84    ;Uses item from inventory/chest
  68. Global Const $HEADER_ITEM_UNEQUIP = 0x55    ;Unequip item
  69. Global Const $HEADER_UPGRADE = 0x87 ;used by gwapi. is it even useful? NOT TESTED
  70. Global Const $HEADER_UPGRADE_ARMOR_1 = 0x84 ;used by gwapi. is it even useful? NOT TESTED
  71. Global Const $HEADER_UPGRADE_ARMOR_2 = 0x87 ;used by gwapi. is it even useful? NOT TESTED
  72.  
  73. ;=TRADE= not touched
  74. Global Const $HEADER_TRADE_PLAYER = 0x4F    ;Send trade request to player
  75. Global Const $HEADER_TRADE_OFFER_ITEM = 0x02    ;Add item to trade window
  76. Global Const $HEADER_TRADE_SUBMIT_OFFER = 0x03  ;Submit offer
  77. Global Const $HEADER_TRADE_CHANGE_OFFER = 0x06  ;Change offer
  78. Global Const $HEADER_TRADE_CANCEL = 0x01    ;Cancel trade
  79. Global Const $HEADER_TRADE_ACCEPT = 0x07    ;Accept trade
  80.  
  81. ;=TRAVEL=
  82. Global Const $HEADER_MAP_TRAVEL = 0xB8  ;Travels to outpost via worldmap
  83. Global Const $HEADER_GUILDHALL_TRAVEL = 0xB7    ;Travels to guild hall
  84. Global Const $HEADER_GUILDHALL_LEAVE = 0xB9 ;Leaves Guildhall
  85.  
  86. ;=FACTION= not touched
  87. Global Const $HEADER_FACTION_DONATE = 0x3B  ;Donates kurzick/luxon faction to ally
  88.  
  89. ;=TITLE=
  90. Global Const $HEADER_TITLE_DISPLAY = 0x5E   ;Displays title (from Gigis Vaettir Bot)
  91. Global Const $HEADER_TITLE_CLEAR = 0x5F ;Hides title (from Gigis Vaettir Bot)
  92.  
  93. ;=DIALOG= Not touched
  94. Global Const $HEADER_DIALOG = 0x41  ;Sends a dialog to NPC
  95. Global Const $HEADER_CINEMATIC_SKIP = 0x69  ;Skips the cinematic
  96.  
  97. ;=SKILL / BUILD=
  98. Global Const $HEADER_SKILL_CHANGE = 0x62    ;Changes a skill on the skillbar
  99. Global Const $HEADER_BUILD_LOAD = 0x63  ;Loads a complete build
  100. Global Const $HEADER_CHANGE_SECONDARY = 0x47    ;Changes Secondary class (from Build window, not class changer)
  101. ;= Not touched
  102. Global Const $HEADER_SKILL_USE_ALLY = 0x4C  ;used by gwapi. appears to have changed
  103. Global Const $HEADER_SKILL_USE_FOE = 0x4C   ;used by gwapi. appears to have changed
  104. Global Const $HEADER_SKILL_USE_ID = 0x4C    ;
  105. Global Const $HEADER_SET_ATTRIBUTES = 0x10  ;hidden in init stuff like sendchat
  106.  
  107. ;=CHEST= not touched
  108. Global Const $HEADER_CHEST_OPEN = 0x59  ;Opens a chest (with key AFAIK)
  109.  
  110. Global Const $HEADER_GOLD_MOVE = 0x82   ;Moves Gold (from chest to inventory, and otherway around IIRC)
  111.  
  112. ;=MISSION=
  113. Global Const $HEADER_MODE_SWITCH = 0xA2 ;Toggles hard- and normal mode
  114. Global Const $HEADER_MISSION_ENTER = 0xAC   ;Enter a mission/challenge
  115. Global Const $HEADER_MISSION_FOREIGN_ENTER = 0xAC   ;Enters a foreign mission/challenge (no idea honestly)
  116. Global Const $HEADER_OUTPOST_RETURN = 0xAE  ;Returns to outpost after /resign
  117.  
  118. ;=CHAT=
  119. Global Const $HEADER_SEND_CHAT = 0x6A   ;Needed for sending messages in chat
  120.  
  121. ;=OTHER CONSTANTS=
  122. Global Const $HEADER_MAX_ATTRIBUTES_CONST_5 = 0x04  ;constant at word 5 of max attrib packet. Changed from 3 to four in most recent update
  123. Global Const $HEADER_MAX_ATTRIBUTES_CONST_22    = 0x04  ;constant at word 22 of max attrib packet. Changed from 3 to four in most recent update
  124.  
  125.  
  126.  
  127. ; Version 3.7.11
  128. ; After the Update from 2019/05/01
  129.  
  130. #include-once
  131. #RequireAdmin
  132. #include "GWA2_Headers.au3"
  133.  
  134. If @AutoItX64 Then
  135.     MsgBox(16, "Error!", "Please run all bots in 32-bit (x86) mode.")
  136.     Exit
  137. EndIf
  138.  
  139. #Region Declarations
  140. Local $Rendering = True
  141. Local $mGWA2Version = '3.7.11'
  142. Local $mKernelHandle
  143. Local $mGWProcHandle
  144. Local $mGWProcessId
  145. Local $mGWWindowHandle
  146. Local $mMemory
  147. Local $mLabels[1][2]
  148. Local $mBase = 0x00DE0000
  149. Local $mASMString
  150. Local $mASMSize
  151. Local $mASMCodeOffset
  152. Local $mGUI = GUICreate('GWA2')
  153. Local $mSkillActivate
  154. Local $mSkillCancel
  155. Local $mSkillComplete
  156. Local $mChatReceive
  157. Local $mLoadFinished
  158. Local $mSkillLogStruct = DllStructCreate('dword;dword;dword;float')
  159. Local $mSkillLogStructPtr = DllStructGetPtr($mSkillLogStruct)
  160. Local $mChatLogStruct = DllStructCreate('dword;wchar[256]')
  161. Local $mChatLogStructPtr = DllStructGetPtr($mChatLogStruct)
  162. GUIRegisterMsg(0x501, 'Event')
  163. Local $mCharname
  164. Local $mBasePointer
  165. Local $mAgentBase
  166. Local $mMaxAgents
  167. Local $mMyID
  168. Local $mMapLoading
  169. Local $mCurrentTarget
  170. Local $mPing
  171. Local $mMapID
  172. Local $mLoggedIn
  173. Local $mRegion
  174. Local $mLanguage
  175. Local $mSkillBase
  176. Local $mSkillTimer
  177. Local $mBuildNumber
  178. Local $mZoomStill
  179. Local $mZoomMoving
  180. Local $mCurrentStatus
  181. Local $mQueueCounter
  182. Local $mQueueSize
  183. Local $mQueueBase
  184. Local $mTargetLogBase
  185. Local $mStringLogBase
  186. Local $mMapIsLoaded
  187. Local $mEnsureEnglish
  188. Local $mTraderQuoteID
  189. Local $mTraderCostID
  190. Local $mTraderCostValue
  191. Local $mDisableRendering
  192. Local $mAgentCopyCount
  193. Local $mAgentCopyBase
  194. Local $mCharslots
  195. #EndRegion Declarations
  196.  
  197. #Region CommandStructs
  198. Local $mUseSkill = DllStructCreate('ptr;dword;dword;dword')
  199. Local $mUseSkillPtr = DllStructGetPtr($mUseSkill)
  200.  
  201. Local $mMove = DllStructCreate('ptr;float;float;float')
  202. Local $mMovePtr = DllStructGetPtr($mMove)
  203.  
  204. Local $mChangeTarget = DllStructCreate('ptr;dword')
  205. Local $mChangeTargetPtr = DllStructGetPtr($mChangeTarget)
  206.  
  207. Local $mPacket = DllStructCreate('ptr;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword')
  208. Local $mPacketPtr = DllStructGetPtr($mPacket)
  209.  
  210. Local $mSellItem = DllStructCreate('ptr;dword;dword')
  211. Local $mSellItemPtr = DllStructGetPtr($mSellItem)
  212.  
  213. Local $mAction = DllStructCreate('ptr;dword;dword')
  214. Local $mActionPtr = DllStructGetPtr($mAction)
  215.  
  216. Local $mToggleLanguage = DllStructCreate('ptr;dword')
  217. Local $mToggleLanguagePtr = DllStructGetPtr($mToggleLanguage)
  218.  
  219. Local $mUseHeroSkill = DllStructCreate('ptr;dword;dword;dword')
  220. Local $mUseHeroSkillPtr = DllStructGetPtr($mUseHeroSkill)
  221.  
  222. Local $mBuyItem = DllStructCreate('ptr;dword;dword;dword')
  223. Local $mBuyItemPtr = DllStructGetPtr($mBuyItem)
  224.  
  225. Local $mSendChat = DllStructCreate('ptr;dword')
  226. Local $mSendChatPtr = DllStructGetPtr($mSendChat)
  227.  
  228. Local $mWriteChat = DllStructCreate('ptr')
  229. Local $mWriteChatPtr = DllStructGetPtr($mWriteChat)
  230.  
  231. Local $mRequestQuote = DllStructCreate('ptr;dword')
  232. Local $mRequestQuotePtr = DllStructGetPtr($mRequestQuote)
  233.  
  234. Local $mRequestQuoteSell = DllStructCreate('ptr;dword')
  235. Local $mRequestQuoteSellPtr = DllStructGetPtr($mRequestQuoteSell)
  236.  
  237. Local $mTraderBuy = DllStructCreate('ptr')
  238. Local $mTraderBuyPtr = DllStructGetPtr($mTraderBuy)
  239.  
  240. Local $mTraderSell = DllStructCreate('ptr')
  241. Local $mTraderSellPtr = DllStructGetPtr($mTraderSell)
  242.  
  243. Local $mSalvage = DllStructCreate('ptr;dword;dword;dword')
  244. Local $mSalvagePtr = DllStructGetPtr($mSalvage)
  245.  
  246. Local $mSetAttributes = DllStructCreate("ptr;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword;dword")
  247. Local $mSetAttributesPtr = DllStructGetPtr($mSetAttributes)
  248.  
  249. Local $mMakeAgentArray = DllStructCreate('ptr;dword')
  250. Local $mMakeAgentArrayPtr = DllStructGetPtr($mMakeAgentArray)
  251.  
  252. Local $mChangeStatus = DllStructCreate('ptr;dword')
  253. Local $mChangeStatusPtr = DllStructGetPtr($mChangeStatus)
  254. #EndRegion CommandStructs
  255.  
  256. #Region Headers
  257. $SalvageMaterialsHeader = 0x80
  258. $SalvageModHeader = 0x81
  259. $IdentifyItemHeader = 0x72
  260. $EquipItemHeader = 0x36
  261. $UseItemHeader = 0x84
  262. $PickUpItemHeader = 0x45
  263. $DropItemHeader = 0x32
  264. $MoveItemHeader = 0x78
  265. $AcceptAllItemsHeader = 0x79
  266. $DropGoldHeader = 0x35
  267. $ChangeGoldHeader = 0x82
  268. $AddHeroHeader = 0x23
  269. $KickHeroHeader = 0x24
  270. $AddNpcHeader = 0xA5
  271. $KickNpcHeader = 0xAD
  272. $CommandHeroHeader = 0x1E
  273. $CommandAllHeader = 0x1F
  274. $LockHeroTargetHeader = 0x18
  275. $SetHeroAggressionHeader = 0x17
  276. $ChangeHeroSkillSlotStateHeader = 0x1C
  277. $SetDisplayedTitleHeader = 0x5E
  278. $RemoveDisplayedTitleHeader = 0x5F
  279. $GoPlayerHeader = 0x39
  280. $GoNPCHeader = 0x3F
  281. $GoSignpostHeader = 0x57
  282. $AttackHeader = 0x2C
  283. $MoveMapHeader = 0xB8
  284. $ReturnToOutpostHeader = 0xAE
  285. $EnterChallengeHeader = 0xAC
  286. $TravelGHHeader = 0xB7
  287. $LeaveGHHeader = 0xB9
  288. $AbandonQuestHeader = 0x12
  289. $CallTargetHeader = 0x2C
  290. $CancelActionHeader = 0x2E
  291. $OpenChestHeader = 0x59
  292. $DropBuffHeader = 0x2F
  293. $LeavePartyHeader = 0xA8
  294. $SwitchModeHeader = 0xA2
  295. $DonateFactionHeader = 0x3B
  296. $DialogHeader = 0x41
  297. $SkipCinematicHeader = 0x68
  298. $SetSkillbarSkillHeader = 0x62
  299. $LoadSkillbarHeader = 0x63
  300. $ChangeSecondProfessionHeader = 0x47
  301. $SendChatHeader = 0x6A
  302. $SetAttributesHeader = 0x10
  303. #EndRegion Headers
  304.  
  305. #Region Memory
  306. ;~ Description: Internal use only.
  307. Func MemoryOpen($aPID)
  308.     $mKernelHandle = DllOpen('kernel32.dll')
  309.     Local $lOpenProcess = DllCall($mKernelHandle, 'int', 'OpenProcess', 'int', 0x1F0FFF, 'int', 1, 'int', $aPID)
  310.     $mGWProcHandle = $lOpenProcess[0]
  311. EndFunc   ;==>MemoryOpen
  312.  
  313. ;~ Description: Internal use only.
  314. Func MemoryClose()
  315.     DllCall($mKernelHandle, 'int', 'CloseHandle', 'int', $mGWProcHandle)
  316.     DllClose($mKernelHandle)
  317. EndFunc   ;==>MemoryClose
  318.  
  319. ;~ Description: Internal use only.
  320. Func WriteBinary($aBinaryString, $aAddress)
  321.     Local $lData = DllStructCreate('byte[' & 0.5 * StringLen($aBinaryString) & ']'), $i
  322.     For $i = 1 To DllStructGetSize($lData)
  323.         DllStructSetData($lData, 1, Dec(StringMid($aBinaryString, 2 * $i - 1, 2)), $i)
  324.     Next
  325.     DllCall($mKernelHandle, 'int', 'WriteProcessMemory', 'int', $mGWProcHandle, 'ptr', $aAddress, 'ptr', DllStructGetPtr($lData), 'int', DllStructGetSize($lData), 'int', 0)
  326. EndFunc   ;==>WriteBinary
  327.  
  328. ;~ Description: Internal use only.
  329. Func MemoryWrite($aAddress, $aData, $aType = 'dword')
  330.     Local $lBuffer = DllStructCreate($aType)
  331.     DllStructSetData($lBuffer, 1, $aData)
  332.     DllCall($mKernelHandle, 'int', 'WriteProcessMemory', 'int', $mGWProcHandle, 'int', $aAddress, 'ptr', DllStructGetPtr($lBuffer), 'int', DllStructGetSize($lBuffer), 'int', '')
  333. EndFunc   ;==>MemoryWrite
  334.  
  335. ;~ Description: Internal use only.
  336. Func MemoryRead($aAddress, $aType = 'dword')
  337.     Local $lBuffer = DllStructCreate($aType)
  338.     DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $aAddress, 'ptr', DllStructGetPtr($lBuffer), 'int', DllStructGetSize($lBuffer), 'int', '')
  339.     Return DllStructGetData($lBuffer, 1)
  340. EndFunc   ;==>MemoryRead
  341.  
  342. ;~ Description: Internal use only.
  343. Func MemoryReadPtr($aAddress, $aOffset, $aType = 'dword')
  344.     Local $lPointerCount = UBound($aOffset) - 2
  345.     Local $lBuffer = DllStructCreate('dword')
  346.  
  347.     For $i = 0 To $lPointerCount
  348.         $aAddress += $aOffset[$i]
  349.         DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $aAddress, 'ptr', DllStructGetPtr($lBuffer), 'int', DllStructGetSize($lBuffer), 'int', '')
  350.         $aAddress = DllStructGetData($lBuffer, 1)
  351.         If $aAddress == 0 Then
  352.             Local $lData[2] = [0, 0]
  353.             Return $lData
  354.         EndIf
  355.     Next
  356.  
  357.     $aAddress += $aOffset[$lPointerCount + 1]
  358.     $lBuffer = DllStructCreate($aType)
  359.     DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $aAddress, 'ptr', DllStructGetPtr($lBuffer), 'int', DllStructGetSize($lBuffer), 'int', '')
  360.     Local $lData[2] = [$aAddress, DllStructGetData($lBuffer, 1)]
  361.     Return $lData
  362. EndFunc   ;==>MemoryReadPtr
  363.  
  364. ;~ Description: Internal use only.
  365. Func SwapEndian($aHex)
  366.     Return StringMid($aHex, 7, 2) & StringMid($aHex, 5, 2) & StringMid($aHex, 3, 2) & StringMid($aHex, 1, 2)
  367. EndFunc   ;==>SwapEndian
  368. #EndRegion Memory
  369.  
  370. #Region Initialisation
  371. ;~ Description: Returns a list of logged characters
  372. Func GetLoggedCharNames()
  373.     Local $array = ScanGW()
  374.     If $array[0] <= 0 Then Return ''
  375.     Local $ret = $array[1]
  376.     For $i=2 To $array[0]
  377.         $ret &= "|"
  378.         $ret &= $array[$i]
  379.     Next
  380.     Return $ret
  381. EndFunc
  382.  
  383. ;~ Description: Returns an array of logged characters of gw windows (at pos 0 there is the size of the array)
  384. Func ScanGW()
  385.     Local $lProcessList = processList("gw.exe")
  386.     Local $lReturnArray[1] = [0]
  387.     Local $lPid
  388.  
  389.     For $i = 1 To $lProcessList[0][0]
  390.         MemoryOpen($lProcessList[$i][1])
  391.  
  392.         If $mGWProcHandle Then
  393.             $lReturnArray[0] += 1
  394.             ReDim $lReturnArray[$lReturnArray[0] + 1]
  395.             $lReturnArray[$lReturnArray[0]] = ScanForCharname()
  396.         EndIf
  397.  
  398.         MemoryClose()
  399.  
  400.         $mGWProcHandle = 0
  401.     Next
  402.  
  403.     Return $lReturnArray
  404. EndFunc
  405.  
  406. Func GetHwnd($aProc)
  407.     Local $wins = WinList()
  408.     For $i = 1 To UBound($wins)-1
  409.         If (WinGetProcess($wins[$i][1]) == $aProc) And (BitAND(WinGetState($wins[$i][1]), 2)) Then Return $wins[$i][1]
  410.     Next
  411. EndFunc
  412.  
  413. ;~ Description: Injects GWA² into the game client. 3rd and 4th arguments are here for legacy purposes
  414. Func Initialize($aGW, $bChangeTitle = True, $notUsed1 = 0, $notUsed2 = 0)
  415.     If IsString($aGW) Then
  416.         Local $lProcessList = processList("gw.exe")
  417.         For $i = 1 To $lProcessList[0][0]
  418.             $mGWProcessId = $lProcessList[$i][1]
  419.             $mGWWindowHandle = GetHwnd($mGWProcessId)
  420.             MemoryOpen($mGWProcessId)
  421.             If $mGWProcHandle Then
  422.                 If StringRegExp(ScanForCharname(), $aGW) = 1 Then ExitLoop
  423.             EndIf
  424.             MemoryClose()
  425.             $mGWProcHandle = 0
  426.         Next
  427.     Else
  428.         $mGWProcessId = $aGW
  429.         $mGWWindowHandle = GetHwnd($mGWProcessId)
  430.         MemoryOpen($aGW)
  431.         ScanForCharname()
  432.     EndIf
  433.  
  434.     If $mGWProcHandle = 0 Then Return False
  435.  
  436.     Scan()
  437.  
  438.     $mBasePointer = MemoryRead(GetScannedAddress('ScanBasePointer', -3))
  439.     SetValue('BasePointer', '0x' & Hex($mBasePointer, 8))
  440.     $mAgentBase = MemoryRead(GetScannedAddress('ScanAgentBase', 13))
  441.     SetValue('AgentBase', '0x' & Hex($mAgentBase, 8))
  442.     $mMaxAgents = $mAgentBase + 8
  443.     SetValue('MaxAgents', '0x' & Hex($mMaxAgents, 8))
  444.     $mMyID = $mAgentBase - 84
  445.     SetValue('MyID', '0x' & Hex($mMyID, 8))
  446.     $mMapLoading = $mAgentBase - 240
  447.     $mCurrentTarget = $mAgentBase - 1280
  448.     SetValue('PacketLocation', '0x' & Hex(MemoryRead(GetScannedAddress('ScanBaseOffset', -3)), 8))
  449.     $mPing = MemoryRead(GetScannedAddress('ScanPing', -8))
  450.     $mMapID = MemoryRead(GetScannedAddress('ScanMapID', 71))
  451.     $mLoggedIn = MemoryRead(GetScannedAddress('ScanLoggedIn', -3)) + 4
  452.     $mRegion = MemoryRead(GetScannedAddress('ScanRegion', 8))
  453.     $mLanguage = MemoryRead(GetScannedAddress('ScanLanguage', 8)) + 12
  454.     $mSkillBase = MemoryRead(GetScannedAddress('ScanSkillBase', 9))
  455.     $mSkillTimer = MemoryRead(GetScannedAddress('ScanSkillTimer', -3))
  456.     $mBuildNumber = MemoryRead(GetScannedAddress('ScanBuildNumber', 0x54))
  457.     $mZoomStill = GetScannedAddress("ScanZoomStill", -1)
  458.     $mZoomMoving = GetScannedAddress("ScanZoomMoving", 5)
  459.     $mCurrentStatus = MemoryRead(GetScannedAddress('ScanChangeStatusFunction', -3))
  460.     $mCharslots = MemoryRead(GetScannedAddress('ScanCharslots', 22))
  461.  
  462.     Local $lTemp
  463.     $lTemp = GetScannedAddress('ScanEngine', -16)
  464.     SetValue('MainStart', '0x' & Hex($lTemp, 8))
  465.     SetValue('MainReturn', '0x' & Hex($lTemp + 5, 8))
  466.     SetValue('RenderingMod', '0x' & Hex($lTemp + 116, 8))
  467.     SetValue('RenderingModReturn', '0x' & Hex($lTemp + 138, 8))
  468.     $lTemp = GetScannedAddress('ScanTargetLog', 1)
  469.     SetValue('TargetLogStart', '0x' & Hex($lTemp, 8))
  470.     SetValue('TargetLogReturn', '0x' & Hex($lTemp + 5, 8))
  471.     $lTemp = GetScannedAddress('ScanSkillLog', 1)
  472.     SetValue('SkillLogStart', '0x' & Hex($lTemp, 8))
  473.     SetValue('SkillLogReturn', '0x' & Hex($lTemp + 5, 8))
  474.     $lTemp = GetScannedAddress('ScanSkillCompleteLog', -4)
  475.     SetValue('SkillCompleteLogStart', '0x' & Hex($lTemp, 8))
  476.     SetValue('SkillCompleteLogReturn', '0x' & Hex($lTemp + 5, 8))
  477.     $lTemp = GetScannedAddress('ScanSkillCancelLog', 5)
  478.     SetValue('SkillCancelLogStart', '0x' & Hex($lTemp, 8))
  479.     SetValue('SkillCancelLogReturn', '0x' & Hex($lTemp + 6, 8))
  480.     $lTemp = GetScannedAddress('ScanChatLog', 18)
  481.     SetValue('ChatLogStart', '0x' & Hex($lTemp, 8))
  482.     SetValue('ChatLogReturn', '0x' & Hex($lTemp + 6, 8))
  483.     $lTemp = GetScannedAddress('ScanTraderHook', -7)
  484.     SetValue('TraderHookStart', '0x' & Hex($lTemp, 8))
  485.     SetValue('TraderHookReturn', '0x' & Hex($lTemp + 5, 8))
  486.     $lTemp = GetScannedAddress('ScanStringFilter1', -2)
  487.     SetValue('StringFilter1Start', '0x' & Hex($lTemp, 8))
  488.     SetValue('StringFilter1Return', '0x' & Hex($lTemp + 5, 8))
  489.     $lTemp = GetScannedAddress('ScanStringFilter2', -2)
  490.     SetValue('StringFilter2Start', '0x' & Hex($lTemp, 8))
  491.     SetValue('StringFilter2Return', '0x' & Hex($lTemp + 5, 8))
  492.     SetValue('StringLogStart', '0x' & Hex(GetScannedAddress('ScanStringLog', 35), 8))
  493.     SetValue('LoadFinishedStart', '0x' & Hex(GetScannedAddress('ScanLoadFinished', 79), 8))
  494.     SetValue('PostMessage', '0x' & Hex(MemoryRead(GetScannedAddress('ScanPostMessage', 11)), 8))
  495.     SetValue('Sleep', MemoryRead(MemoryRead(GetValue('ScanSleep') + 8) + 3))
  496.     SetValue('SalvageFunction', MemoryRead(GetValue('ScanSalvageFunction') + 8) - 18)
  497.     SetValue('SalvageGlobal', MemoryRead(MemoryRead(GetValue('ScanSalvageGlobal') + 8) + 1))
  498.     SetValue('MoveFunction', '0x' & Hex(GetScannedAddress('ScanMoveFunction', 1), 8))
  499.     SetValue('UseSkillFunction', '0x' & Hex(GetScannedAddress('ScanUseSkillFunction', 1), 8))
  500.     SetValue('ChangeTargetFunction', '0x' & Hex(GetScannedAddress('ScanChangeTargetFunction', -0x78), 8))
  501.     SetValue('WriteChatFunction', '0x' & Hex(GetScannedAddress('ScanWriteChatFunction', 1), 8))
  502.     SetValue('SellItemFunction', '0x' & Hex(GetScannedAddress('ScanSellItemFunction', -85), 8))
  503.     SetValue('PacketSendFunction', '0x' & Hex(GetScannedAddress('ScanPacketSendFunction', 1), 8))
  504.     SetValue('ActionBase', '0x' & Hex(MemoryRead(GetScannedAddress('ScanActionBase', -9)), 8))
  505.     SetValue('ActionFunction', '0x' & Hex(GetScannedAddress('ScanActionFunction', -5), 8))
  506.     SetValue('UseHeroSkillFunction', '0x' & Hex(GetScannedAddress('ScanUseHeroSkillFunction', -0xA1), 8))
  507.     SetValue('BuyItemFunction', '0x' & Hex(GetScannedAddress('ScanBuyItemFunction', 1), 8))
  508.     SetValue('RequestQuoteFunction', '0x' & Hex(GetScannedAddress('ScanRequestQuoteFunction', -2), 8))
  509.     SetValue('TraderFunction', '0x' & Hex(GetScannedAddress('ScanTraderFunction', -71), 8))
  510.     SetValue('ClickToMoveFix', '0x' & Hex(GetScannedAddress("ScanClickToMoveFix", 1), 8))
  511.     SetValue('ChangeStatusFunction', '0x' & Hex(GetScannedAddress("ScanChangeStatusFunction", 12), 8))
  512.  
  513.     SetValue('QueueSize', '0x00000010')
  514.     SetValue('SkillLogSize', '0x00000010')
  515.     SetValue('ChatLogSize', '0x00000010')
  516.     SetValue('TargetLogSize', '0x00000200')
  517.     SetValue('StringLogSize', '0x00000200')
  518.     SetValue('CallbackEvent', '0x00000501')
  519.  
  520.     ModifyMemory()
  521.  
  522.     $mQueueCounter = MemoryRead(GetValue('QueueCounter'))
  523.     $mQueueSize = GetValue('QueueSize') - 1
  524.     $mQueueBase = GetValue('QueueBase')
  525.     $mTargetLogBase = GetValue('TargetLogBase')
  526.     $mStringLogBase = GetValue('StringLogBase')
  527.     $mMapIsLoaded = GetValue('MapIsLoaded')
  528.     $mEnsureEnglish = GetValue('EnsureEnglish')
  529.     $mTraderQuoteID = GetValue('TraderQuoteID')
  530.     $mTraderCostID = GetValue('TraderCostID')
  531.     $mTraderCostValue = GetValue('TraderCostValue')
  532.     $mDisableRendering = GetValue('DisableRendering')
  533.     $mAgentCopyCount = GetValue('AgentCopyCount')
  534.     $mAgentCopyBase = GetValue('AgentCopyBase')
  535.  
  536.     ;EventSystem
  537.     MemoryWrite(GetValue('CallbackHandle'), $mGUI)
  538.  
  539.     DllStructSetData($mUseSkill, 1, GetValue('CommandUseSkill'))
  540.     DllStructSetData($mMove, 1, GetValue('CommandMove'))
  541.     DllStructSetData($mChangeTarget, 1, GetValue('CommandChangeTarget'))
  542.     DllStructSetData($mPacket, 1, GetValue('CommandPacketSend'))
  543.     DllStructSetData($mSellItem, 1, GetValue('CommandSellItem'))
  544.     DllStructSetData($mAction, 1, GetValue('CommandAction'))
  545.     DllStructSetData($mToggleLanguage, 1, GetValue('CommandToggleLanguage'))
  546.     DllStructSetData($mUseHeroSkill, 1, GetValue('CommandUseHeroSkill'))
  547.     DllStructSetData($mBuyItem, 1, GetValue('CommandBuyItem'))
  548.     DllStructSetData($mSendChat, 1, GetValue('CommandSendChat'))
  549.     DllStructSetData($mSendChat, 2, $HEADER_SEND_CHAT)
  550.     DllStructSetData($mWriteChat, 1, GetValue('CommandWriteChat'))
  551.     DllStructSetData($mRequestQuote, 1, GetValue('CommandRequestQuote'))
  552.     DllStructSetData($mRequestQuoteSell, 1, GetValue('CommandRequestQuoteSell'))
  553.     DllStructSetData($mTraderBuy, 1, GetValue('CommandTraderBuy'))
  554.     DllStructSetData($mTraderSell, 1, GetValue('CommandTraderSell'))
  555.     DllStructSetData($mSalvage, 1, GetValue('CommandSalvage'))
  556.     DllStructSetData($mSetAttributes, 1, GetValue('CommandPacketSend'))
  557.     DllStructSetData($mSetAttributes, 2, 0x90)
  558.     DllStructSetData($mSetAttributes, 3, $HEADER_SET_ATTRIBUTES)
  559.     DllStructSetData($mMakeAgentArray, 1, GetValue('CommandMakeAgentArray'))
  560.     DllStructSetData($mChangeStatus, 1, GetValue('CommandChangeStatus'))
  561.  
  562.     If $bChangeTitle Then WinSetTitle($mGWWindowHandle, '', 'Guild Wars - ' & GetCharname())
  563.     Return $mGWWindowHandle
  564. EndFunc   ;==>Initialize
  565.  
  566. ;~ Description: Internal use only.
  567. Func GetValue($aKey)
  568.     For $i = 1 To $mLabels[0][0]
  569.         If $mLabels[$i][0] = $aKey Then Return Number($mLabels[$i][1])
  570.     Next
  571.     Return -1
  572. EndFunc   ;==>GetValue
  573.  
  574. ;~ Description: Internal use only.
  575. Func SetValue($aKey, $aValue)
  576.     $mLabels[0][0] += 1
  577.     ReDim $mLabels[$mLabels[0][0] + 1][2]
  578.     $mLabels[$mLabels[0][0]][0] = $aKey
  579.     $mLabels[$mLabels[0][0]][1] = $aValue
  580. EndFunc   ;==>SetValue
  581.  
  582. ;~ Description: Internal use only.
  583. Func Scan()
  584.     $mASMSize = 0
  585.     $mASMCodeOffset = 0
  586.     $mASMString = ''
  587.  
  588.     _('MainModPtr/4')
  589.     _('ScanBasePointer:')
  590.     AddPattern('85C0750F8BCE')
  591.     _('ScanAgentBase:')
  592.     AddPattern('568BF13BF07204')
  593.     _('ScanEngine:')
  594.     AddPattern('5356DFE0F6C441')
  595.     _('ScanLoadFinished:')
  596.     AddPattern('894DD88B4D0C8955DC8B')
  597.     _('ScanPostMessage:')
  598.     AddPattern('6A00680080000051FF15')
  599.     _('ScanTargetLog:')
  600.     AddPattern('5356578BFA894DF4E8')
  601.     _('ScanChangeTargetFunction:')
  602.     AddPattern('33C03BDA0F95C033')
  603.     _('ScanMoveFunction:')
  604.     AddPattern('558BEC83EC2056578BF98D4DF0')
  605.     _('ScanPing:')
  606.     AddPattern('C390908BD1B9')
  607.     _('ScanMapID:')
  608.     AddPattern('B07F8D55')
  609.     _('ScanLoggedIn:')
  610.     AddPattern('85C07411B807')
  611.     _('ScanRegion:')
  612.     AddPattern('83F9FD7406')
  613.     _('ScanLanguage:')
  614.     AddPattern('C38B75FC8B04B5')
  615.     _('ScanUseSkillFunction:')
  616.     AddPattern('558BEC83EC1053568BD9578BF2895DF0')
  617.     _('ScanChangeTargetFunction:')
  618.     AddPattern('33C03BDA0F95C033')
  619.     _('ScanPacketSendFunction:')
  620.     AddPattern('558BEC83EC2C5356578BF985')
  621.     _('ScanBaseOffset:')
  622.     AddPattern('5633F63BCE740E5633D2')
  623.     _('ScanWriteChatFunction:')
  624.     AddPattern('558BEC5153894DFC8B4D0856578B')
  625.     _('ScanSkillLog:')
  626.     AddPattern('408946105E5B5D')
  627.     _('ScanSkillCompleteLog:')
  628.     AddPattern('741D6A006A40')
  629.     _('ScanSkillCancelLog:')
  630.     AddPattern('85C0741D6A006A42')
  631.     _('ScanChatLog:')
  632.     AddPattern('8B45F48B138B4DEC50')
  633.     _('ScanSellItemFunction:')
  634.     AddPattern('8B4D2085C90F858E')
  635.     _('ScanStringLog:')
  636.     AddPattern('893E8B7D10895E04397E08')
  637.     _('ScanStringFilter1:')
  638.     AddPattern('51568B7508578BF9833E00')
  639.     _('ScanStringFilter2:')
  640.     AddPattern('515356578BF933D28B4F2C')
  641.     _('ScanActionFunction:')
  642.     AddPattern('8B7D0883FF098BF175116876010000')
  643.     _('ScanActionBase:')
  644.     AddPattern('8B4208A80175418B4A08')
  645.     _('ScanSkillBase:')
  646.     AddPattern('8D04B65EC1E00505')
  647.     _('ScanUseHeroSkillFunction:')
  648.     AddPattern('8D0C765F5E8B')
  649.     _('ScanBuyItemFunction:')
  650.     AddPattern('558BEC81ECC000000053568B75085783FE108BFA8BD97614')
  651.     _('ScanRequestQuoteFunction:')
  652.     AddPattern('81EC9C00000053568B')
  653.     _('ScanTraderFunction:')
  654.     AddPattern('8B45188B551085')
  655.     _('ScanTraderHook:')
  656.     AddPattern('8955FC6A008D55F8B9BA')
  657.     _('ScanSleep:')
  658.     AddPattern('5F5E5B741A6860EA0000')
  659.     _('ScanSalvageFunction:')
  660.     AddPattern('8BFA8BD9897DF0895DF4')
  661.     _('ScanSalvageGlobal:')
  662.     AddPattern('8B018B4904A3')
  663.     _('ScanSkillTimer:')
  664.     AddPattern('85c974158bd62bd183fa64')
  665.     _('ScanClickToMoveFix:')
  666.     AddPattern('3DD301000074')
  667.     _('ScanZoomStill:')
  668.     AddPattern('3B448BCB')
  669.     _('ScanZoomMoving:')
  670.     AddPattern('50EB116800803B448BCE')
  671.     _('ScanBuildNumber:')
  672.     AddPattern('8D8500FCFFFF8D')
  673.     _('ScanChangeStatusFunction:')
  674.     AddPattern('C390909090909090909090568BF183FE04')
  675.     _('ScanCharslots:')
  676.     AddPattern('8B551041897E38897E3C897E34897E48897E4C890D')
  677.  
  678.     _('ScanProc:')
  679.     _('pushad')
  680.     _('mov ecx,401000')
  681.     _('mov esi,ScanProc')
  682.     _('ScanLoop:')
  683.     _('inc ecx')
  684.     _('mov al,byte[ecx]')
  685.     _('mov edx,ScanBasePointer')
  686.  
  687.     _('ScanInnerLoop:')
  688.     _('mov ebx,dword[edx]')
  689.     _('cmp ebx,-1')
  690.     _('jnz ScanContinue')
  691.     _('add edx,50')
  692.     _('cmp edx,esi')
  693.     _('jnz ScanInnerLoop')
  694.     _('cmp ecx,900000')
  695.     _('jnz ScanLoop')
  696.     _('jmp ScanExit')
  697.  
  698.     _('ScanContinue:')
  699.     _('lea edi,dword[edx+ebx]')
  700.     _('add edi,C')
  701.     _('mov ah,byte[edi]')
  702.     _('cmp al,ah')
  703.     _('jz ScanMatched')
  704.     _('mov dword[edx],0')
  705.     _('add edx,50')
  706.     _('cmp edx,esi')
  707.     _('jnz ScanInnerLoop')
  708.     _('cmp ecx,900000')
  709.     _('jnz ScanLoop')
  710.     _('jmp ScanExit')
  711.  
  712.     _('ScanMatched:')
  713.     _('inc ebx')
  714.     _('mov edi,dword[edx+4]')
  715.     _('cmp ebx,edi')
  716.     _('jz ScanFound')
  717.     _('mov dword[edx],ebx')
  718.     _('add edx,50')
  719.     _('cmp edx,esi')
  720.     _('jnz ScanInnerLoop')
  721.     _('cmp ecx,900000')
  722.     _('jnz ScanLoop')
  723.     _('jmp ScanExit')
  724.  
  725.     _('ScanFound:')
  726.     _('lea edi,dword[edx+8]')
  727.     _('mov dword[edi],ecx')
  728.     _('mov dword[edx],-1')
  729.     _('add edx,50')
  730.     _('cmp edx,esi')
  731.     _('jnz ScanInnerLoop')
  732.     _('cmp ecx,900000')
  733.     _('jnz ScanLoop')
  734.  
  735.     _('ScanExit:')
  736.     _('popad')
  737.     _('retn')
  738.  
  739.     Local $lScanMemory = MemoryRead($mBase, 'ptr')
  740.  
  741.     If $lScanMemory = 0 Then
  742.         $mMemory = DllCall($mKernelHandle, 'ptr', 'VirtualAllocEx', 'handle', $mGWProcHandle, 'ptr', 0, 'ulong_ptr', $mASMSize, 'dword', 0x1000, 'dword', 0x40)
  743.         $mMemory = $mMemory[0]
  744.         MemoryWrite($mBase, $mMemory)
  745.     Else
  746.         $mMemory = $lScanMemory
  747.     EndIf
  748.  
  749.     CompleteASMCode()
  750.  
  751.     If $lScanMemory = 0 Then
  752.         WriteBinary($mASMString, $mMemory + $mASMCodeOffset)
  753.         Local $lThread = DllCall($mKernelHandle, 'int', 'CreateRemoteThread', 'int', $mGWProcHandle, 'ptr', 0, 'int', 0, 'int', GetLabelInfo('ScanProc'), 'ptr', 0, 'int', 0, 'int', 0)
  754.         $lThread = $lThread[0]
  755.         Local $lResult
  756.         Do
  757.             $lResult = DllCall($mKernelHandle, 'int', 'WaitForSingleObject', 'int', $lThread, 'int', 50)
  758.         Until $lResult[0] <> 258
  759.         DllCall($mKernelHandle, 'int', 'CloseHandle', 'int', $lThread)
  760.     EndIf
  761. EndFunc   ;==>Scan
  762.  
  763. ;~ Description: Internal use only.
  764. Func AddPattern($aPattern)
  765.     Local $lSize = Int(0.5 * StringLen($aPattern))
  766.     $mASMString &= '00000000' & SwapEndian(Hex($lSize, 8)) & '00000000' & $aPattern
  767.     $mASMSize += $lSize + 12
  768.     For $i = 1 To 68 - $lSize
  769.         $mASMSize += 1
  770.         $mASMString &= '00'
  771.     Next
  772. EndFunc   ;==>AddPattern
  773.  
  774. ;~ Description: Internal use only.
  775. Func GetScannedAddress($aLabel, $aOffset)
  776.     Return MemoryRead(GetLabelInfo($aLabel) + 8) - MemoryRead(GetLabelInfo($aLabel) + 4) + $aOffset
  777. EndFunc   ;==>GetScannedAddress
  778.  
  779. ;~ Description: Internal use only.
  780. Func ScanForCharname()
  781.     Local $lCharNameCode = BinaryToString('0x90909066C705')
  782.     Local $lCurrentSearchAddress = 0x00401000
  783.     Local $lMBI[7], $lMBIBuffer = DllStructCreate('dword;dword;dword;dword;dword;dword;dword')
  784.     Local $lSearch, $lTmpMemData, $lTmpAddress, $lTmpBuffer = DllStructCreate('ptr'), $i
  785.  
  786.     While $lCurrentSearchAddress < 0x00900000
  787.         Local $lMBI[7]
  788.         DllCall($mKernelHandle, 'int', 'VirtualQueryEx', 'int', $mGWProcHandle, 'int', $lCurrentSearchAddress, 'ptr', DllStructGetPtr($lMBIBuffer), 'int', DllStructGetSize($lMBIBuffer))
  789.         For $i = 0 To 6
  790.             $lMBI[$i] = StringStripWS(DllStructGetData($lMBIBuffer, ($i + 1)), 3)
  791.         Next
  792.  
  793.         If $lMBI[4] = 4096 Then
  794.             Local $lBuffer = DllStructCreate('byte[' & $lMBI[3] & ']')
  795.             DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lCurrentSearchAddress, 'ptr', DllStructGetPtr($lBuffer), 'int', DllStructGetSize($lBuffer), 'int', '')
  796.  
  797.             $lTmpMemData = DllStructGetData($lBuffer, 1)
  798.             $lTmpMemData = BinaryToString($lTmpMemData)
  799.  
  800.             $lSearch = StringInStr($lTmpMemData, $lCharNameCode, 2)
  801.             If $lSearch > 0 Then
  802.                 $lTmpAddress = $lCurrentSearchAddress + $lSearch - 1
  803.                 DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lTmpAddress + 0x6, 'ptr', DllStructGetPtr($lTmpBuffer), 'int', DllStructGetSize($lTmpBuffer), 'int', '')
  804.                 $mCharname = DllStructGetData($lTmpBuffer, 1)
  805.                 Return GetCharname()
  806.             EndIf
  807.  
  808.             $lCurrentSearchAddress += $lMBI[3]
  809.         EndIf
  810.     WEnd
  811.  
  812.     Return ''
  813. EndFunc   ;==>ScanForCharname
  814. #EndRegion Initialisation
  815.  
  816. #Region Commands
  817. #Region Item
  818. ;~ Description: Starts a salvaging session of an item.
  819. Func StartSalvage($aItem, $aExpert = False)
  820.     Local $lOffset[4] = [0, 0x18, 0x2C, 0x690]
  821.     Local $lSalvageSessionID = MemoryReadPtr($mBasePointer, $lOffset)
  822.  
  823.     If IsDllStruct($aItem) = 0 Then
  824.         Local $lItemID = $aItem
  825.     Else
  826.         Local $lItemID = DllStructGetData($aItem, 'ID')
  827.     EndIf
  828.  
  829.     Local $lSalvageKit = 0
  830.     If $aExpert Then
  831.         $lSalvageKit = FindExpertSalvageKit()
  832.     Else
  833.         $lSalvageKit = FindSalvageKit()
  834.     EndIf
  835.     If $lSalvageKit = 0 Then Return
  836.  
  837.     DllStructSetData($mSalvage, 2, $lItemID)
  838.     DllStructSetData($mSalvage, 3, $lSalvageKit)
  839.     DllStructSetData($mSalvage, 4, $lSalvageSessionID[1])
  840.  
  841.     Enqueue($mSalvagePtr, 16)
  842. EndFunc   ;==>StartSalvage
  843.  
  844. ;~ Description: Salvage the materials out of an item.
  845. Func SalvageMaterials()
  846.     Return SendPacket(0x4, $HEADER_SALVAGE_MATS)
  847. EndFunc   ;==>SalvageMaterials
  848.  
  849. ;~ Description: Salvages a mod out of an item.
  850. Func SalvageMod($aModIndex)
  851.     Return SendPacket(0x8, $HEADER_SALVAGE_MODS, $aModIndex)
  852. EndFunc   ;==>SalvageMod
  853.  
  854. ;~ Description: Identifies an item.
  855. Func IdentifyItem($aItem)
  856.     If GetIsIDed($aItem) Then Return
  857.  
  858.     Local $lItemID
  859.     If IsDllStruct($aItem) = 0 Then
  860.         $lItemID = $aItem
  861.     Else
  862.         $lItemID = DllStructGetData($aItem, 'ID')
  863.     EndIf
  864.  
  865.     Local $lIDKit = FindIDKit()
  866.     If $lIDKit == 0 Then Return
  867.  
  868.     SendPacket(0xC, $HEADER_ITEM_ID, $lIDKit, $lItemID)
  869.  
  870.     Local $lDeadlock = TimerInit()
  871.     Do
  872.         Sleep(20)
  873.     Until GetIsIDed($lItemID) Or TimerDiff($lDeadlock) > 5000
  874.     If Not GetIsIDed($lItemID) Then IdentifyItem($aItem)
  875. EndFunc   ;==>IdentifyItem
  876.  
  877. ;~ Description: Identifies all items in a bag.
  878. Func IdentifyBag($aBag, $aWhites = False, $aGolds = True)
  879.     Local $lItem
  880.     If Not IsDllStruct($aBag) Then $aBag = GetBag($aBag)
  881.     For $i = 1 To DllStructGetData($aBag, 'Slots')
  882.         $lItem = GetItemBySlot($aBag, $i)
  883.         If DllStructGetData($lItem, 'ID') == 0 Then ContinueLoop
  884.         If GetRarity($lItem) == 2621 And $aWhites == False Then ContinueLoop
  885.         If GetRarity($lItem) == 2624 And $aGolds == False Then ContinueLoop
  886.         IdentifyItem($lItem)
  887.         Sleep(GetPing())
  888.     Next
  889. EndFunc   ;==>IdentifyBag
  890.  
  891. ;~ Description: Equips an item.
  892. Func EquipItem($aItem)
  893.     Local $lItemID
  894.  
  895.     If IsDllStruct($aItem) = 0 Then
  896.         $lItemID = $aItem
  897.     Else
  898.         $lItemID = DllStructGetData($aItem, 'ID')
  899.     EndIf
  900.  
  901.     Return SendPacket(0x8, $HEADER_ITEM_EQUIP, $lItemID)
  902. EndFunc   ;==>EquipItem
  903.  
  904. ;~ Description: Uses an item.
  905. Func UseItem($aItem)
  906.     Local $lItemID
  907.  
  908.     If IsDllStruct($aItem) = 0 Then
  909.         $lItemID = $aItem
  910.     Else
  911.         $lItemID = DllStructGetData($aItem, 'ID')
  912.     EndIf
  913.  
  914.     Return SendPacket(0x8, $HEADER_ITEM_USE, $lItemID)
  915. EndFunc   ;==>UseItem
  916.  
  917. ;~ Description: Picks up an item.
  918. Func PickUpItem($aItem)
  919.     Local $lAgentID
  920.  
  921.     If IsDllStruct($aItem) = 0 Then
  922.         $lAgentID = $aItem
  923.     ElseIf DllStructGetSize($aItem) < 400 Then
  924.         $lAgentID = DllStructGetData($aItem, 'AgentID')
  925.     Else
  926.         $lAgentID = DllStructGetData($aItem, 'ID')
  927.     EndIf
  928.  
  929.     Return SendPacket(0xC, $HEADER_ITEM_PICKUP, $lAgentID, 0)
  930. EndFunc   ;==>PickUpItem
  931.  
  932. ;~ Description: Drops an item.
  933. Func DropItem($aItem, $aAmount = 0)
  934.     Local $lItemID, $lAmount
  935.  
  936.     If IsDllStruct($aItem) = 0 Then
  937.         $lItemID = $aItem
  938.         If $aAmount > 0 Then
  939.             $lAmount = $aAmount
  940.         Else
  941.             $lAmount = DllStructGetData(GetItemByItemID($aItem), 'Quantity')
  942.         EndIf
  943.     Else
  944.         $lItemID = DllStructGetData($aItem, 'ID')
  945.         If $aAmount > 0 Then
  946.             $lAmount = $aAmount
  947.         Else
  948.             $lAmount = DllStructGetData($aItem, 'Quantity')
  949.         EndIf
  950.     EndIf
  951.  
  952.     Return SendPacket(0xC, $HEADER_ITEM_DROP, $lItemID, $lAmount)
  953. EndFunc   ;==>DropItem
  954.  
  955. ;~ Description: Moves an item.
  956. Func MoveItem($aItem, $aBag, $aSlot)
  957.     Local $lItemID, $lBagID
  958.  
  959.     If IsDllStruct($aItem) = 0 Then
  960.         $lItemID = $aItem
  961.     Else
  962.         $lItemID = DllStructGetData($aItem, 'ID')
  963.     EndIf
  964.  
  965.     If IsDllStruct($aBag) = 0 Then
  966.         $lBagID = DllStructGetData(GetBag($aBag), 'ID')
  967.     Else
  968.         $lBagID = DllStructGetData($aBag, 'ID')
  969.     EndIf
  970.  
  971.     Return SendPacket(0x10, $HEADER_ITEM_MOVE, $lItemID, $lBagID, $aSlot - 1)
  972. EndFunc   ;==>MoveItem
  973.  
  974. ;~ Description: Accepts unclaimed items after a mission.
  975. Func AcceptAllItems()
  976.     Return SendPacket(0x8, $HEADER_ITEMS_ACCEPT_UNCLAIMED, DllStructGetData(GetBag(7), 'ID'))
  977. EndFunc   ;==>AcceptAllItems
  978.  
  979. ;~ Description: Sells an item.
  980. Func SellItem($aItem, $aQuantity = 0)
  981.     If IsDllStruct($aItem) = 0 Then $aItem = GetItemByItemID($aItem)
  982.     If $aQuantity = 0 Or $aQuantity > DllStructGetData($aItem, 'Quantity') Then $aQuantity = DllStructGetData($aItem, 'Quantity')
  983.  
  984.     DllStructSetData($mSellItem, 2, $aQuantity * DllStructGetData($aItem, 'Value'))
  985.     DllStructSetData($mSellItem, 3, DllStructGetData($aItem, 'ID'))
  986.     Enqueue($mSellItemPtr, 12)
  987. EndFunc   ;==>SellItem
  988.  
  989. ;~ Description: Buys an item.
  990. Func BuyItem($aItem, $aQuantity, $aValue)
  991.     Local $lMerchantItemsBase = GetMerchantItemsBase()
  992.  
  993.     If Not $lMerchantItemsBase Then Return
  994.     If $aItem < 1 Or $aItem > GetMerchantItemsSize() Then Return
  995.  
  996.     DllStructSetData($mBuyItem, 2, $aQuantity)
  997.     DllStructSetData($mBuyItem, 3, MemoryRead($lMerchantItemsBase + 4 * ($aItem - 1)))
  998.     DllStructSetData($mBuyItem, 4, $aQuantity * $aValue)
  999.     Enqueue($mBuyItemPtr, 16)
  1000. EndFunc   ;==>BuyItem
  1001.  
  1002. ;~ Description: Legacy function, use BuyIdentificationKit instead.
  1003. Func BuyIDKit($aQuantity = 1)
  1004.     BuyIdentificationKit($aQuantity)
  1005. EndFunc   ;==>BuyIDKit
  1006.  
  1007. ;~ Description: Buys an ID kit.
  1008. Func BuyIdentificationKit($aQuantity = 1)
  1009.     BuyItem(5, $aQuantity, 100)
  1010. EndFunc   ;==>BuyIdentificationKit
  1011.  
  1012. ;~ Description: Legacy function, use BuySuperiorIdentificationKit instead.
  1013. Func BuySuperiorIDKit($aQuantity = 1)
  1014.     BuySuperiorIdentificationKit($aQuantity)
  1015. EndFunc   ;==>BuySuperiorIDKit
  1016.  
  1017. ;~ Description: Buys a superior ID kit.
  1018. Func BuySuperiorIdentificationKit($aQuantity = 1)
  1019.     BuyItem(6, $aQuantity, 500)
  1020. EndFunc   ;==>BuySuperiorIdentificationKit
  1021.  
  1022. func BuySalvageKit($aQuantity = 1)
  1023.     buyItem(2, $aQuantity, 100)
  1024. endFunc   ;==>buySalvageKit
  1025.  
  1026. func BuyExpertSalvageKit($aQuantity = 1)
  1027.     buyItem(3, $aQuantity, 400)
  1028. endFunc   ;==>buyExpertSalvageKit
  1029.  
  1030. ;~ Description: Request a quote to buy an item from a trader. Returns true if successful.
  1031. Func TraderRequest($aModelID, $aExtraID = -1)
  1032.     Local $lItemStruct = DllStructCreate('long Id;long AgentId;byte Unknown1[4];ptr Bag;ptr ModStruct;long ModStructSize;ptr Customized;byte unknown2[4];byte Type;byte unknown4;short ExtraId;short Value;byte unknown4[2];short Interaction;long ModelId;ptr ModString;byte unknown5[4];ptr NameString;ptr SingleItemName;byte Unknown4[10];byte IsSalvageable;byte Unknown6;byte Quantity;byte Equiped;byte Profession;byte Type2;byte Slot')
  1033.     Local $lOffset[4] = [0, 0x18, 0x40, 0xC0]
  1034.     Local $lItemArraySize = MemoryReadPtr($mBasePointer, $lOffset)
  1035.     Local $lOffset[5] = [0, 0x18, 0x40, 0xB8, 0]
  1036.     Local $lItemPtr, $lItemID
  1037.     Local $lFound = False
  1038.     Local $lQuoteID = MemoryRead($mTraderQuoteID)
  1039.  
  1040.     For $lItemID = 1 To $lItemArraySize[1]
  1041.         $lOffset[4] = 0x4 * $lItemID
  1042.         $lItemPtr = MemoryReadPtr($mBasePointer, $lOffset)
  1043.         If $lItemPtr[1] = 0 Then ContinueLoop
  1044.  
  1045.         DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lItemPtr[1], 'ptr', DllStructGetPtr($lItemStruct), 'int', DllStructGetSize($lItemStruct), 'int', '')
  1046.         If DllStructGetData($lItemStruct, 'ModelID') = $aModelID And DllStructGetData($lItemStruct, 'bag') = 0 And DllStructGetData($lItemStruct, 'AgentID') == 0 Then
  1047.             If $aExtraID = -1 Or DllStructGetData($lItemStruct, 'ExtraID') = $aExtraID Then
  1048.                 $lFound = True
  1049.                 ExitLoop
  1050.             EndIf
  1051.         EndIf
  1052.     Next
  1053.     If Not $lFound Then Return False
  1054.  
  1055.     DllStructSetData($mRequestQuote, 2, DllStructGetData($lItemStruct, 'ID'))
  1056.     Enqueue($mRequestQuotePtr, 8)
  1057.  
  1058.     Local $lDeadlock = TimerInit()
  1059.     $lFound = False
  1060.     Do
  1061.         Sleep(20)
  1062.         $lFound = MemoryRead($mTraderQuoteID) <> $lQuoteID
  1063.     Until $lFound Or TimerDiff($lDeadlock) > GetPing() + 5000
  1064.     Return $lFound
  1065. EndFunc   ;==>TraderRequest
  1066.  
  1067. ;~ Description: Buy the requested item.
  1068. Func TraderBuy()
  1069.     If Not GetTraderCostID() Or Not GetTraderCostValue() Then Return False
  1070.     Enqueue($mTraderBuyPtr, 4)
  1071.     Return True
  1072. EndFunc   ;==>TraderBuy
  1073.  
  1074. ;~ Description: Request a quote to sell an item to the trader.
  1075. Func TraderRequestSell($aItem)
  1076.     Local $lItemID
  1077.     Local $lFound = False
  1078.     Local $lQuoteID = MemoryRead($mTraderQuoteID)
  1079.  
  1080.     If IsDllStruct($aItem) = 0 Then
  1081.         $lItemID = $aItem
  1082.     Else
  1083.         $lItemID = DllStructGetData($aItem, 'ID')
  1084.     EndIf
  1085.  
  1086.     DllStructSetData($mRequestQuoteSell, 2, $lItemID)
  1087.     Enqueue($mRequestQuoteSellPtr, 8)
  1088.  
  1089.     Local $lDeadlock = TimerInit()
  1090.     Do
  1091.         Sleep(20)
  1092.         $lFound = MemoryRead($mTraderQuoteID) <> $lQuoteID
  1093.     Until $lFound Or TimerDiff($lDeadlock) > GetPing() + 5000
  1094.     Return $lFound
  1095. EndFunc   ;==>TraderRequestSell
  1096.  
  1097. ;~ Description: ID of the item item being sold.
  1098. Func TraderSell()
  1099.     If Not GetTraderCostID() Or Not GetTraderCostValue() Then Return False
  1100.     Enqueue($mTraderSellPtr, 4)
  1101.     Return True
  1102. EndFunc   ;==>TraderSell
  1103.  
  1104. ;~ Description: Drop gold on the ground.
  1105. Func DropGold($aAmount = 0)
  1106.     Local $lAmount
  1107.  
  1108.     If $aAmount > 0 Then
  1109.         $lAmount = $aAmount
  1110.     Else
  1111.         $lAmount = GetGoldCharacter()
  1112.     EndIf
  1113.  
  1114.     Return SendPacket(0x8, $HEADER_GOLD_DROP, $lAmount)
  1115. EndFunc   ;==>DropGold
  1116.  
  1117. ;~ Description: Deposit gold into storage.
  1118. Func DepositGold($aAmount = 0)
  1119.     Local $lAmount
  1120.     Local $lStorage = GetGoldStorage()
  1121.     Local $lCharacter = GetGoldCharacter()
  1122.  
  1123.     If $aAmount > 0 And $lCharacter >= $aAmount Then
  1124.         $lAmount = $aAmount
  1125.     Else
  1126.         $lAmount = $lCharacter
  1127.     EndIf
  1128.  
  1129.     If $lStorage + $lAmount > 1000000 Then $lAmount = 1000000 - $lStorage
  1130.  
  1131.     ChangeGold($lCharacter - $lAmount, $lStorage + $lAmount)
  1132. EndFunc   ;==>DepositGold
  1133.  
  1134. ;~ Description: Withdraw gold from storage.
  1135. Func WithdrawGold($aAmount = 0)
  1136.     Local $lAmount
  1137.     Local $lStorage = GetGoldStorage()
  1138.     Local $lCharacter = GetGoldCharacter()
  1139.  
  1140.     If $aAmount > 0 And $lStorage >= $aAmount Then
  1141.         $lAmount = $aAmount
  1142.     Else
  1143.         $lAmount = $lStorage
  1144.     EndIf
  1145.  
  1146.     If $lCharacter + $lAmount > 100000 Then $lAmount = 100000 - $lCharacter
  1147.  
  1148.     ChangeGold($lCharacter + $lAmount, $lStorage - $lAmount)
  1149. EndFunc   ;==>WithdrawGold
  1150.  
  1151. ;~ Description: Internal use for moving gold.
  1152. Func ChangeGold($aCharacter, $aStorage)
  1153.     Return SendPacket(0xC, $HEADER_GOLD_MOVE, $aCharacter, $aStorage)
  1154. EndFunc   ;==>ChangeGold
  1155. #EndRegion Item
  1156.  
  1157. #Region H&H
  1158. ;~ Description: Adds a hero to the party.
  1159. Func AddHero($aHeroId)
  1160.     Return SendPacket(0x8, $HEADER_HERO_ADD, $aHeroId)
  1161. EndFunc   ;==>AddHero
  1162.  
  1163. ;~ Description: Kicks a hero from the party.
  1164. Func KickHero($aHeroId)
  1165.     Return SendPacket(0x8, $HEADER_HERO_KICK, $aHeroId)
  1166. EndFunc   ;==>KickHero
  1167.  
  1168. ;~ Description: Kicks all heroes from the party.
  1169. Func KickAllHeroes()
  1170.     Return SendPacket(0x8, $HEADER_HEROES_KICK, 0x24)
  1171. EndFunc   ;==>KickAllHeroes
  1172.  
  1173. ;~ Description: Add a henchman to the party.
  1174. Func AddNpc($aNpcId)
  1175.     Return SendPacket(0x8, $HEADER_HENCHMAN_ADD, $aNpcId)
  1176. EndFunc   ;==>AddNpc
  1177.  
  1178. ;~ Description: Kick a henchman from the party.
  1179. Func KickNpc($aNpcId)
  1180.     Return SendPacket(0x8, $HEADER_HENCHMAN_KICK, $aNpcId)
  1181. EndFunc   ;==>KickNpc
  1182.  
  1183. ;~ Description: Clear the position flag from a hero.
  1184. Func CancelHero($aHeroNumber)
  1185.     Local $lAgentID = GetHeroID($aHeroNumber)
  1186.     Return SendPacket(0x14, $HEADER_HERO_CLEAR_FLAG, $lAgentID, 0x7F800000, 0x7F800000, 0)
  1187. EndFunc   ;==>CancelHero
  1188.  
  1189. ;~ Description: Clear the position flag from all heroes.
  1190. Func CancelAll()
  1191.     Return SendPacket(0x10, $HEADER_PARTY_CLEAR_FLAG, 0x7F800000, 0x7F800000, 0)
  1192. EndFunc   ;==>CancelAll
  1193.  
  1194. ;~ Description: Place a hero's position flag.
  1195. Func CommandHero($aHeroNumber, $aX, $aY)
  1196.     Return SendPacket(0x14, $HEADER_HERO_PLACE_FLAG, GetHeroID($aHeroNumber), FloatToInt($aX), FloatToInt($aY), 0)
  1197. EndFunc   ;==>CommandHero
  1198.  
  1199. ;~ Description: Place the full-party position flag.
  1200. Func CommandAll($aX, $aY)
  1201.     Return SendPacket(0x10, $HEADER_PARTY_PLACE_FLAG, FloatToInt($aX), FloatToInt($aY), 0)
  1202. EndFunc   ;==>CommandAll
  1203.  
  1204. ;~ Description: Lock a hero onto a target.
  1205. Func LockHeroTarget($aHeroNumber, $aAgentID = 0) ;$aAgentID=0 Cancels Lock
  1206.     Local $lHeroID = GetHeroID($aHeroNumber)
  1207.     Return SendPacket(0xC, $HEADER_HERO_LOCK, $lHeroID, $aAgentID)
  1208. EndFunc   ;==>LockHeroTarget
  1209.  
  1210. ;~ Description: Change a hero's aggression level.
  1211. Func SetHeroAggression($aHeroNumber, $aAggression) ;0=Fight, 1=Guard, 2=Avoid
  1212.     Local $lHeroID = GetHeroID($aHeroNumber)
  1213.     Return SendPacket(0xC, $HEADER_HERO_AGGRESSION, $lHeroID, $aAggression)
  1214. EndFunc   ;==>SetHeroAggression
  1215.  
  1216. ;~ Description: Disable a skill on a hero's skill bar.
  1217. Func DisableHeroSkillSlot($aHeroNumber, $aSkillSlot)
  1218.     If Not GetIsHeroSkillSlotDisabled($aHeroNumber, $aSkillSlot) Then ChangeHeroSkillSlotState($aHeroNumber, $aSkillSlot)
  1219. EndFunc   ;==>DisableHeroSkillSlot
  1220.  
  1221. ;~ Description: Enable a skill on a hero's skill bar.
  1222. Func EnableHeroSkillSlot($aHeroNumber, $aSkillSlot)
  1223.     If GetIsHeroSkillSlotDisabled($aHeroNumber, $aSkillSlot) Then ChangeHeroSkillSlotState($aHeroNumber, $aSkillSlot)
  1224. EndFunc   ;==>EnableHeroSkillSlot
  1225.  
  1226. ;~ Description: Internal use for enabling or disabling hero skills
  1227. Func ChangeHeroSkillSlotState($aHeroNumber, $aSkillSlot)
  1228.     Return SendPacket(0xC, $HEADER_HERO_TOGGLE_SKILL, GetHeroID($aHeroNumber), $aSkillSlot - 1)
  1229. EndFunc   ;==>ChangeHeroSkillSlotState
  1230.  
  1231. ;~ Description: Order a hero to use a skill.
  1232. Func UseHeroSkill($aHero, $aSkillSlot, $aTarget = 0)
  1233.     Local $lTargetID
  1234.  
  1235.     If IsDllStruct($aTarget) = 0 Then
  1236.         $lTargetID = ConvertID($aTarget)
  1237.     Else
  1238.         $lTargetID = DllStructGetData($aTarget, 'ID')
  1239.     EndIf
  1240.  
  1241.     DllStructSetData($mUseHeroSkill, 2, GetHeroID($aHero))
  1242.     DllStructSetData($mUseHeroSkill, 3, $lTargetID)
  1243.     DllStructSetData($mUseHeroSkill, 4, $aSkillSlot - 1)
  1244.     Enqueue($mUseHeroSkillPtr, 16)
  1245. EndFunc   ;==>UseHeroSkill
  1246.  
  1247. Func SetDisplayedTitle($aTitle = 0)
  1248.     If $aTitle Then
  1249.         Return SendPacket(0x8, $HEADER_TITLE_DISPLAY, $aTitle)
  1250.     Else
  1251.         Return SendPacket(0x4, $HEADER_TITLE_CLEAR)
  1252.     EndIf
  1253. EndFunc   ;==>SetDisplayedTitle
  1254. #EndRegion H&H
  1255.  
  1256. #Region Movement
  1257. ;~ Description: Move to a location.
  1258. Func Move($aX, $aY, $aRandom = 50)
  1259.     ;returns true if successful
  1260.     If GetAgentExists(-2) Then
  1261.         DllStructSetData($mMove, 2, $aX + Random(-$aRandom, $aRandom))
  1262.         DllStructSetData($mMove, 3, $aY + Random(-$aRandom, $aRandom))
  1263.         Enqueue($mMovePtr, 16)
  1264.         Return True
  1265.     Else
  1266.         Return False
  1267.     EndIf
  1268. EndFunc   ;==>Move
  1269.  
  1270. ;~ Description: Move to a location and wait until you reach it.
  1271. Func MoveTo($aX, $aY, $aRandom = 50)
  1272.     Local $lBlocked = 0
  1273.     Local $lMe
  1274.     Local $lMapLoading = GetMapLoading(), $lMapLoadingOld
  1275.     Local $lDestX = $aX + Random(-$aRandom, $aRandom)
  1276.     Local $lDestY = $aY + Random(-$aRandom, $aRandom)
  1277.  
  1278.     Move($lDestX, $lDestY, 0)
  1279.  
  1280.     Do
  1281.         Sleep(100)
  1282.         $lMe = GetAgentByID(-2)
  1283.  
  1284.         If DllStructGetData($lMe, 'HP') <= 0 Then ExitLoop
  1285.  
  1286.         $lMapLoadingOld = $lMapLoading
  1287.         $lMapLoading = GetMapLoading()
  1288.         If $lMapLoading <> $lMapLoadingOld Then ExitLoop
  1289.  
  1290.         If DllStructGetData($lMe, 'MoveX') == 0 And DllStructGetData($lMe, 'MoveY') == 0 Then
  1291.             $lBlocked += 1
  1292.             $lDestX = $aX + Random(-$aRandom, $aRandom)
  1293.             $lDestY = $aY + Random(-$aRandom, $aRandom)
  1294.             Move($lDestX, $lDestY, 0)
  1295.         EndIf
  1296.     Until ComputeDistance(DllStructGetData($lMe, 'X'), DllStructGetData($lMe, 'Y'), $lDestX, $lDestY) < 25 Or $lBlocked > 14
  1297. EndFunc   ;==>MoveTo
  1298.  
  1299. ;~ Description: Run to or follow a player.
  1300. Func GoPlayer($aAgent)
  1301.     Local $lAgentID
  1302.  
  1303.     If IsDllStruct($aAgent) = 0 Then
  1304.         $lAgentID = ConvertID($aAgent)
  1305.     Else
  1306.         $lAgentID = DllStructGetData($aAgent, 'ID')
  1307.     EndIf
  1308.  
  1309.     Return SendPacket(0x8, $HEADER_AGENT_FOLLOW, $lAgentID)
  1310. EndFunc   ;==>GoPlayer
  1311.  
  1312. ;~ Description: Talk to an NPC
  1313. Func GoNPC($aAgent)
  1314.     Local $lAgentID
  1315.  
  1316.     If IsDllStruct($aAgent) = 0 Then
  1317.         $lAgentID = ConvertID($aAgent)
  1318.     Else
  1319.         $lAgentID = DllStructGetData($aAgent, 'ID')
  1320.     EndIf
  1321.  
  1322.     Return SendPacket(0xC, $HEADER_NPC_TALK, $lAgentID)
  1323. EndFunc   ;==>GoNPC
  1324.  
  1325. ;~ Description: Talks to NPC and waits until you reach them.
  1326. Func GoToNPC($aAgent)
  1327.     If Not IsDllStruct($aAgent) Then $aAgent = GetAgentByID($aAgent)
  1328.     Local $lMe
  1329.     Local $lBlocked = 0
  1330.     Local $lMapLoading = GetMapLoading(), $lMapLoadingOld
  1331.  
  1332.     Move(DllStructGetData($aAgent, 'X'), DllStructGetData($aAgent, 'Y'), 100)
  1333.     Sleep(100)
  1334.     GoNPC($aAgent)
  1335.  
  1336.     Do
  1337.         Sleep(100)
  1338.         $lMe = GetAgentByID(-2)
  1339.  
  1340.         If DllStructGetData($lMe, 'HP') <= 0 Then ExitLoop
  1341.  
  1342.         $lMapLoadingOld = $lMapLoading
  1343.         $lMapLoading = GetMapLoading()
  1344.         If $lMapLoading <> $lMapLoadingOld Then ExitLoop
  1345.  
  1346.         If DllStructGetData($lMe, 'MoveX') == 0 And DllStructGetData($lMe, 'MoveY') == 0 Then
  1347.             $lBlocked += 1
  1348.             Move(DllStructGetData($aAgent, 'X'), DllStructGetData($aAgent, 'Y'), 100)
  1349.             Sleep(100)
  1350.             GoNPC($aAgent)
  1351.         EndIf
  1352.     Until ComputeDistance(DllStructGetData($lMe, 'X'), DllStructGetData($lMe, 'Y'), DllStructGetData($aAgent, 'X'), DllStructGetData($aAgent, 'Y')) < 250 Or $lBlocked > 14
  1353.     Sleep(GetPing() + Random(1500, 2000, 1))
  1354. EndFunc   ;==>GoToNPC
  1355.  
  1356. ;~ Description: Run to a signpost.
  1357. Func GoSignpost($aAgent)
  1358.     Local $lAgentID
  1359.  
  1360.     If IsDllStruct($aAgent) = 0 Then
  1361.         $lAgentID = ConvertID($aAgent)
  1362.     Else
  1363.         $lAgentID = DllStructGetData($aAgent, 'ID')
  1364.     EndIf
  1365.  
  1366.     Return SendPacket(0xC, $HEADER_SIGNPOST_RUN, $lAgentID, 0)
  1367. EndFunc   ;==>GoSignpost
  1368.  
  1369. ;~ Description: Go to signpost and waits until you reach it.
  1370. Func GoToSignpost($aAgent)
  1371.     If Not IsDllStruct($aAgent) Then $aAgent = GetAgentByID($aAgent)
  1372.     Local $lMe
  1373.     Local $lBlocked = 0
  1374.     Local $lMapLoading = GetMapLoading(), $lMapLoadingOld
  1375.  
  1376.     Move(DllStructGetData($aAgent, 'X'), DllStructGetData($aAgent, 'Y'), 100)
  1377.     Sleep(100)
  1378.     GoSignpost($aAgent)
  1379.  
  1380.     Do
  1381.         Sleep(100)
  1382.         $lMe = GetAgentByID(-2)
  1383.  
  1384.         If DllStructGetData($lMe, 'HP') <= 0 Then ExitLoop
  1385.  
  1386.         $lMapLoadingOld = $lMapLoading
  1387.         $lMapLoading = GetMapLoading()
  1388.         If $lMapLoading <> $lMapLoadingOld Then ExitLoop
  1389.  
  1390.         If DllStructGetData($lMe, 'MoveX') == 0 And DllStructGetData($lMe, 'MoveY') == 0 Then
  1391.             $lBlocked += 1
  1392.             Move(DllStructGetData($aAgent, 'X'), DllStructGetData($aAgent, 'Y'), 100)
  1393.             Sleep(100)
  1394.             GoSignpost($aAgent)
  1395.         EndIf
  1396.     Until ComputeDistance(DllStructGetData($lMe, 'X'), DllStructGetData($lMe, 'Y'), DllStructGetData($aAgent, 'X'), DllStructGetData($aAgent, 'Y')) < 250 Or $lBlocked > 14
  1397.     Sleep(GetPing() + Random(1500, 2000, 1))
  1398. EndFunc   ;==>GoToSignpost
  1399.  
  1400. ;~ Description: Attack an agent.
  1401. Func Attack($aAgent, $aCallTarget = False)
  1402.     Local $lAgentID
  1403.  
  1404.     If IsDllStruct($aAgent) = 0 Then
  1405.         $lAgentID = ConvertID($aAgent)
  1406.     Else
  1407.         $lAgentID = DllStructGetData($aAgent, 'ID')
  1408.     EndIf
  1409.  
  1410.     Return SendPacket(0xC, $HEADER_ATTACK_AGENT, $lAgentID, $aCallTarget)
  1411. EndFunc   ;==>Attack
  1412.  
  1413. ;~ Description: Turn character to the left.
  1414. Func TurnLeft($aTurn)
  1415.     If $aTurn Then
  1416.         Return PerformAction(0xA2, 0x18)
  1417.     Else
  1418.         Return PerformAction(0xA2, 0x1A)
  1419.     EndIf
  1420. EndFunc   ;==>TurnLeft
  1421.  
  1422. ;~ Description: Turn character to the right.
  1423. Func TurnRight($aTurn)
  1424.     If $aTurn Then
  1425.         Return PerformAction(0xA3, 0x18)
  1426.     Else
  1427.         Return PerformAction(0xA3, 0x1A)
  1428.     EndIf
  1429. EndFunc   ;==>TurnRight
  1430.  
  1431. ;~ Description: Move backwards.
  1432. Func MoveBackward($aMove)
  1433.     If $aMove Then
  1434.         Return PerformAction(0xAC, 0x18)
  1435.     Else
  1436.         Return PerformAction(0xAC, 0x1A)
  1437.     EndIf
  1438. EndFunc   ;==>MoveBackward
  1439.  
  1440. ;~ Description: Run forwards.
  1441. Func MoveForward($aMove)
  1442.     If $aMove Then
  1443.         Return PerformAction(0xAD, 0x18)
  1444.     Else
  1445.         Return PerformAction(0xAD, 0x1A)
  1446.     EndIf
  1447. EndFunc   ;==>MoveForward
  1448.  
  1449. ;~ Description: Strafe to the left.
  1450. Func StrafeLeft($aStrafe)
  1451.     If $aStrafe Then
  1452.         Return PerformAction(0x91, 0x18)
  1453.     Else
  1454.         Return PerformAction(0x91, 0x1A)
  1455.     EndIf
  1456. EndFunc   ;==>StrafeLeft
  1457.  
  1458. ;~ Description: Strafe to the right.
  1459. Func StrafeRight($aStrafe)
  1460.     If $aStrafe Then
  1461.         Return PerformAction(0x92, 0x18)
  1462.     Else
  1463.         Return PerformAction(0x92, 0x1A)
  1464.     EndIf
  1465. EndFunc   ;==>StrafeRight
  1466.  
  1467. ;~ Description: Auto-run.
  1468. Func ToggleAutoRun()
  1469.     Return PerformAction(0xB7, 0x18)
  1470. EndFunc   ;==>ToggleAutoRun
  1471.  
  1472. ;~ Description: Turn around.
  1473. Func ReverseDirection()
  1474.     Return PerformAction(0xB1, 0x18)
  1475. EndFunc   ;==>ReverseDirection
  1476. #EndRegion Movement
  1477.  
  1478. #Region Travel
  1479. ;~ Description: Map travel to an outpost.
  1480. Func TravelTo($aMapID, $aDis = 0)
  1481.     ;returns true if successful
  1482.     If GetMapID() = $aMapID And $aDis = 0 And GetMapLoading() = 0 Then Return True
  1483.     ZoneMap($aMapID, $aDis)
  1484.     Return WaitMapLoading($aMapID)
  1485. EndFunc   ;==>TravelTo
  1486.  
  1487. ;~ Description: Internal use for map travel.
  1488. Func ZoneMap($aMapID, $aDistrict = 0)
  1489.     MoveMap($aMapID, GetRegion(), $aDistrict, GetLanguage());
  1490. EndFunc   ;==>ZoneMap
  1491.  
  1492. ;~ Description: Internal use for map travel.
  1493. Func MoveMap($aMapID, $aRegion, $aDistrict, $aLanguage)
  1494.     Return SendPacket(0x18, $HEADER_MAP_TRAVEL, $aMapID, $aRegion, $aDistrict, $aLanguage, False)
  1495. EndFunc   ;==>MoveMap
  1496.  
  1497. ;~ Description: Returns to outpost after resigning/failure.
  1498. Func ReturnToOutpost()
  1499.     Return SendPacket(0x4, $HEADER_OUTPOST_RETURN)
  1500. EndFunc   ;==>ReturnToOutpost
  1501.  
  1502. ;~ Description: Enter a challenge mission/pvp.
  1503. Func EnterChallenge()
  1504.     Return SendPacket(0x8, $HEADER_MISSION_ENTER, 1)
  1505. EndFunc   ;==>EnterChallenge
  1506.  
  1507. ;~ Description: Enter a foreign challenge mission/pvp.
  1508. Func EnterChallengeForeign()
  1509.     Return SendPacket(0x8, $HEADER_MISSION_FOREIGN_ENTER, 0)
  1510. EndFunc   ;==>EnterChallengeForeign
  1511.  
  1512. ;~ Description: Travel to your guild hall.
  1513. Func TravelGH()
  1514.     Local $lOffset[3] = [0, 0x18, 0x3C]
  1515.     Local $lGH = MemoryReadPtr($mBasePointer, $lOffset)
  1516.     SendPacket(0x18, $HEADER_GUILDHALL_TRAVEL, MemoryRead($lGH[1] + 0x64), MemoryRead($lGH[1] + 0x68), MemoryRead($lGH[1] + 0x6C), MemoryRead($lGH[1] + 0x70), 1)
  1517.     Return WaitMapLoading()
  1518. EndFunc   ;==>TravelGH
  1519.  
  1520. ;~ Description: Leave your guild hall.
  1521. Func LeaveGH()
  1522.     SendPacket(0x8, $HEADER_GUILDHALL_LEAVE, 1)
  1523.     Return WaitMapLoading()
  1524. EndFunc   ;==>LeaveGH
  1525. #EndRegion Travel
  1526.  
  1527. #Region Quest
  1528. ;~ Description: Accept a quest from an NPC.
  1529. Func AcceptQuest($aQuestID)
  1530.     Return SendPacket(0x8, $HEADER_QUEST_ACCEPT, '0x008' & Hex($aQuestID, 3) & '01')
  1531. EndFunc   ;==>AcceptQuest
  1532.  
  1533. ;~ Description: Accept the reward for a quest.
  1534. Func QuestReward($aQuestID)
  1535.     Return SendPacket(0x8, $HEADER_QUEST_REWARD, '0x008' & Hex($aQuestID, 3) & '07')
  1536. EndFunc   ;==>QuestReward
  1537.  
  1538. ;~ Description: Abandon a quest.
  1539. Func AbandonQuest($aQuestID)
  1540.     Return SendPacket(0x8, $HEADER_QUEST_ABANDON, $aQuestID)
  1541. EndFunc   ;==>AbandonQuest
  1542. #EndRegion Quest
  1543.  
  1544. #Region Windows
  1545. ;~ Description: Close all in-game windows.
  1546. Func CloseAllPanels()
  1547.     Return PerformAction(0x85, 0x18)
  1548. EndFunc   ;==>CloseAllPanels
  1549.  
  1550. ;~ Description: Toggle hero window.
  1551. Func ToggleHeroWindow()
  1552.     Return PerformAction(0x8A, 0x18)
  1553. EndFunc   ;==>ToggleHeroWindow
  1554.  
  1555. ;~ Description: Toggle inventory window.
  1556. Func ToggleInventory()
  1557.     Return PerformAction(0x8B, 0x18)
  1558. EndFunc   ;==>ToggleInventory
  1559.  
  1560. ;~ Description: Toggle all bags window.
  1561. Func ToggleAllBags()
  1562.     Return PerformAction(0xB8, 0x18)
  1563. EndFunc   ;==>ToggleAllBags
  1564.  
  1565. ;~ Description: Toggle world map.
  1566. Func ToggleWorldMap()
  1567.     Return PerformAction(0x8C, 0x18)
  1568. EndFunc   ;==>ToggleWorldMap
  1569.  
  1570. ;~ Description: Toggle options window.
  1571. Func ToggleOptions()
  1572.     Return PerformAction(0x8D, 0x18)
  1573. EndFunc   ;==>ToggleOptions
  1574.  
  1575. ;~ Description: Toggle quest window.
  1576. Func ToggleQuestWindow()
  1577.     Return PerformAction(0x8E, 0x18)
  1578. EndFunc   ;==>ToggleQuestWindow
  1579.  
  1580. ;~ Description: Toggle skills window.
  1581. Func ToggleSkillWindow()
  1582.     Return PerformAction(0x8F, 0x18)
  1583. EndFunc   ;==>ToggleSkillWindow
  1584.  
  1585. ;~ Description: Toggle mission map.
  1586. Func ToggleMissionMap()
  1587.     Return PerformAction(0xB6, 0x18)
  1588. EndFunc   ;==>ToggleMissionMap
  1589.  
  1590. ;~ Description: Toggle friends list window.
  1591. Func ToggleFriendList()
  1592.     Return PerformAction(0xB9, 0x18)
  1593. EndFunc   ;==>ToggleFriendList
  1594.  
  1595. ;~ Description: Toggle guild window.
  1596. Func ToggleGuildWindow()
  1597.     Return PerformAction(0xBA, 0x18)
  1598. EndFunc   ;==>ToggleGuildWindow
  1599.  
  1600. ;~ Description: Toggle party window.
  1601. Func TogglePartyWindow()
  1602.     Return PerformAction(0xBF, 0x18)
  1603. EndFunc   ;==>TogglePartyWindow
  1604.  
  1605. ;~ Description: Toggle score chart.
  1606. Func ToggleScoreChart()
  1607.     Return PerformAction(0xBD, 0x18)
  1608. EndFunc   ;==>ToggleScoreChart
  1609.  
  1610. ;~ Description: Toggle layout window.
  1611. Func ToggleLayoutWindow()
  1612.     Return PerformAction(0xC1, 0x18)
  1613. EndFunc   ;==>ToggleLayoutWindow
  1614.  
  1615. ;~ Description: Toggle minions window.
  1616. Func ToggleMinionList()
  1617.     Return PerformAction(0xC2, 0x18)
  1618. EndFunc   ;==>ToggleMinionList
  1619.  
  1620. ;~ Description: Toggle a hero panel.
  1621. Func ToggleHeroPanel($aHero)
  1622.     If $aHero < 4 Then
  1623.         Return PerformAction(0xDB + $aHero, 0x18)
  1624.     ElseIf $aHero < 8 Then
  1625.         Return PerformAction(0xFE + $aHero, 0x18)
  1626.     EndIf
  1627. EndFunc   ;==>ToggleHeroPanel
  1628.  
  1629. ;~ Description: Toggle hero's pet panel.
  1630. Func ToggleHeroPetPanel($aHero)
  1631.     If $aHero < 4 Then
  1632.         Return PerformAction(0xDF + $aHero, 0x18)
  1633.     ElseIf $aHero < 8 Then
  1634.         Return PerformAction(0xFA + $aHero, 0x18)
  1635.     EndIf
  1636. EndFunc   ;==>ToggleHeroPetPanel
  1637.  
  1638. ;~ Description: Toggle pet panel.
  1639. Func TogglePetPanel()
  1640.     Return PerformAction(0xDF, 0x18)
  1641. EndFunc   ;==>TogglePetPanel
  1642.  
  1643. ;~ Description: Toggle help window.
  1644. Func ToggleHelpWindow()
  1645.     Return PerformAction(0xE4, 0x18)
  1646. EndFunc   ;==>ToggleHelpWindow
  1647. #EndRegion Windows
  1648.  
  1649. #Region Targeting
  1650. ;~ Description: Target an agent.
  1651. Func ChangeTarget($aAgent)
  1652.     Local $lAgentID
  1653.  
  1654.     If IsDllStruct($aAgent) = 0 Then
  1655.         $lAgentID = ConvertID($aAgent)
  1656.     Else
  1657.         $lAgentID = DllStructGetData($aAgent, 'ID')
  1658.     EndIf
  1659.  
  1660.     DllStructSetData($mChangeTarget, 2, $lAgentID)
  1661.     Enqueue($mChangeTargetPtr, 8)
  1662. EndFunc   ;==>ChangeTarget
  1663.  
  1664. ;~ Description: Call target.
  1665. Func CallTarget($aTarget)
  1666.     Local $lTargetID
  1667.  
  1668.     If IsDllStruct($aTarget) = 0 Then
  1669.         $lTargetID = ConvertID($aTarget)
  1670.     Else
  1671.         $lTargetID = DllStructGetData($aTarget, 'ID')
  1672.     EndIf
  1673.  
  1674.     Return SendPacket(0xC, $HEADER_CALL_TARGET, 0xA, $lTargetID)
  1675. EndFunc   ;==>CallTarget
  1676.  
  1677. ;~ Description: Clear current target.
  1678. Func ClearTarget()
  1679.     Return PerformAction(0xE3, 0x18)
  1680. EndFunc   ;==>ClearTarget
  1681.  
  1682. ;~ Description: Target the nearest enemy.
  1683. Func TargetNearestEnemy()
  1684.     Local $target = GetNearestEnemyToAgent(-2)
  1685.     ChangeTarget($target)
  1686.     ;Return PerformAction(0x93, 0x18)
  1687. EndFunc   ;==>TargetNearestEnemy
  1688.  
  1689. ;~ Description: Target the next enemy.
  1690. Func TargetNextEnemy()
  1691.     Return PerformAction(0x95, 0x18)
  1692. EndFunc   ;==>TargetNextEnemy
  1693.  
  1694. ;~ Description: Target the next party member.
  1695. Func TargetPartyMember($aNumber)
  1696.     If $aNumber > 0 And $aNumber < 13 Then Return PerformAction(0x95 + $aNumber, 0x18)
  1697. EndFunc   ;==>TargetPartyMember
  1698.  
  1699. ;~ Description: Target the previous enemy.
  1700. Func TargetPreviousEnemy()
  1701.     Return PerformAction(0x9E, 0x18)
  1702. EndFunc   ;==>TargetPreviousEnemy
  1703.  
  1704. ;~ Description: Target the called target.
  1705. Func TargetCalledTarget()
  1706.     Return PerformAction(0x9F, 0x18)
  1707. EndFunc   ;==>TargetCalledTarget
  1708.  
  1709. ;~ Description: Target yourself.
  1710. Func TargetSelf()
  1711.     Return PerformAction(0xA0, 0x18)
  1712. EndFunc   ;==>TargetSelf
  1713.  
  1714. ;~ Description: Target the nearest ally.
  1715. Func TargetNearestAlly()
  1716.     Return PerformAction(0xBC, 0x18)
  1717. EndFunc   ;==>TargetNearestAlly
  1718.  
  1719. ;~ Description: Target the nearest item.
  1720. Func TargetNearestItem()
  1721.     Return PerformAction(0xC3, 0x18)
  1722. EndFunc   ;==>TargetNearestItem
  1723.  
  1724. ;~ Description: Target the next item.
  1725. Func TargetNextItem()
  1726.     Return PerformAction(0xC4, 0x18)
  1727. EndFunc   ;==>TargetNextItem
  1728.  
  1729. ;~ Description: Target the previous item.
  1730. Func TargetPreviousItem()
  1731.     Return PerformAction(0xC5, 0x18)
  1732. EndFunc   ;==>TargetPreviousItem
  1733.  
  1734. ;~ Description: Target the next party member.
  1735. Func TargetNextPartyMember()
  1736.     Return PerformAction(0xCA, 0x18)
  1737. EndFunc   ;==>TargetNextPartyMember
  1738.  
  1739. ;~ Description: Target the previous party member.
  1740. Func TargetPreviousPartyMember()
  1741.     Return PerformAction(0xCB, 0x18)
  1742. EndFunc   ;==>TargetPreviousPartyMember
  1743. #EndRegion Targeting
  1744.  
  1745. #Region Display
  1746. ;~ Description: Enable graphics rendering.
  1747. Func EnableRendering()
  1748.     MemoryWrite($mDisableRendering, 0)
  1749. EndFunc   ;==>EnableRendering
  1750.  
  1751. ;~ Description: Disable graphics rendering.
  1752. Func DisableRendering()
  1753.     MemoryWrite($mDisableRendering, 1)
  1754. EndFunc   ;==>DisableRendering
  1755.  
  1756. ;~ Description: Display all names.
  1757. Func DisplayAll($aDisplay)
  1758.     DisplayAllies($aDisplay)
  1759.     DisplayEnemies($aDisplay)
  1760. EndFunc   ;==>DisplayAll
  1761.  
  1762. ;~ Description: Display the names of allies.
  1763. Func DisplayAllies($aDisplay)
  1764.     If $aDisplay Then
  1765.         Return PerformAction(0x89, 0x18)
  1766.     Else
  1767.         Return PerformAction(0x89, 0x1A)
  1768.     EndIf
  1769. EndFunc   ;==>DisplayAllies
  1770.  
  1771. ;~ Description: Display the names of enemies.
  1772. Func DisplayEnemies($aDisplay)
  1773.     If $aDisplay Then
  1774.         Return PerformAction(0x94, 0x18)
  1775.     Else
  1776.         Return PerformAction(0x94, 0x1A)
  1777.     EndIf
  1778. EndFunc   ;==>DisplayEnemies
  1779. #EndRegion Display
  1780.  
  1781. #Region Chat
  1782. ;~ Description: Write a message in chat (can only be seen by botter).
  1783. Func WriteChat($aMessage, $aSender = 'GWA2')
  1784.     Local $lMessage, $lSender
  1785.     Local $lAddress = 256 * $mQueueCounter + $mQueueBase
  1786.  
  1787.     If $mQueueCounter = $mQueueSize Then
  1788.         $mQueueCounter = 0
  1789.     Else
  1790.         $mQueueCounter = $mQueueCounter + 1
  1791.     EndIf
  1792.  
  1793.     If StringLen($aSender) > 19 Then
  1794.         $lSender = StringLeft($aSender, 19)
  1795.     Else
  1796.         $lSender = $aSender
  1797.     EndIf
  1798.  
  1799.     MemoryWrite($lAddress + 4, $lSender, 'wchar[20]')
  1800.  
  1801.     If StringLen($aMessage) > 100 Then
  1802.         $lMessage = StringLeft($aMessage, 100)
  1803.     Else
  1804.         $lMessage = $aMessage
  1805.     EndIf
  1806.  
  1807.     MemoryWrite($lAddress + 44, $lMessage, 'wchar[101]')
  1808.     DllCall($mKernelHandle, 'int', 'WriteProcessMemory', 'int', $mGWProcHandle, 'int', $lAddress, 'ptr', $mWriteChatPtr, 'int', 4, 'int', '')
  1809.  
  1810.     If StringLen($aMessage) > 100 Then WriteChat(StringTrimLeft($aMessage, 100), $aSender)
  1811. EndFunc   ;==>WriteChat
  1812.  
  1813. ;~ Description: Send a whisper to another player.
  1814. Func SendWhisper($aReceiver, $aMessage)
  1815.     Local $lTotal = 'whisper ' & $aReceiver & ',' & $aMessage
  1816.     Local $lMessage
  1817.  
  1818.     If StringLen($lTotal) > 120 Then
  1819.         $lMessage = StringLeft($lTotal, 120)
  1820.     Else
  1821.         $lMessage = $lTotal
  1822.     EndIf
  1823.  
  1824.     SendChat($lMessage, '/')
  1825.  
  1826.     If StringLen($lTotal) > 120 Then SendWhisper($aReceiver, StringTrimLeft($lTotal, 120))
  1827. EndFunc   ;==>SendWhisper
  1828.  
  1829. ;~ Description: Send a message to chat.
  1830. Func SendChat($aMessage, $aChannel = '!')
  1831.     Local $lMessage
  1832.     Local $lAddress = 256 * $mQueueCounter + $mQueueBase
  1833.  
  1834.     If $mQueueCounter = $mQueueSize Then
  1835.         $mQueueCounter = 0
  1836.     Else
  1837.         $mQueueCounter = $mQueueCounter + 1
  1838.     EndIf
  1839.  
  1840.     If StringLen($aMessage) > 120 Then
  1841.         $lMessage = StringLeft($aMessage, 120)
  1842.     Else
  1843.         $lMessage = $aMessage
  1844.     EndIf
  1845.  
  1846.     ;MemoryWrite($lAddress + 8, $aChannel & $lMessage, 'wchar[122]')
  1847.     MemoryWrite($lAddress + 12, $aChannel & $lMessage, 'wchar[122]')
  1848.     DllCall($mKernelHandle, 'int', 'WriteProcessMemory', 'int', $mGWProcHandle, 'int', $lAddress, 'ptr', $mSendChatPtr, 'int', 8, 'int', '')
  1849.  
  1850.     If StringLen($aMessage) > 120 Then SendChat(StringTrimLeft($aMessage, 120), $aChannel)
  1851. EndFunc   ;==>SendChat
  1852. #EndRegion Chat
  1853.  
  1854. #Region Misc
  1855. ;~ Description: Change weapon sets.
  1856. Func ChangeWeaponSet($aSet)
  1857.     Return PerformAction(0x8 + $aSet, 0x38 )
  1858. EndFunc   ;==>ChangeWeaponSet
  1859.  
  1860. ;~ Description: Use a skill.
  1861. Func UseSkill($aSkillSlot, $aTarget = 0, $aCallTarget = False)
  1862.     Local $lTargetID
  1863.  
  1864.     If IsDllStruct($aTarget) = 0 Then
  1865.         $lTargetID = ConvertID($aTarget)
  1866.     Else
  1867.         $lTargetID = DllStructGetData($aTarget, 'ID')
  1868.     EndIf
  1869.  
  1870.     DllStructSetData($mUseSkill, 2, $aSkillSlot)
  1871.     DllStructSetData($mUseSkill, 3, $lTargetID)
  1872.     DllStructSetData($mUseSkill, 4, $aCallTarget)
  1873.     Enqueue($mUseSkillPtr, 16)
  1874. EndFunc   ;==>UseSkill
  1875.  
  1876. ;~ Description: Cancel current action.
  1877. Func CancelAction()
  1878.     Return SendPacket(0x4, $HEADER_CANCEL_ACTION)
  1879. EndFunc   ;==>CancelAction
  1880.  
  1881. ;~ Description: Same as hitting spacebar.
  1882. Func ActionInteract()
  1883.     Return PerformAction(0x80, 0x18)
  1884. EndFunc   ;==>ActionInteract
  1885.  
  1886. ;~ Description: Follow a player.
  1887. Func ActionFollow()
  1888.     Return PerformAction(0xCC, 0x18)
  1889. EndFunc   ;==>ActionFollow
  1890.  
  1891. ;~ Description: Drop environment object.
  1892. Func DropBundle()
  1893.     Return PerformAction(0xCD, 0x18)
  1894. EndFunc   ;==>DropBundle
  1895.  
  1896. ;~ Description: Clear all hero flags.
  1897. Func ClearPartyCommands()
  1898.     Return PerformAction(0xDB, 0x18)
  1899. EndFunc   ;==>ClearPartyCommands
  1900.  
  1901. ;~ Description: Suppress action.
  1902. Func SuppressAction($aSuppress)
  1903.     If $aSuppress Then
  1904.         Return PerformAction(0xD0, 0x18)
  1905.     Else
  1906.         Return PerformAction(0xD0, 0x1A)
  1907.     EndIf
  1908. EndFunc   ;==>SuppressAction
  1909.  
  1910. ;~ Description: Open a chest.
  1911. Func OpenChest()
  1912.     Return SendPacket(0x8, $HEADER_CHEST_OPEN, 2)
  1913. EndFunc   ;==>OpenChest
  1914.  
  1915. ;~ Description: Stop maintaining enchantment on target.
  1916. Func DropBuff($aSkillID, $aAgentID, $aHeroNumber = 0)
  1917.     Local $lBuffStruct = DllStructCreate('long SkillId;byte unknown1[4];long BuffId;long TargetId')
  1918.     Local $lBuffCount = GetBuffCount($aHeroNumber)
  1919.     Local $lBuffStructAddress
  1920.     Local $lOffset[4]
  1921.     $lOffset[0] = 0
  1922.     $lOffset[1] = 0x18
  1923.     $lOffset[2] = 0x2C
  1924.     $lOffset[3] = 0x510
  1925.     Local $lCount = MemoryReadPtr($mBasePointer, $lOffset)
  1926.     ReDim $lOffset[5]
  1927.     $lOffset[3] = 0x508
  1928.     Local $lBuffer
  1929.     For $i = 0 To $lCount[1] - 1
  1930.         $lOffset[4] = 0x24 * $i
  1931.         $lBuffer = MemoryReadPtr($mBasePointer, $lOffset)
  1932.         If $lBuffer[1] == GetHeroID($aHeroNumber) Then
  1933.             $lOffset[4] = 0x4 + 0x24 * $i
  1934.             ReDim $lOffset[6]
  1935.             For $j = 0 To $lBuffCount - 1
  1936.                 $lOffset[5] = 0 + 0x10 * $j
  1937.                 $lBuffStructAddress = MemoryReadPtr($mBasePointer, $lOffset)
  1938.                 DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lBuffStructAddress[0], 'ptr', DllStructGetPtr($lBuffStruct), 'int', DllStructGetSize($lBuffStruct), 'int', '')
  1939.                 If (DllStructGetData($lBuffStruct, 'SkillID') == $aSkillID) And (DllStructGetData($lBuffStruct, 'TargetId') == ConvertID($aAgentID)) Then
  1940.                     Return SendPacket(0x8, $HEADER_STOP_MAINTAIN_ENCH, DllStructGetData($lBuffStruct, 'BuffId'))
  1941.                     ExitLoop 2
  1942.                 EndIf
  1943.             Next
  1944.         EndIf
  1945.     Next
  1946. EndFunc   ;==>DropBuff
  1947.  
  1948. ;~ Description: Take a screenshot.
  1949. Func MakeScreenshot()
  1950.     Return PerformAction(0xAE, 0x18)
  1951. EndFunc   ;==>MakeScreenshot
  1952.  
  1953. ;~ Description: Invite a player to the party.
  1954. Func InvitePlayer($aPlayerName)
  1955.     SendChat('invite ' & $aPlayerName, '/')
  1956. EndFunc   ;==>InvitePlayer
  1957.  
  1958. ;~ Description: Leave your party.
  1959. Func LeaveGroup($aKickHeroes = True)
  1960.     If $aKickHeroes Then KickAllHeroes()
  1961.     Return SendPacket(0x4, $HEADER_PARTY_LEAVE)
  1962. EndFunc   ;==>LeaveGroup
  1963.  
  1964. ;~ Description: Switches to/from Hard Mode.
  1965. Func SwitchMode($aMode)
  1966.     Return SendPacket(0x8, $HEADER_MODE_SWITCH, $aMode)
  1967. EndFunc   ;==>SwitchMode
  1968.  
  1969. ;~ Description: Resign.
  1970. Func Resign()
  1971.     SendChat('resign', '/')
  1972. EndFunc   ;==>Resign
  1973.  
  1974. ;~ Description: Donate Kurzick or Luxon faction.
  1975. Func DonateFaction($aFaction)
  1976.     If StringLeft($aFaction, 1) = 'k' Then
  1977.         Return SendPacket(0x10, $HEADER_FACTION_DONATE, 0, 0, 0x1388)
  1978.     ElseIf StringLeft($aFaction, 1) = 'l' Then
  1979.         Return SendPacket(0x10, $HEADER_FACTION_DONATE, 0, 1, 0x1388)
  1980.     EndIf
  1981. EndFunc   ;==>DonateFaction
  1982.  
  1983. ;~ Description: Open a dialog.
  1984. Func Dialog($aDialogID)
  1985.     Return SendPacket(0x8, $HEADER_DIALOG, $aDialogID)
  1986. EndFunc   ;==>Dialog
  1987.  
  1988. ;~ Description: Skip a cinematic.
  1989. Func SkipCinematic()
  1990.     Return SendPacket(0x4, $HEADER_CINEMATIC_SKIP)
  1991. EndFunc   ;==>SkipCinematic
  1992.  
  1993. ;~ Description: Change a skill on the skillbar.
  1994. Func SetSkillbarSkill($aSlot, $aSkillID, $aHeroNumber = 0)
  1995.     Return SendPacket(0x14, $HEADER_SKILL_CHANGE, GetHeroID($aHeroNumber), $aSlot - 1, $aSkillID, 0)
  1996. EndFunc   ;==>SetSkillbarSkill
  1997.  
  1998. ;~ Description: Load all skills onto a skillbar simultaneously.
  1999. Func LoadSkillBar($aSkill1 = 0, $aSkill2 = 0, $aSkill3 = 0, $aSkill4 = 0, $aSkill5 = 0, $aSkill6 = 0, $aSkill7 = 0, $aSkill8 = 0, $aHeroNumber = 0)
  2000.     SendPacket(0x2C, $HEADER_BUILD_LOAD, GetHeroID($aHeroNumber), 8, $aSkill1, $aSkill2, $aSkill3, $aSkill4, $aSkill5, $aSkill6, $aSkill7, $aSkill8)
  2001. EndFunc   ;==>LoadSkillBar
  2002.  
  2003. ;~ Description: Loads skill template code.
  2004. Func LoadSkillTemplate($aTemplate, $aHeroNumber = 0)
  2005.     Local $lHeroID = GetHeroID($aHeroNumber)
  2006.     Local $lSplitTemplate = StringSplit($aTemplate, "")
  2007.     Local $lAttributeStr = ""
  2008.     Local $lAttributeLevelStr = ""
  2009.     Local $lTemplateType ; 4 Bits
  2010.     Local $lVersionNumber ; 4 Bits
  2011.     Local $lProfBits ; 2 Bits -> P
  2012.     Local $lProfPrimary ; P Bits
  2013.     Local $lProfSecondary ; P Bits
  2014.     Local $lAttributesCount ; 4 Bits
  2015.     Local $lAttributesBits ; 4 Bits -> A
  2016.     ;Local $lAttributes[1][2] ; A Bits + 4 Bits (for each Attribute)
  2017.     Local $lSkillsBits ; 4 Bits -> S
  2018.     Local $lSkills[8] ; S Bits * 8
  2019.     Local $lOpTail ; 1 Bit
  2020.     $aTemplate = ""
  2021.     For $i = 1 To $lSplitTemplate[0]
  2022.         $aTemplate &= Base64ToBin64($lSplitTemplate[$i])
  2023.     Next
  2024.     $lTemplateType = Bin64ToDec(StringLeft($aTemplate, 4))
  2025.     $aTemplate = StringTrimLeft($aTemplate, 4)
  2026.     If $lTemplateType <> 14 Then Return False
  2027.     $lVersionNumber = Bin64ToDec(StringLeft($aTemplate, 4))
  2028.     $aTemplate = StringTrimLeft($aTemplate, 4)
  2029.     $lProfBits = Bin64ToDec(StringLeft($aTemplate, 2)) * 2 + 4
  2030.     $aTemplate = StringTrimLeft($aTemplate, 2)
  2031.     $lProfPrimary = Bin64ToDec(StringLeft($aTemplate, $lProfBits))
  2032.     $aTemplate = StringTrimLeft($aTemplate, $lProfBits)
  2033.     If $lProfPrimary <> GetHeroProfession($aHeroNumber) Then Return False
  2034.     $lProfSecondary = Bin64ToDec(StringLeft($aTemplate, $lProfBits))
  2035.     $aTemplate = StringTrimLeft($aTemplate, $lProfBits)
  2036.     $lAttributesCount = Bin64ToDec(StringLeft($aTemplate, 4))
  2037.     $aTemplate = StringTrimLeft($aTemplate, 4)
  2038.     $lAttributesBits = Bin64ToDec(StringLeft($aTemplate, 4)) + 4
  2039.     $aTemplate = StringTrimLeft($aTemplate, 4)
  2040.     For $i = 1 To $lAttributesCount
  2041.         ;Attribute ID
  2042.         $lAttributeStr &= Bin64ToDec(StringLeft($aTemplate, $lAttributesBits))
  2043.         If $i <> $lAttributesCount Then $lAttributeStr &= "|"
  2044.         $aTemplate = StringTrimLeft($aTemplate, $lAttributesBits)
  2045.         ;Attribute level of above ID
  2046.         $lAttributeLevelStr &= Bin64ToDec(StringLeft($aTemplate, 4))
  2047.         If $i <> $lAttributesCount Then $lAttributeLevelStr &= "|"
  2048.         $aTemplate = StringTrimLeft($aTemplate, 4)
  2049.     Next
  2050.     $lSkillsBits = Bin64ToDec(StringLeft($aTemplate, 4)) + 8
  2051.     $aTemplate = StringTrimLeft($aTemplate, 4)
  2052.     For $i = 0 To 7
  2053.         $lSkills[$i] = Bin64ToDec(StringLeft($aTemplate, $lSkillsBits))
  2054.         $aTemplate = StringTrimLeft($aTemplate, $lSkillsBits)
  2055.     Next
  2056.     $lOpTail = Bin64ToDec($aTemplate)
  2057.     ChangeSecondProfession($lProfSecondary, $aHeroNumber)
  2058.     SetAttributes($lAttributeStr, $lAttributeLevelStr, $aHeroNumber)
  2059.     LoadSkillBar($lSkills[0], $lSkills[1], $lSkills[2], $lSkills[3], $lSkills[4], $lSkills[5], $lSkills[6], $lSkills[7], $aHeroNumber)
  2060. EndFunc   ;==>LoadSkillTemplate
  2061.  
  2062. ;~ Description: Set attributes to the given values
  2063. Func SetAttributes($fAttsID, $fAttsLevel, $aHeroNumber = 0)
  2064.    Local $lAttsID = StringSplit(String($fAttsID), "|")
  2065.    Local $lAttsLevel = StringSplit(String($fAttsLevel), "|")
  2066.  
  2067.    DllStructSetData($mSetAttributes, 4, GetHeroID($aHeroNumber))
  2068.    DllStructSetData($mSetAttributes, 5, $lAttsID[0]) ;# of attributes
  2069.    DllStructSetData($mSetAttributes, 22, $lAttsID[0]) ;# of attributes
  2070.  
  2071.    For $i = 1 To $lAttsID[0]
  2072.       DllStructSetData($mSetAttributes, 5 + $i, $lAttsID[$i]) ;ID ofAttributes
  2073.    Next
  2074.  
  2075.    For $i = 1 To $lAttsLevel[0]
  2076.       DllStructSetData($mSetAttributes, 22 + $i, $lAttsLevel[$i]) ;Attribute Levels
  2077.    Next
  2078.  
  2079.    Enqueue($mSetAttributesPtr, 152)
  2080. EndFunc   ;==>SetAttributes
  2081.  
  2082. ;~ Description: Change your secondary profession.
  2083. Func ChangeSecondProfession($aProfession, $aHeroNumber = 0)
  2084.     Return SendPacket(0xC, $HEADER_CHANGE_SECONDARY, GetHeroID($aHeroNumber), $aProfession)
  2085. EndFunc   ;==>ChangeSecondProfession
  2086.  
  2087. ;~ Description: Sets value of GetMapIsLoaded() to 0.
  2088. Func InitMapLoad()
  2089.     MemoryWrite($mMapIsLoaded, 0)
  2090. EndFunc   ;==>InitMapLoad
  2091.  
  2092. ;~ Description: Changes game language to english.
  2093. Func EnsureEnglish($aEnsure)
  2094.     If $aEnsure Then
  2095.         MemoryWrite($mEnsureEnglish, 1)
  2096.     Else
  2097.         MemoryWrite($mEnsureEnglish, 0)
  2098.     EndIf
  2099. EndFunc   ;==>EnsureEnglish
  2100.  
  2101. ;~ Description: Change game language.
  2102. Func ToggleLanguage()
  2103.     DllStructSetData($mToggleLanguage, 2, 0x18)
  2104.     Enqueue($mToggleLanguagePtr, 8)
  2105. EndFunc   ;==>ToggleLanguage
  2106.  
  2107. ;~ Description: Changes the maximum distance you can zoom out.
  2108. Func ChangeMaxZoom($aZoom = 750)
  2109.     MemoryWrite($mZoomStill, $aZoom, "float")
  2110.     MemoryWrite($mZoomMoving, $aZoom, "float")
  2111. EndFunc   ;==>ChangeMaxZoom
  2112.  
  2113. ;~ Description: Emptys Guild Wars client memory
  2114. Func ClearMemory()
  2115.     DllCall($mKernelHandle, 'int', 'SetProcessWorkingSetSize', 'int', $mGWProcHandle, 'int', -1, 'int', -1)
  2116. EndFunc   ;==>ClearMemory
  2117.  
  2118. ;~ Description: Changes the maximum memory Guild Wars can use.
  2119. Func SetMaxMemory($aMemory = 157286400)
  2120.     DllCall($mKernelHandle, 'int', 'SetProcessWorkingSetSizeEx', 'int', $mGWProcHandle, 'int', 1, 'int', $aMemory, 'int', 6)
  2121. EndFunc   ;==>SetMaxMemory
  2122. #EndRegion Misc
  2123.  
  2124. #Region Online Status
  2125.  ;~ Description: Change online status. 0 = Offline, 1 = Online, 2 = Do not disturb, 3 = Away
  2126.  Func SetPlayerStatus($iStatus)
  2127.     If (($iStatus >= 0 And $iStatus <= 3) And (GetPlayerStatus() <> $iStatus)) Then
  2128.         DllStructSetData($mChangeStatus, 2, $iStatus)
  2129.  
  2130.         Enqueue($mChangeStatusPtr, 8)
  2131.         Return True
  2132.     Else
  2133.         Return False
  2134.     EndIf
  2135. EndFunc   ;==>SetPlayerStatus
  2136.  
  2137. Func GetPlayerStatus()
  2138.        Return MemoryRead($mCurrentStatus)
  2139.  EndFunc   ;==>GetPlayerStatus
  2140. #EndRegion Online Status
  2141.  
  2142. ;~ Description: Internal use only.
  2143. Func Enqueue($aPtr, $aSize)
  2144.     DllCall($mKernelHandle, 'int', 'WriteProcessMemory', 'int', $mGWProcHandle, 'int', 256 * $mQueueCounter + $mQueueBase, 'ptr', $aPtr, 'int', $aSize, 'int', '')
  2145.     If $mQueueCounter = $mQueueSize Then
  2146.         $mQueueCounter = 0
  2147.     Else
  2148.         $mQueueCounter = $mQueueCounter + 1
  2149.     EndIf
  2150. EndFunc   ;==>Enqueue
  2151.  
  2152. ;~ Description: Converts float to integer.
  2153. Func FloatToInt($nFloat)
  2154.     Local $tFloat = DllStructCreate("float")
  2155.     Local $tInt = DllStructCreate("int", DllStructGetPtr($tFloat))
  2156.     DllStructSetData($tFloat, 1, $nFloat)
  2157.     Return DllStructGetData($tInt, 1)
  2158. EndFunc   ;==>FloatToInt
  2159. #EndRegion Commands
  2160.  
  2161. #Region Queries
  2162. #Region Titles
  2163. ;~ Description: Returns Hero title progress.
  2164. Func GetHeroTitle()
  2165.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x4]
  2166.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2167.     Return $lReturn[1]
  2168. EndFunc   ;==>GetHeroTitle
  2169.  
  2170. ;~ Description: Returns Gladiator title progress.
  2171. Func GetGladiatorTitle()
  2172.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x7C]
  2173.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2174.     Return $lReturn[1]
  2175. EndFunc   ;==>GetGladiatorTitle
  2176.  
  2177. ;~ Description: Returns Kurzick title progress.
  2178. Func GetKurzickTitle()
  2179.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0xCC]
  2180.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2181.     Return $lReturn[1]
  2182. EndFunc   ;==>GetKurzickTitle
  2183.  
  2184. ;~ Description: Returns Luxon title progress.
  2185. Func GetLuxonTitle()
  2186.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0xF4]
  2187.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2188.     Return $lReturn[1]
  2189. EndFunc   ;==>GetLuxonTitle
  2190.  
  2191. ;~ Description: Returns drunkard title progress.
  2192. Func GetDrunkardTitle()
  2193.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x11C]
  2194.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2195.     Return $lReturn[1]
  2196. EndFunc   ;==>GetDrunkardTitle
  2197.  
  2198. ;~ Description: Returns survivor title progress.
  2199. Func GetSurvivorTitle()
  2200.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x16C]
  2201.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2202.     Return $lReturn[1]
  2203. EndFunc   ;==>GetSurvivorTitle
  2204.  
  2205. ;~ Description: Returns max titles
  2206. Func GetMaxTitles()
  2207.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x194]
  2208.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2209.     Return $lReturn[1]
  2210. EndFunc   ;==>GetMaxTitles
  2211.  
  2212. ;~ Description: Returns lucky title progress.
  2213. Func GetLuckyTitle()
  2214.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x25C]
  2215.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2216.     Return $lReturn[1]
  2217. EndFunc   ;==>GetLuckyTitle
  2218.  
  2219. ;~ Description: Returns unlucky title progress.
  2220. Func GetUnluckyTitle()
  2221.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x284]
  2222.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2223.     Return $lReturn[1]
  2224. EndFunc   ;==>GetUnluckyTitle
  2225.  
  2226. ;~ Description: Returns Sunspear title progress.
  2227. Func GetSunspearTitle()
  2228.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x2AC]
  2229.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2230.     Return $lReturn[1]
  2231. EndFunc   ;==>GetSunspearTitle
  2232.  
  2233. ;~ Description: Returns Lightbringer title progress.
  2234. Func GetLightbringerTitle()
  2235.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x324]
  2236.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2237.     Return $lReturn[1]
  2238. EndFunc   ;==>GetLightbringerTitle
  2239.  
  2240. ;~ Description: Returns Commander title progress.
  2241. Func GetCommanderTitle()
  2242.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x374]
  2243.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2244.     Return $lReturn[1]
  2245. EndFunc   ;==>GetCommanderTitle
  2246.  
  2247. ;~ Description: Returns Gamer title progress.
  2248. Func GetGamerTitle()
  2249.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x39C]
  2250.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2251.     Return $lReturn[1]
  2252. EndFunc   ;==>GetGamerTitle
  2253.  
  2254. ;~ Description: Returns Legendary Guardian title progress.
  2255. Func GetLegendaryGuardianTitle()
  2256.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x4DC]
  2257.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2258.     Return $lReturn[1]
  2259. EndFunc   ;==>GetLegendaryGuardianTitle
  2260.  
  2261. ;~ Description: Returns sweets title progress.
  2262. Func GetSweetTitle()
  2263.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x554]
  2264.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2265.     Return $lReturn[1]
  2266. EndFunc   ;==>GetSweetTitle
  2267.  
  2268. ;~ Description: Returns Asura title progress.
  2269. Func GetAsuraTitle()
  2270.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x5F4]
  2271.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2272.     Return $lReturn[1]
  2273. EndFunc   ;==>GetAsuraTitle
  2274.  
  2275. ;~ Description: Returns Deldrimor title progress.
  2276. Func GetDeldrimorTitle()
  2277.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x61C]
  2278.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2279.     Return $lReturn[1]
  2280. EndFunc   ;==>GetDeldrimorTitle
  2281.  
  2282. ;~ Description: Returns Vanguard title progress.
  2283. Func GetVanguardTitle()
  2284.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x644]
  2285.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2286.     Return $lReturn[1]
  2287. EndFunc   ;==>GetVanguardTitle
  2288.  
  2289. ;~ Description: Returns Norn title progress.
  2290. Func GetNornTitle()
  2291.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x66C]
  2292.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2293.     Return $lReturn[1]
  2294. EndFunc   ;==>GetNornTitle
  2295.  
  2296. ;~ Description: Returns mastery of the north title progress.
  2297. Func GetNorthMasteryTitle()
  2298.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x694]
  2299.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2300.     Return $lReturn[1]
  2301. EndFunc   ;==>GetNorthMasteryTitle
  2302.  
  2303. ;~ Description: Returns party title progress.
  2304. Func GetPartyTitle()
  2305.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x6BC]
  2306.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2307.     Return $lReturn[1]
  2308. EndFunc   ;==>GetPartyTitle
  2309.  
  2310. ;~ Description: Returns Zaishen title progress.
  2311. Func GetZaishenTitle()
  2312.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x6E4]
  2313.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2314.     Return $lReturn[1]
  2315. EndFunc   ;==>GetZaishenTitle
  2316.  
  2317. ;~ Description: Returns treasure hunter title progress.
  2318. Func GetTreasureTitle()
  2319.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x70C]
  2320.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2321.     Return $lReturn[1]
  2322. EndFunc   ;==>GetTreasureTitle
  2323.  
  2324. ;~ Description: Returns wisdom title progress.
  2325. Func GetWisdomTitle()
  2326.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x734]
  2327.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2328.     Return $lReturn[1]
  2329. EndFunc   ;==>GetWisdomTitle
  2330.  
  2331.  ;~ Description: Returns codex title progress.
  2332. Func GetCodexTitle()
  2333.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x81C, 0x75C] ;0x7B8 before apr20
  2334.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2335.     Return $lReturn[1]
  2336.  EndFunc   ;==>GetCodexTitle
  2337.  
  2338.  ;~ Description: Returns current Tournament points.
  2339. Func GetTournamentPoints()
  2340.     Local $lOffset[5] = [0 ,0x18, 0x2C, 0, 0x18]
  2341.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2342.     Return $lReturn[1]
  2343. EndFunc   ;==>GetTournamentPoints
  2344. #EndRegion Titles
  2345.  
  2346. #Region Faction
  2347. ;~ Description: Returns current Kurzick faction.
  2348. Func GetKurzickFaction()
  2349.     Local $lOffset[4] = [0, 0x18, 0x2C, 0x748]
  2350.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2351.     Return $lReturn[1]
  2352. EndFunc   ;==>GetKurzickFaction
  2353.  
  2354. ;~ Description: Returns max Kurzick faction.
  2355. Func GetMaxKurzickFaction()
  2356.     Local $lOffset[4] = [0, 0x18, 0x2C, 0x7B8]
  2357.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2358.     Return $lReturn[1]
  2359. EndFunc   ;==>GetMaxKurzickFaction
  2360.  
  2361. ;~ Description: Returns current Luxon faction.
  2362. Func GetLuxonFaction()
  2363.     Local $lOffset[4] = [0, 0x18, 0x2C, 0x758]
  2364.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2365.     Return $lReturn[1]
  2366. EndFunc   ;==>GetLuxonFaction
  2367.  
  2368. ;~ Description: Returns max Luxon faction.
  2369. Func GetMaxLuxonFaction()
  2370.     Local $lOffset[4] = [0, 0x18, 0x2C, 0x7BC]
  2371.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2372.     Return $lReturn[1]
  2373. EndFunc   ;==>GetMaxLuxonFaction
  2374.  
  2375. ;~ Description: Returns current Balthazar faction.
  2376. Func GetBalthazarFaction()
  2377.     Local $lOffset[4] = [0, 0x18, 0x2C, 0x798]
  2378.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2379.     Return $lReturn[1]
  2380. EndFunc   ;==>GetBalthazarFaction
  2381.  
  2382. ;~ Description: Returns max Balthazar faction.
  2383. Func GetMaxBalthazarFaction()
  2384.     Local $lOffset[4] = [0, 0x18, 0x2C, 0x7C0]
  2385.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2386.     Return $lReturn[1]
  2387. EndFunc   ;==>GetMaxBalthazarFaction
  2388.  
  2389. ;~ Description: Returns current Imperial faction.
  2390. Func GetImperialFaction()
  2391.     Local $lOffset[4] = [0, 0x18, 0x2C, 0x76C]
  2392.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2393.     Return $lReturn[1]
  2394. EndFunc   ;==>GetImperialFaction
  2395.  
  2396. ;~ Description: Returns max Imperial faction.
  2397. Func GetMaxImperialFaction()
  2398.     Local $lOffset[4] = [0, 0x18, 0x2C, 0x7C4]
  2399.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2400.     Return $lReturn[1]
  2401. EndFunc   ;==>GetMaxImperialFaction
  2402. #EndRegion Faction
  2403.  
  2404. #Region Item
  2405. ;~ Description: Returns rarity (name color) of an item.
  2406. Func GetRarity($aItem)
  2407.     If Not IsDllStruct($aItem) Then $aItem = GetItemByItemID($aItem)
  2408.     Local $lPtr = DllStructGetData($aItem, 'NameString')
  2409.     If $lPtr == 0 Then Return
  2410.     Return MemoryRead($lPtr, 'ushort')
  2411. EndFunc   ;==>GetRarity
  2412.  
  2413.  
  2414. ;~ Description: Returns if material is Rare.
  2415. Func GetIsRareMaterial($aItem)
  2416.     If Not IsDllStruct($aItem) Then $aItem = GetItemByItemID($aItem)
  2417.     If DllStructGetData($aItem, "Type") <> 11 Then Return False
  2418.     Return Not GetIsCommonMaterial($aItem)
  2419. EndFunc   ;==>GetIsRareMaterial
  2420.  
  2421. ;~ Description: Returns if material is Common.
  2422. Func GetIsCommonMaterial($aItem)
  2423.     If Not IsDllStruct($aItem) Then $aItem = GetItemByItemID($aItem)
  2424.     Return BitAND(DllStructGetData($aItem, "Interaction"), 0x20) <> 0
  2425. EndFunc   ;==>GetIsCommonMaterial
  2426.  
  2427. ;~ Description: Legacy function, use GetIsIdentified instead.
  2428. Func GetIsIDed($aItem)
  2429.     Return GetIsIdentified($aItem)
  2430. EndFunc   ;==>GetIsIDed
  2431.  
  2432. ;~ Description: Tests if an item is identified.
  2433. Func GetIsIdentified($aItem)
  2434.     If Not IsDllStruct($aItem) Then $aItem = GetItemByItemID($aItem)
  2435.     Return BitAND(DllStructGetData($aItem, 'interaction'), 1) > 0
  2436. EndFunc   ;==>GetIsIdentified
  2437.  
  2438.  
  2439. ;~ Description: Returns a weapon or shield's minimum required attribute.
  2440. Func GetItemReq($aItem)
  2441.     Local $lMod = GetModByIdentifier($aItem, "9827")
  2442.     Return $lMod[0]
  2443. EndFunc   ;==>GetItemReq
  2444.  
  2445. ;~ Description: Returns a weapon or shield's required attribute.
  2446. Func GetItemAttribute($aItem)
  2447.     Local $lMod = GetModByIdentifier($aItem, "9827")
  2448.     Return $lMod[1]
  2449. EndFunc   ;==>GetItemAttribute
  2450.  
  2451. ;~ Description: Returns an array of a the requested mod.
  2452. Func GetModByIdentifier($aItem, $aIdentifier)
  2453.     If Not IsDllStruct($aItem) Then $aItem = GetItemByItemID($aItem)
  2454.     Local $lReturn[2]
  2455.     Local $lString = StringTrimLeft(GetModStruct($aItem), 2)
  2456.     For $i = 0 To StringLen($lString) / 8 - 2
  2457.         If StringMid($lString, 8 * $i + 5, 4) == $aIdentifier Then
  2458.             $lReturn[0] = Int("0x" & StringMid($lString, 8 * $i + 1, 2))
  2459.             $lReturn[1] = Int("0x" & StringMid($lString, 8 * $i + 3, 2))
  2460.             ExitLoop
  2461.         EndIf
  2462.     Next
  2463.     Return $lReturn
  2464. EndFunc   ;==>GetModByIdentifier
  2465.  
  2466. ;~ Description: Returns modstruct of an item.
  2467. Func GetModStruct($aItem)
  2468.     If Not IsDllStruct($aItem) Then $aItem = GetItemByItemID($aItem)
  2469.     If DllStructGetData($aItem, 'modstruct') = 0 Then Return
  2470.     Return MemoryRead(DllStructGetData($aItem, 'modstruct'), 'Byte[' & DllStructGetData($aItem, 'modstructsize') * 4 & ']')
  2471. EndFunc   ;==>GetModStruct
  2472.  
  2473. ;~ Description: Tests if an item is assigned to you.
  2474. Func GetAssignedToMe($aAgent)
  2475.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  2476.     Return (DllStructGetData($aAgent, 'Owner') = GetMyID())
  2477. EndFunc   ;==>GetAssignedToMe
  2478.  
  2479. ;~ Description: Tests if you can pick up an item.
  2480. Func GetCanPickUp($aAgent)
  2481.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  2482.     If GetAssignedToMe($aAgent) Or DllStructGetData($aAgent, 'Owner') = 0 Then
  2483.         Return True
  2484.     Else
  2485.         Return False
  2486.     EndIf
  2487. EndFunc   ;==>GetCanPickUp
  2488.  
  2489. ;~ Description: Returns struct of an inventory bag.
  2490. Func GetBag($aBag)
  2491.     Local $lOffset[5] = [0, 0x18, 0x40, 0xF8, 0x4 * $aBag]
  2492.     Local $lBagStruct = DllStructCreate('byte unknown1[4];long index;long id;ptr containerItem;long ItemsCount;ptr bagArray;ptr itemArray;long fakeSlots;long slots')
  2493.     Local $lBagPtr = MemoryReadPtr($mBasePointer, $lOffset)
  2494.     If $lBagPtr[1] = 0 Then Return
  2495.     DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lBagPtr[1], 'ptr', DllStructGetPtr($lBagStruct), 'int', DllStructGetSize($lBagStruct), 'int', '')
  2496.     Return $lBagStruct
  2497. EndFunc   ;==>GetBag
  2498.  
  2499. ;~ Description: Returns item by slot.
  2500. Func GetItemBySlot($aBag, $aSlot)
  2501.     Local $lBag
  2502.  
  2503.     If IsDllStruct($aBag) = 0 Then
  2504.         $lBag = GetBag($aBag)
  2505.     Else
  2506.         $lBag = $aBag
  2507.     EndIf
  2508.  
  2509.     Local $lItemPtr = DllStructGetData($lBag, 'ItemArray')
  2510.     Local $lBuffer = DllStructCreate('ptr')
  2511.     Local $lItemStruct = DllStructCreate('long Id;long AgentId;byte Unknown1[4];ptr Bag;ptr ModStruct;long ModStructSize;ptr Customized;byte unknown2[4];byte Type;byte unknown4;short ExtraId;short Value;byte unknown4[2];short Interaction;long ModelId;ptr ModString;byte unknown5[4];ptr NameString;ptr SingleItemName;byte Unknown4[10];byte IsSalvageable;byte Unknown6;byte Quantity;byte Equiped;byte Profession;byte Type2;byte Slot')
  2512.     DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', DllStructGetData($lBag, 'ItemArray') + 4 * ($aSlot - 1), 'ptr', DllStructGetPtr($lBuffer), 'int', DllStructGetSize($lBuffer), 'int', '')
  2513.     DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', DllStructGetData($lBuffer, 1), 'ptr', DllStructGetPtr($lItemStruct), 'int', DllStructGetSize($lItemStruct), 'int', '')
  2514.     Return $lItemStruct
  2515. EndFunc   ;==>GetItemBySlot
  2516.  
  2517. ;~ Description: Returns item struct.
  2518. Func GetItemByItemID($aItemID)
  2519.     Local $lItemStruct = DllStructCreate('long Id;long AgentId;byte Unknown1[4];ptr Bag;ptr ModStruct;long ModStructSize;ptr Customized;byte unknown2[4];byte Type;byte unknown4;short ExtraId;short Value;byte unknown4[2];short Interaction;long ModelId;ptr ModString;byte unknown5[4];ptr NameString;ptr SingleItemName;byte Unknown4[10];byte IsSalvageable;byte Unknown6;byte Quantity;byte Equiped;byte Profession;byte Type2;byte Slot')
  2520.     Local $lOffset[5] = [0, 0x18, 0x40, 0xB8, 0x4 * $aItemID]
  2521.     Local $lItemPtr = MemoryReadPtr($mBasePointer, $lOffset)
  2522.     DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lItemPtr[1], 'ptr', DllStructGetPtr($lItemStruct), 'int', DllStructGetSize($lItemStruct), 'int', '')
  2523.     Return $lItemStruct
  2524. EndFunc   ;==>GetItemByItemID
  2525.  
  2526. ;~ Description: Returns item by agent ID.
  2527. Func GetItemByAgentID($aAgentID)
  2528.     Local $lItemStruct = DllStructCreate('long Id;long AgentId;byte Unknown1[4];ptr Bag;ptr ModStruct;long ModStructSize;ptr Customized;byte unknown2[4];byte Type;byte unknown4;short ExtraId;short Value;byte unknown4[2];short Interaction;long ModelId;ptr ModString;byte unknown5[4];ptr NameString;ptr SingleItemName;byte Unknown4[10];byte IsSalvageable;byte Unknown6;byte Quantity;byte Equiped;byte Profession;byte Type2;byte Slot')
  2529.     Local $lOffset[4] = [0, 0x18, 0x40, 0xC0]
  2530.     Local $lItemArraySize = MemoryReadPtr($mBasePointer, $lOffset)
  2531.     Local $lOffset[5] = [0, 0x18, 0x40, 0xB8, 0]
  2532.     Local $lItemPtr, $lItemID
  2533.     Local $lAgentID = ConvertID($aAgentID)
  2534.  
  2535.     For $lItemID = 1 To $lItemArraySize[1]
  2536.         $lOffset[4] = 0x4 * $lItemID
  2537.         $lItemPtr = MemoryReadPtr($mBasePointer, $lOffset)
  2538.         If $lItemPtr[1] = 0 Then ContinueLoop
  2539.  
  2540.         DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lItemPtr[1], 'ptr', DllStructGetPtr($lItemStruct), 'int', DllStructGetSize($lItemStruct), 'int', '')
  2541.         If DllStructGetData($lItemStruct, 'AgentID') = $lAgentID Then Return $lItemStruct
  2542.     Next
  2543. EndFunc   ;==>GetItemByAgentID
  2544.  
  2545. ;~ Description: Returns item by model ID.
  2546. Func GetItemByModelID($aModelID)
  2547.     Local $lItemStruct = DllStructCreate('long Id;long AgentId;byte Unknown1[4];ptr Bag;ptr ModStruct;long ModStructSize;ptr Customized;byte unknown2[4];byte Type;byte unknown4;short ExtraId;short Value;byte unknown4[2];short Interaction;long ModelId;ptr ModString;byte unknown5[4];ptr NameString;ptr SingleItemName;byte Unknown4[10];byte IsSalvageable;byte Unknown6;byte Quantity;byte Equiped;byte Profession;byte Type2;byte Slot')
  2548.     Local $lOffset[4] = [0, 0x18, 0x40, 0xC0]
  2549.     Local $lItemArraySize = MemoryReadPtr($mBasePointer, $lOffset)
  2550.     Local $lOffset[5] = [0, 0x18, 0x40, 0xB8, 0]
  2551.     Local $lItemPtr, $lItemID
  2552.  
  2553.     For $lItemID = 1 To $lItemArraySize[1]
  2554.         $lOffset[4] = 0x4 * $lItemID
  2555.         $lItemPtr = MemoryReadPtr($mBasePointer, $lOffset)
  2556.         If $lItemPtr[1] = 0 Then ContinueLoop
  2557.  
  2558.         DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lItemPtr[1], 'ptr', DllStructGetPtr($lItemStruct), 'int', DllStructGetSize($lItemStruct), 'int', '')
  2559.         If DllStructGetData($lItemStruct, 'ModelID') = $aModelID Then Return $lItemStruct
  2560.     Next
  2561. EndFunc   ;==>GetItemByModelID
  2562.  
  2563. ;~ Description: Returns amount of gold in storage.
  2564. Func GetGoldStorage()
  2565.     Local $lOffset[5] = [0, 0x18, 0x40, 0xF8, 0x94]
  2566.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2567.     Return $lReturn[1]
  2568. EndFunc   ;==>GetGoldStorage
  2569.  
  2570. ;~ Description: Returns amount of gold being carried.
  2571. Func GetGoldCharacter()
  2572.     Local $lOffset[5] = [0, 0x18, 0x40, 0xF8, 0x90]
  2573.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2574.     Return $lReturn[1]
  2575. EndFunc   ;==>GetGoldCharacter
  2576.  
  2577. ;~ Description: Returns item ID of salvage kit in inventory.
  2578. Func FindSalvageKit()
  2579.     Local $lItem
  2580.     Local $lKit = 0
  2581.     Local $lUses = 101
  2582.     For $i = 1 To 16
  2583.         For $j = 1 To DllStructGetData(GetBag($i), 'Slots')
  2584.             $lItem = GetItemBySlot($i, $j)
  2585.             Switch DllStructGetData($lItem, 'ModelID')
  2586.                 Case 2992
  2587.                     If DllStructGetData($lItem, 'Value') / 2 < $lUses Then
  2588.                         $lKit = DllStructGetData($lItem, 'ID')
  2589.                         $lUses = DllStructGetData($lItem, 'Value') / 2
  2590.                     EndIf
  2591.                         ContinueLoop
  2592.             EndSwitch
  2593.         Next
  2594.     Next
  2595.     Return $lKit
  2596. EndFunc   ;==>FindSalvageKit
  2597.  
  2598. ;~ Description: Returns item ID of expert salvage kit in inventory.
  2599. Func FindExpertSalvageKit()
  2600.     Local $lItem
  2601.     Local $lKit = 0
  2602.     Local $lUses = 101
  2603.     For $i = 1 To 4
  2604.         For $j = 1 To DllStructGetData(GetBag($i), 'Slots')
  2605.             $lItem = GetItemBySlot($i, $j)
  2606.             Switch DllStructGetData($lItem, 'ModelID')
  2607.                 Case 2991
  2608.                     If DllStructGetData($lItem, 'Value') / 8 < $lUses Then
  2609.                         $lKit = DllStructGetData($lItem, 'ID')
  2610.                         $lUses = DllStructGetData($lItem, 'Value') / 8
  2611.                     EndIf
  2612.                 Case 5900
  2613.                     If DllStructGetData($lItem, 'Value') / 10 < $lUses Then
  2614.                         $lKit = DllStructGetData($lItem, 'ID')
  2615.                         $lUses = DllStructGetData($lItem, 'Value') / 10
  2616.                     EndIf
  2617.                 Case Else
  2618.                     ContinueLoop
  2619.             EndSwitch
  2620.         Next
  2621.     Next
  2622.     Return $lKit
  2623. EndFunc   ;==>FindExpertSalvageKit
  2624.  
  2625. ;~ Description: Legacy function, use FindIdentificationKit instead.
  2626. Func FindIDKit()
  2627.     Return FindIdentificationKit()
  2628. EndFunc   ;==>FindIDKit
  2629.  
  2630. ;~ Description: Returns item ID of ID kit in inventory.
  2631. Func FindIdentificationKit()
  2632.     Local $lItem
  2633.     Local $lKit = 0
  2634.     Local $lUses = 101
  2635.     For $i = 1 To 4
  2636.         For $j = 1 To DllStructGetData(GetBag($i), 'Slots')
  2637.             $lItem = GetItemBySlot($i, $j)
  2638.             Switch DllStructGetData($lItem, 'ModelID')
  2639.                 Case 2989
  2640.                     If DllStructGetData($lItem, 'Value') / 2 < $lUses Then
  2641.                         $lKit = DllStructGetData($lItem, 'ID')
  2642.                         $lUses = DllStructGetData($lItem, 'Value') / 2
  2643.                     EndIf
  2644.                 Case 5899
  2645.                     If DllStructGetData($lItem, 'Value') / 2.5 < $lUses Then
  2646.                         $lKit = DllStructGetData($lItem, 'ID')
  2647.                         $lUses = DllStructGetData($lItem, 'Value') / 2.5
  2648.                     EndIf
  2649.                 Case Else
  2650.                     ContinueLoop
  2651.             EndSwitch
  2652.         Next
  2653.     Next
  2654.     Return $lKit
  2655. EndFunc   ;==>FindIdentificationKit
  2656.  
  2657. ;~ Description: Returns the item ID of the quoted item.
  2658. Func GetTraderCostID()
  2659.     Return MemoryRead($mTraderCostID)
  2660. EndFunc   ;==>GetTraderCostID
  2661.  
  2662. ;~ Description: Returns the cost of the requested item.
  2663. Func GetTraderCostValue()
  2664.     Return MemoryRead($mTraderCostValue)
  2665. EndFunc   ;==>GetTraderCostValue
  2666.  
  2667. ;~ Description: Internal use for BuyItem()
  2668. Func GetMerchantItemsBase()
  2669.     Local $lOffset[4] = [0, 0x18, 0x2C, 0x24]
  2670.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2671.     Return $lReturn[1]
  2672. EndFunc   ;==>GetMerchantItemsBase
  2673.  
  2674. ;~ Description: Internal use for BuyItem()
  2675. Func GetMerchantItemsSize()
  2676.     Local $lOffset[4] = [0, 0x18, 0x2C, 0x28]
  2677.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  2678.     Return $lReturn[1]
  2679. EndFunc   ;==>GetMerchantItemsSize
  2680. #EndRegion Item
  2681.  
  2682. #Region H&H
  2683. ;~ Description: Returns number of heroes you control.
  2684. Func GetHeroCount()
  2685.     Local $lOffset[5]
  2686.     $lOffset[0] = 0
  2687.     $lOffset[1] = 0x18
  2688.     $lOffset[2] = 0x4C
  2689.     $lOffset[3] = 0x54
  2690.     $lOffset[4] = 0x2C
  2691.     Local $lHeroCount = MemoryReadPtr($mBasePointer, $lOffset)
  2692.     Return $lHeroCount[1]
  2693. EndFunc   ;==>GetHeroCount
  2694.  
  2695. ;~ Description: Returns agent ID of a hero.
  2696. Func GetHeroID($aHeroNumber)
  2697.     If $aHeroNumber == 0 Then Return GetMyID()
  2698.     Local $lOffset[6]
  2699.     $lOffset[0] = 0
  2700.     $lOffset[1] = 0x18
  2701.     $lOffset[2] = 0x4C
  2702.     $lOffset[3] = 0x54
  2703.     $lOffset[4] = 0x24
  2704.     $lOffset[5] = 0x18 * ($aHeroNumber - 1)
  2705.     Local $lAgentID = MemoryReadPtr($mBasePointer, $lOffset)
  2706.     Return $lAgentID[1]
  2707. EndFunc   ;==>GetHeroID
  2708.  
  2709. ;~ Description: Returns hero number by agent ID.
  2710. Func GetHeroNumberByAgentID($aAgentID)
  2711.     Local $lAgentID
  2712.     Local $lOffset[6]
  2713.     $lOffset[0] = 0
  2714.     $lOffset[1] = 0x18
  2715.     $lOffset[2] = 0x4C
  2716.     $lOffset[3] = 0x54
  2717.     $lOffset[4] = 0x24
  2718.     For $i = 1 To GetHeroCount()
  2719.         $lOffset[5] = 0x18 * ($i - 1)
  2720.         $lAgentID = MemoryReadPtr($mBasePointer, $lOffset)
  2721.         If $lAgentID[1] == ConvertID($aAgentID) Then Return $i
  2722.     Next
  2723.     Return 0
  2724. EndFunc   ;==>GetHeroNumberByAgentID
  2725.  
  2726. ;~ Description: Returns hero number by hero ID.
  2727. Func GetHeroNumberByHeroID($aHeroId)
  2728.     Local $lAgentID
  2729.     Local $lOffset[6]
  2730.     $lOffset[0] = 0
  2731.     $lOffset[1] = 0x18
  2732.     $lOffset[2] = 0x4C
  2733.     $lOffset[3] = 0x54
  2734.     $lOffset[4] = 0x24
  2735.     For $i = 1 To GetHeroCount()
  2736.         $lOffset[5] = 8 + 0x18 * ($i - 1)
  2737.         $lAgentID = MemoryReadPtr($mBasePointer, $lOffset)
  2738.         If $lAgentID[1] == ConvertID($aHeroId) Then Return $i
  2739.     Next
  2740.     Return 0
  2741. EndFunc   ;==>GetHeroNumberByHeroID
  2742.  
  2743. ;~ Description: Returns hero's profession ID (when it can't be found by other means)
  2744. Func GetHeroProfession($aHeroNumber, $aSecondary = False)
  2745.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x6BC, 0]
  2746.     Local $lBuffer
  2747.     $aHeroNumber = GetHeroID($aHeroNumber)
  2748.     For $i = 0 To GetHeroCount()
  2749.         $lBuffer = MemoryReadPtr($mBasePointer, $lOffset)
  2750.         If $lBuffer[1] = $aHeroNumber Then
  2751.             $lOffset[4] += 4
  2752.             If $aSecondary Then $lOffset[4] += 4
  2753.             $lBuffer = MemoryReadPtr($mBasePointer, $lOffset)
  2754.             Return $lBuffer[1]
  2755.         EndIf
  2756.         $lOffset[4] += 0x14
  2757.     Next
  2758. EndFunc   ;==>GetHeroProfession
  2759.  
  2760. ;~ Description: Tests if a hero's skill slot is disabled.
  2761. Func GetIsHeroSkillSlotDisabled($aHeroNumber, $aSkillSlot)
  2762.     Return BitAND(2 ^ ($aSkillSlot - 1), DllStructGetData(GetSkillbar($aHeroNumber), 'Disabled')) > 0
  2763. EndFunc   ;==>GetIsHeroSkillSlotDisabled
  2764. #EndRegion H&H
  2765.  
  2766. #Region Agent
  2767. ;~ Description: Returns an agent struct.
  2768. Func GetAgentByID($aAgentID = -2)
  2769.     ;returns dll struct if successful
  2770.     Local $lAgentPtr = GetAgentPtr($aAgentID)
  2771.     If $lAgentPtr = 0 Then Return 0
  2772.     ;Offsets: 0x2C=AgentID 0x9C=Type 0xF4=PlayerNumber 0114=Energy Pips
  2773.     Local $lAgentStruct = DllStructCreate('ptr vtable;byte unknown1[24];byte unknown2[4];ptr NextAgent;byte unknown3[8];long Id;float Z;byte unknown4[8];float BoxHoverWidth;float BoxHoverHeight;byte unknown5[8];float Rotation;byte unknown6[8];long NameProperties;byte unknown7[24];float X;float Y;byte unknown8[8];float NameTagX;float NameTagY;float NameTagZ;byte unknown9[12];long Type;float MoveX;float MoveY;byte unknown10[28];long Owner;byte unknown30[8];long ExtraType;byte unknown11[24];float AttackSpeed;float AttackSpeedModifier;word PlayerNumber;byte unknown12[6];ptr Equip;byte unknown13[10];byte Primary;byte Secondary;byte Level;byte Team;byte unknown14[6];float EnergyPips;byte unknown[4];float EnergyPercent;long MaxEnergy;byte unknown15[4];float HPPips;byte unknown16[4];float HP;long MaxHP;long Effects;byte unknown17[4];byte Hex;byte unknown18[18];long ModelState;long TypeMap;byte unknown19[16];long InSpiritRange;byte unknown20[16];long LoginNumber;float ModelMode;byte unknown21[4];long ModelAnimation;byte unknown22[32];byte LastStrike;byte Allegiance;word WeaponType;word Skill;byte unknown23[4];word WeaponItemId;word OffhandItemId')
  2774.     DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lAgentPtr, 'ptr', DllStructGetPtr($lAgentStruct), 'int', DllStructGetSize($lAgentStruct), 'int', '')
  2775.     Return $lAgentStruct
  2776. EndFunc   ;==>GetAgentByID
  2777.  
  2778. ;~ Description: Internal use for GetAgentByID()
  2779. Func GetAgentPtr($aAgentID)
  2780.     Local $lOffset[3] = [0, 4 * ConvertID($aAgentID), 0]
  2781.     Local $lAgentStructAddress = MemoryReadPtr($mAgentBase, $lOffset)
  2782.     Return $lAgentStructAddress[0]
  2783. EndFunc   ;==>GetAgentPtr
  2784.  
  2785. ;~ Description: Test if an agent exists.
  2786. Func GetAgentExists($aAgentID = -2)
  2787.     Return (GetAgentPtr($aAgentID) > 0 And $aAgentID < GetMaxAgents())
  2788. EndFunc   ;==>GetAgentExists
  2789.  
  2790. ;~ Description: Returns the target of an agent.
  2791. Func GetTarget($aAgent = -2)
  2792.     Local $lAgentID
  2793.  
  2794.     If IsDllStruct($aAgent) = 0 Then
  2795.         $lAgentID = ConvertID($aAgent)
  2796.     Else
  2797.         $lAgentID = DllStructGetData($aAgent, 'ID')
  2798.     EndIf
  2799.  
  2800.     Return MemoryRead(GetValue('TargetLogBase') + 4 * $lAgentID)
  2801. EndFunc   ;==>GetTarget
  2802.  
  2803. ;~ Description: Returns agent by player name.
  2804. Func GetAgentByPlayerName($aPlayerName)
  2805.     For $i = 1 To GetMaxAgents()
  2806.         If GetPlayerName($i) = $aPlayerName Then
  2807.             Return GetAgentByID($i)
  2808.         EndIf
  2809.     Next
  2810. EndFunc   ;==>GetAgentByPlayerName
  2811.  
  2812. ;~ Description: Returns agent by name.
  2813. Func GetAgentByName($aName)
  2814.     Local $lName, $lAddress
  2815.  
  2816.     For $i = 1 To GetMaxAgents()
  2817.         $lAddress = $mStringLogBase + 256 * $i
  2818.         $lName = MemoryRead($lAddress, 'wchar [128]')
  2819.         $lName = StringRegExpReplace($lName, '[<]{1}([^>]+)[>]{1}', '')
  2820.         If StringInStr($lName, $aName) > 0 Then Return GetAgentByID($i)
  2821.     Next
  2822.  
  2823.     DisplayAll(True)
  2824.     Sleep(100)
  2825.     DisplayAll(False)
  2826.     DisplayAll(True)
  2827.     Sleep(100)
  2828.     DisplayAll(False)
  2829.  
  2830.     For $i = 1 To GetMaxAgents()
  2831.         $lAddress = $mStringLogBase + 256 * $i
  2832.         $lName = MemoryRead($lAddress, 'wchar [128]')
  2833.         $lName = StringRegExpReplace($lName, '[<]{1}([^>]+)[>]{1}', '')
  2834.         If StringInStr($lName, $aName) > 0 Then Return GetAgentByID($i)
  2835.     Next
  2836. EndFunc   ;==>GetAgentByName
  2837.  
  2838. ;~ Description: Returns the nearest agent to an agent.
  2839. Func GetNearestAgentToAgent($aAgent = -2)
  2840.     Local $lNearestAgent, $lNearestDistance = 100000000
  2841.     Local $lDistance
  2842.     Local $lAgentArray = GetAgentArray()
  2843.  
  2844.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  2845.  
  2846.     Local $lID = DllStructGetData($aAgent, 'ID')
  2847.  
  2848.     For $i = 1 To $lAgentArray[0]
  2849.         $lDistance = (DllStructGetData($aAgent, 'X') - DllStructGetData($lAgentArray[$i], 'X')) ^ 2 + (DllStructGetData($aAgent, 'Y') - DllStructGetData($lAgentArray[$i], 'Y')) ^ 2
  2850.  
  2851.         If $lDistance < $lNearestDistance Then
  2852.             If DllStructGetData($lAgentArray[$i], 'ID') == $lID Then ContinueLoop
  2853.             $lNearestAgent = $lAgentArray[$i]
  2854.             $lNearestDistance = $lDistance
  2855.         EndIf
  2856.     Next
  2857.  
  2858.     SetExtended(Sqrt($lNearestDistance))
  2859.     Return $lNearestAgent
  2860. EndFunc   ;==>GetNearestAgentToAgent
  2861.  
  2862. ;~ Description: Returns the nearest enemy to an agent.
  2863. Func GetNearestEnemyToAgent($aAgent = -2)
  2864.     Local $lNearestAgent, $lNearestDistance = 100000000
  2865.     Local $lDistance
  2866.     Local $lAgentArray = GetAgentArray(0xDB)
  2867.  
  2868.     If Not IsDllStruct($aAgent) Then $aAgent = GetAgentByID($aAgent)
  2869.  
  2870.     Local $lID = DllStructGetData($aAgent, 'ID')
  2871.  
  2872.     For $i = 1 To $lAgentArray[0]
  2873.         If DllStructGetData($lAgentArray[$i], 'Allegiance') <> 3 Then ContinueLoop
  2874.         If DllStructGetData($lAgentArray[$i], 'HP') <= 0 Then ContinueLoop
  2875.         If BitAND(DllStructGetData($lAgentArray[$i], 'Effects'), 0x0010) > 0 Then ContinueLoop
  2876.         $lDistance = (DllStructGetData($aAgent, 'X') - DllStructGetData($lAgentArray[$i], 'X')) ^ 2 + (DllStructGetData($aAgent, 'Y') - DllStructGetData($lAgentArray[$i], 'Y')) ^ 2
  2877.         If $lDistance < $lNearestDistance Then
  2878.             If DllStructGetData($lAgentArray[$i], 'ID') == $lID Then ContinueLoop
  2879.             $lNearestAgent = $lAgentArray[$i]
  2880.             $lNearestDistance = $lDistance
  2881.         EndIf
  2882.     Next
  2883.  
  2884.     SetExtended(Sqrt($lNearestDistance))
  2885.     Return $lNearestAgent
  2886. EndFunc   ;==>GetNearestEnemyToAgent
  2887.  
  2888. ;~ Description: Returns the nearest agent to a set of coordinates.
  2889. Func GetNearestAgentToCoords($aX, $aY)
  2890.     Local $lNearestAgent, $lNearestDistance = 100000000
  2891.     Local $lDistance
  2892.     Local $lAgentArray = GetAgentArray()
  2893.  
  2894.     For $i = 1 To $lAgentArray[0]
  2895.         $lDistance = ($aX - DllStructGetData($lAgentArray[$i], 'X')) ^ 2 + ($aY - DllStructGetData($lAgentArray[$i], 'Y')) ^ 2
  2896.         If $lDistance < $lNearestDistance Then
  2897.             $lNearestAgent = $lAgentArray[$i]
  2898.             $lNearestDistance = $lDistance
  2899.         EndIf
  2900.     Next
  2901.  
  2902.     SetExtended(Sqrt($lNearestDistance))
  2903.     Return $lNearestAgent
  2904. EndFunc   ;==>GetNearestAgentToCoords
  2905.  
  2906. ;~ Description: Returns the nearest signpost to an agent.
  2907. Func GetNearestSignpostToAgent($aAgent = -2)
  2908.     Local $lNearestAgent, $lNearestDistance = 100000000
  2909.     Local $lDistance
  2910.     Local $lAgentArray = GetAgentArray(0x200)
  2911.  
  2912.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  2913.  
  2914.     Local $lID = DllStructGetData($aAgent, 'ID')
  2915.  
  2916.     For $i = 1 To $lAgentArray[0]
  2917.         $lDistance = (DllStructGetData($lAgentArray[$i], 'Y') - DllStructGetData($aAgent, 'Y')) ^ 2 + (DllStructGetData($lAgentArray[$i], 'X') - DllStructGetData($aAgent, 'X')) ^ 2
  2918.         If $lDistance < $lNearestDistance Then
  2919.             If DllStructGetData($lAgentArray[$i], 'ID') == $lID Then ContinueLoop
  2920.             $lNearestAgent = $lAgentArray[$i]
  2921.             $lNearestDistance = $lDistance
  2922.         EndIf
  2923.     Next
  2924.  
  2925.     SetExtended(Sqrt($lNearestDistance))
  2926.     Return $lNearestAgent
  2927. EndFunc   ;==>GetNearestSignpostToAgent
  2928.  
  2929. ;~ Description: Returns the nearest signpost to a set of coordinates.
  2930. Func GetNearestSignpostToCoords($aX, $aY)
  2931.     Local $lNearestAgent, $lNearestDistance = 100000000
  2932.     Local $lDistance
  2933.     Local $lAgentArray = GetAgentArray(0x200)
  2934.  
  2935.     For $i = 1 To $lAgentArray[0]
  2936.         $lDistance = ($aX - DllStructGetData($lAgentArray[$i], 'X')) ^ 2 + ($aY - DllStructGetData($lAgentArray[$i], 'Y')) ^ 2
  2937.  
  2938.         If $lDistance < $lNearestDistance Then
  2939.             $lNearestAgent = $lAgentArray[$i]
  2940.             $lNearestDistance = $lDistance
  2941.         EndIf
  2942.     Next
  2943.  
  2944.     SetExtended(Sqrt($lNearestDistance))
  2945.     Return $lNearestAgent
  2946. EndFunc   ;==>GetNearestSignpostToCoords
  2947.  
  2948. ;~ Description: Returns the nearest NPC to an agent.
  2949. Func GetNearestNPCToAgent($aAgent = -2)
  2950.     Local $lNearestAgent, $lNearestDistance = 100000000
  2951.     Local $lDistance
  2952.     Local $lAgentArray = GetAgentArray(0xDB)
  2953.  
  2954.     If Not IsDllStruct($aAgent) Then $aAgent = GetAgentByID($aAgent)
  2955.  
  2956.     Local $lID = DllStructGetData($aAgent, 'ID')
  2957.  
  2958.     For $i = 1 To $lAgentArray[0]
  2959.         If DllStructGetData($lAgentArray[$i], 'Allegiance') <> 6 Then ContinueLoop
  2960.         If DllStructGetData($lAgentArray[$i], 'HP') <= 0 Then ContinueLoop
  2961.         If BitAND(DllStructGetData($lAgentArray[$i], 'Effects'), 0x0010) > 0 Then ContinueLoop
  2962.  
  2963.         $lDistance = (DllStructGetData($aAgent, 'X') - DllStructGetData($lAgentArray[$i], 'X')) ^ 2 + (DllStructGetData($aAgent, 'Y') - DllStructGetData($lAgentArray[$i], 'Y')) ^ 2
  2964.         If $lDistance < $lNearestDistance Then
  2965.             If DllStructGetData($lAgentArray[$i], 'ID') == $lID Then ContinueLoop
  2966.             $lNearestAgent = $lAgentArray[$i]
  2967.             $lNearestDistance = $lDistance
  2968.         EndIf
  2969.     Next
  2970.  
  2971.     SetExtended(Sqrt($lNearestDistance))
  2972.     Return $lNearestAgent
  2973. EndFunc   ;==>GetNearestNPCToAgent
  2974.  
  2975. ;~ Description: Returns the nearest NPC to a set of coordinates.
  2976. Func GetNearestNPCToCoords($aX, $aY)
  2977.     Local $lNearestAgent, $lNearestDistance = 100000000
  2978.     Local $lDistance
  2979.     Local $lAgentArray = GetAgentArray(0xDB)
  2980.  
  2981.     For $i = 1 To $lAgentArray[0]
  2982.         If DllStructGetData($lAgentArray[$i], 'Allegiance') <> 6 Then ContinueLoop
  2983.         If DllStructGetData($lAgentArray[$i], 'HP') <= 0 Then ContinueLoop
  2984.         If BitAND(DllStructGetData($lAgentArray[$i], 'Effects'), 0x0010) > 0 Then ContinueLoop
  2985.  
  2986.         $lDistance = ($aX - DllStructGetData($lAgentArray[$i], 'X')) ^ 2 + ($aY - DllStructGetData($lAgentArray[$i], 'Y')) ^ 2
  2987.  
  2988.         If $lDistance < $lNearestDistance Then
  2989.             $lNearestAgent = $lAgentArray[$i]
  2990.             $lNearestDistance = $lDistance
  2991.         EndIf
  2992.     Next
  2993.  
  2994.     SetExtended(Sqrt($lNearestDistance))
  2995.     Return $lNearestAgent
  2996. EndFunc   ;==>GetNearestNPCToCoords
  2997.  
  2998. ;~ Description: Returns the nearest item to an agent.
  2999. Func GetNearestItemToAgent($aAgent = -2, $aCanPickUp = True)
  3000.     Local $lNearestAgent, $lNearestDistance = 100000000
  3001.     Local $lDistance
  3002.     Local $lAgentArray = GetAgentArray(0x400)
  3003.  
  3004.     If Not IsDllStruct($aAgent) Then $aAgent = GetAgentByID($aAgent)
  3005.  
  3006.     Local $lID = DllStructGetData($aAgent, 'ID')
  3007.  
  3008.     For $i = 1 To $lAgentArray[0]
  3009.  
  3010.         If $aCanPickUp And Not GetCanPickUp($lAgentArray[$i]) Then ContinueLoop
  3011.         $lDistance = (DllStructGetData($aAgent, 'X') - DllStructGetData($lAgentArray[$i], 'X')) ^ 2 + (DllStructGetData($aAgent, 'Y') - DllStructGetData($lAgentArray[$i], 'Y')) ^ 2
  3012.         If $lDistance < $lNearestDistance Then
  3013.             If DllStructGetData($lAgentArray[$i], 'ID') == $lID Then ContinueLoop
  3014.             $lNearestAgent = $lAgentArray[$i]
  3015.             $lNearestDistance = $lDistance
  3016.         EndIf
  3017.     Next
  3018.  
  3019.     SetExtended(Sqrt($lNearestDistance))
  3020.     Return $lNearestAgent
  3021. EndFunc   ;==>GetNearestItemToAgent
  3022.  
  3023. ;~ Description: Returns array of party members
  3024. ;~ Param: an array returned by GetAgentArray. This is totally optional, but can greatly improve script speed.
  3025. Func GetParty($aAgentArray = 0)
  3026.     Local $lReturnArray[1] = [0]
  3027.     If $aAgentArray==0 Then $aAgentArray = GetAgentArray(0xDB)
  3028.     For $i = 1 To $aAgentArray[0]
  3029.         If DllStructGetData($aAgentArray[$i], 'Allegiance') == 1 Then
  3030.             If BitAND(DllStructGetData($aAgentArray[$i], 'TypeMap'), 131072) Then
  3031.                 $lReturnArray[0] += 1
  3032.                 ReDim $lReturnArray[$lReturnArray[0] + 1]
  3033.                 $lReturnArray[$lReturnArray[0]] = $aAgentArray[$i]
  3034.             EndIf
  3035.         EndIf
  3036.     Next
  3037.     Return $lReturnArray
  3038. EndFunc   ;==>GetParty
  3039.  
  3040. ;~ Description: Quickly creates an array of agents of a given type
  3041. Func GetAgentArray($aType = 0)
  3042.     Local $lStruct
  3043.     Local $lCount
  3044.     Local $lBuffer = ''
  3045.     DllStructSetData($mMakeAgentArray, 2, $aType)
  3046.     MemoryWrite($mAgentCopyCount, -1, 'long')
  3047.     Enqueue($mMakeAgentArrayPtr, 8)
  3048.     Local $lDeadlock = TimerInit()
  3049.     Do
  3050.         Sleep(1)
  3051.         $lCount = MemoryRead($mAgentCopyCount, 'long')
  3052.     Until $lCount >= 0 Or TimerDiff($lDeadlock) > 5000
  3053.     If $lCount < 0 Then $lCount = 0
  3054.     For $i = 1 To $lCount
  3055.         $lBuffer &= 'Byte[448];'
  3056.     Next
  3057.     $lBuffer = DllStructCreate($lBuffer)
  3058.     DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $mAgentCopyBase, 'ptr', DllStructGetPtr($lBuffer), 'int', DllStructGetSize($lBuffer), 'int', '')
  3059.     Local $lReturnArray[$lCount + 1] = [$lCount]
  3060.     For $i = 1 To $lCount
  3061.         $lReturnArray[$i] = DllStructCreate('ptr vtable;byte unknown1[24];byte unknown2[4];ptr NextAgent;byte unknown3[8];long Id;float Z;byte unknown4[8];float BoxHoverWidth;float BoxHoverHeight;byte unknown5[8];float Rotation;byte unknown6[8];long NameProperties;byte unknown7[24];float X;float Y;byte unknown8[8];float NameTagX;float NameTagY;float NameTagZ;byte unknown9[12];long Type;float MoveX;float MoveY;byte unknown10[28];long Owner;byte unknown30[8];long ExtraType;byte unknown11[24];float AttackSpeed;float AttackSpeedModifier;word PlayerNumber;byte unknown12[6];ptr Equip;byte unknown13[10];byte Primary;byte Secondary;byte Level;byte Team;byte unknown14[6];float EnergyPips;byte unknown[4];float EnergyPercent;long MaxEnergy;byte unknown15[4];float HPPips;byte unknown16[4];float HP;long MaxHP;long Effects;byte unknown17[4];byte Hex;byte unknown18[18];long ModelState;long TypeMap;byte unknown19[16];long InSpiritRange;byte unknown20[16];long LoginNumber;float ModelMode;byte unknown21[4];long ModelAnimation;byte unknown22[32];byte LastStrike;byte Allegiance;word WeaponType;word Skill;byte unknown23[4];word WeaponItemId;word OffhandItemId')
  3062.         $lStruct = DllStructCreate('byte[448]', DllStructGetPtr($lReturnArray[$i]))
  3063.         DllStructSetData($lStruct, 1, DllStructGetData($lBuffer, $i))
  3064.     Next
  3065.     Return $lReturnArray
  3066. EndFunc   ;==>GetAgentArray
  3067.  
  3068. Func GetPartySize()
  3069.     Local $lSize = 0, $lReturn
  3070.     Local $lOffset[5] = [0, 0x18, 0x4C, 0x54, 0]
  3071.     For $i=0 To 2
  3072.         $lOffset[4] = $i * 0x10 + 0xC
  3073.         $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  3074.         $lSize += $lReturn[1]
  3075.     Next
  3076.     Return $lSize
  3077. EndFunc
  3078.  
  3079. ;~  Description: Returns different States about Party. Check with BitAND.
  3080. ;~  0x8 = Leader starts Mission / Leader is travelling with Party
  3081. ;~  0x10 = Hardmode enabled
  3082. ;~  0x20 = Party defeated
  3083. ;~  0x40 = Guild Battle
  3084. ;~  0x80 = Party Leader
  3085. ;~  0x100 = Observe-Mode
  3086. Func GetPartyState($aFlag)
  3087.     Local $lOffset[4] = [0, 0x18, 0x4C, 0x14]
  3088.     Local $lBitMask = MemoryReadPtr($mBasePointer,$lOffset)
  3089.     Return BitAND($lBitMask[1], $aFlag) > 0
  3090. EndFunc   ;==>GetPartyState
  3091.  
  3092. Func GetPartyWaitingForMission()
  3093.     Return GetPartyState(0x8)
  3094. EndFunc
  3095.  
  3096. Func GetIsHardMode()
  3097.     Return GetPartyState(0x10)
  3098. EndFunc
  3099.  
  3100. Func GetPartyDefeated()
  3101.     Return GetPartyState(0x20)
  3102. EndFunc
  3103. ;~ Description Returns the "danger level" of each party member
  3104. ;~ Param1: an array returned by GetAgentArray(). This is totally optional, but can greatly improve script speed.
  3105. ;~ Param2: an array returned by GetParty() This is totally optional, but can greatly improve script speed.
  3106. Func GetPartyDanger($aAgentArray = 0, $aParty = 0)
  3107.     If $aAgentArray == 0 Then $aAgentArray = GetAgentArray(0xDB)
  3108.     If $aParty == 0 Then $aParty = GetParty($aAgentArray)
  3109.  
  3110.     Local $lReturnArray[$aParty[0]+1]
  3111.     $lReturnArray[0] = $aParty[0]
  3112.     For $i=1 To $lReturnArray[0]
  3113.         $lReturnArray[$i] = 0
  3114.     Next
  3115.  
  3116.     For $i=1 To $aAgentArray[0]
  3117.         If BitAND(DllStructGetData($aAgentArray[$i], 'Effects'), 0x0010) > 0 Then ContinueLoop
  3118.         If DllStructGetData($aAgentArray[$i], 'HP') <= 0 Then ContinueLoop
  3119.         If Not GetIsLiving($aAgentArray[$i]) Then ContinueLoop
  3120.         If DllStructGetData($aAgentArray[$i], "Allegiance") > 3 Then ContinueLoop   ; ignore NPCs, spirits, minions, pets
  3121.  
  3122.         For $j=1 To $aParty[0]
  3123.             If GetTarget(DllStructGetData($aAgentArray[$i], "ID")) == DllStructGetData($aParty[$j], "ID") Then
  3124.                 If GetDistance($aAgentArray[$i], $aParty[$j]) < 5000 Then
  3125.                     If DllStructGetData($aAgentArray[$i], "Team") <> 0 Then
  3126.                         If DllStructGetData($aAgentArray[$i], "Team") <> DllStructGetData($aParty[$j], "Team") Then
  3127.                             $lReturnArray[$j] += 1
  3128.                         EndIf
  3129.                     ElseIf DllStructGetData($aAgentArray[$i], "Allegiance") <> DllStructGetData($aParty[$j], "Allegiance") Then
  3130.                         $lReturnArray[$j] += 1
  3131.                     EndIf
  3132.                 EndIf
  3133.             EndIf
  3134.         Next
  3135.     Next
  3136.     Return $lReturnArray
  3137. EndFunc
  3138. ;~ Description: Return the number of enemy agents targeting the given agent.
  3139. Func GetAgentDanger($aAgent = -2, $aAgentArray = 0)
  3140.     If IsDllStruct($aAgent) = 0 Then
  3141.         $aAgent = GetAgentByID($aAgent)
  3142.     EndIf
  3143.  
  3144.     Local $lCount = 0
  3145.  
  3146.     If $aAgentArray == 0 Then $aAgentArray = GetAgentArray(0xDB)
  3147.  
  3148.     For $i=1 To $aAgentArray[0]
  3149.         If BitAND(DllStructGetData($aAgentArray[$i], 'Effects'), 0x0010) > 0 Then ContinueLoop
  3150.         If DllStructGetData($aAgentArray[$i], 'HP') <= 0 Then ContinueLoop
  3151.         If Not GetIsLiving($aAgentArray[$i]) Then ContinueLoop
  3152.         If DllStructGetData($aAgentArray[$i], "Allegiance") > 3 Then ContinueLoop   ; ignore NPCs, spirits, minions, pets
  3153.         If GetTarget(DllStructGetData($aAgentArray[$i], "ID")) == DllStructGetData($aAgent, "ID") Then
  3154.             If GetDistance($aAgentArray[$i], $aAgent) < 5000 Then
  3155.                 If DllStructGetData($aAgentArray[$i], "Team") <> 0 Then
  3156.                     If DllStructGetData($aAgentArray[$i], "Team") <> DllStructGetData($aAgent, "Team") Then
  3157.                         $lCount += 1
  3158.                     EndIf
  3159.                 ElseIf DllStructGetData($aAgentArray[$i], "Allegiance") <> DllStructGetData($aAgent, "Allegiance") Then
  3160.                     $lCount += 1
  3161.                 EndIf
  3162.             EndIf
  3163.         EndIf
  3164.     Next
  3165.     Return $lCount
  3166. EndFunc
  3167. #EndRegion Agent
  3168.  
  3169. #Region AgentInfo
  3170. ;~ Description: Tests if an agent is living.
  3171. Func GetIsLiving($aAgent = -2)
  3172.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3173.     Return DllStructGetData($aAgent, 'Type') = 0xDB
  3174. EndFunc   ;==>GetIsLiving
  3175.  
  3176. ;~ Description: Tests if an agent is a signpost/chest/etc.
  3177. Func GetIsStatic($aAgent)
  3178.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3179.     Return DllStructGetData($aAgent, 'Type') = 0x200
  3180. EndFunc   ;==>GetIsStatic
  3181.  
  3182. ;~ Description: Tests if an agent is an item.
  3183. Func GetIsMovable($aAgent)
  3184.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3185.     Return DllStructGetData($aAgent, 'Type') = 0x400
  3186. EndFunc   ;==>GetIsMovable
  3187.  
  3188. ;~ Description: Returns energy of an agent. (Only self/heroes)
  3189. Func GetEnergy($aAgent = -2)
  3190.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3191.     Return DllStructGetData($aAgent, 'EnergyPercent') * DllStructGetData($aAgent, 'MaxEnergy')
  3192. EndFunc   ;==>GetEnergy
  3193.  
  3194. ;~ Description: Returns health of an agent. (Must have caused numerical change in health)
  3195. Func GetHealth($aAgent = -2)
  3196.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3197.     Return DllStructGetData($aAgent, 'HP') * DllStructGetData($aAgent, 'MaxHP')
  3198. EndFunc   ;==>GetHealth
  3199.  
  3200. ;~ Description: Tests if an agent is moving.
  3201. Func GetIsMoving($aAgent = -2)
  3202.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3203.     If DllStructGetData($aAgent, 'MoveX') <> 0 Or DllStructGetData($aAgent, 'MoveY') <> 0 Then Return True
  3204.     Return False
  3205. EndFunc   ;==>GetIsMoving
  3206.  
  3207. ;~ Description: Tests if an agent is knocked down.
  3208. Func GetIsKnocked($aAgent = -2)
  3209.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3210.     Return DllStructGetData($aAgent, 'ModelState') = 0x450
  3211. EndFunc   ;==>GetIsKnocked
  3212.  
  3213. ;~ Description: Tests if an agent is attacking.
  3214. Func GetIsAttacking($aAgent = -2)
  3215.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3216.     Switch DllStructGetData($aAgent, 'ModelState')
  3217.         Case 0x60 ; Is Attacking
  3218.             Return True
  3219.         Case 0x440 ; Is Attacking
  3220.             Return True
  3221.         Case 0x460 ; Is Attacking
  3222.             Return True
  3223.         Case Else
  3224.             Return False
  3225.     EndSwitch
  3226. EndFunc   ;==>GetIsAttacking
  3227.  
  3228. ;~ Description: Tests if an agent is casting.
  3229. Func GetIsCasting($aAgent = -2)
  3230.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3231.     Return DllStructGetData($aAgent, 'Skill') <> 0
  3232. EndFunc   ;==>GetIsCasting
  3233.  
  3234. ;~ Description: Tests if an agent is bleeding.
  3235. Func GetIsBleeding($aAgent = -2)
  3236.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3237.     Return BitAND(DllStructGetData($aAgent, 'Effects'), 0x0001) > 0
  3238. EndFunc   ;==>GetIsBleeding
  3239.  
  3240. ;~ Description: Tests if an agent has a condition.
  3241. Func GetHasCondition($aAgent = -2)
  3242.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3243.     Return BitAND(DllStructGetData($aAgent, 'Effects'), 0x0002) > 0
  3244. EndFunc   ;==>GetHasCondition
  3245.  
  3246. ;~ Description: Tests if an agent is dead.
  3247. Func GetIsDead($aAgent = -2)
  3248.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3249.     Return BitAND(DllStructGetData($aAgent, 'Effects'), 0x0010) > 0
  3250. EndFunc   ;==>GetIsDead
  3251.  
  3252. ;~ Description: Tests if an agent has a deep wound.
  3253. Func GetHasDeepWound($aAgent = -2)
  3254.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3255.     Return BitAND(DllStructGetData($aAgent, 'Effects'), 0x0020) > 0
  3256. EndFunc   ;==>GetHasDeepWound
  3257.  
  3258. ;~ Description: Tests if an agent is poisoned.
  3259. Func GetIsPoisoned($aAgent = -2)
  3260.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3261.     Return BitAND(DllStructGetData($aAgent, 'Effects'), 0x0040) > 0
  3262. EndFunc   ;==>GetIsPoisoned
  3263.  
  3264. ;~ Description: Tests if an agent is enchanted.
  3265. Func GetIsEnchanted($aAgent = -2)
  3266.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3267.     Return BitAND(DllStructGetData($aAgent, 'Effects'), 0x0080) > 0
  3268. EndFunc   ;==>GetIsEnchanted
  3269.  
  3270. ;~ Description: Tests if an agent has a degen hex.
  3271. Func GetHasDegenHex($aAgent = -2)
  3272.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3273.     Return BitAND(DllStructGetData($aAgent, 'Effects'), 0x0400) > 0
  3274. EndFunc   ;==>GetHasDegenHex
  3275.  
  3276. ;~ Description: Tests if an agent is hexed.
  3277. Func GetHasHex($aAgent = -2)
  3278.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3279.     Return BitAND(DllStructGetData($aAgent, 'Effects'), 0x0800) > 0
  3280. EndFunc   ;==>GetHasHex
  3281.  
  3282. ;~ Description: Tests if an agent has a weapon spell.
  3283. Func GetHasWeaponSpell($aAgent = -2)
  3284.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3285.     Return BitAND(DllStructGetData($aAgent, 'Effects'), 0x8000) > 0
  3286. EndFunc   ;==>GetHasWeaponSpell
  3287.  
  3288. ;~ Description: Tests if an agent is a boss.
  3289. Func GetIsBoss($aAgent)
  3290.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3291.     Return BitAND(DllStructGetData($aAgent, 'TypeMap'), 1024) > 0
  3292. EndFunc   ;==>GetIsBoss
  3293.  
  3294. ;~ Description: Returns a player's name.
  3295. Func GetPlayerName($aAgent = -2)
  3296.     If IsDllStruct($aAgent) = 0 Then $aAgent = GetAgentByID($aAgent)
  3297.     Local $lLogin = DllStructGetData($aAgent, 'LoginNumber')
  3298.     Local $lOffset[6] = [0, 0x18, 0x2C, 0x80C, 76 * $lLogin + 0x28, 0]
  3299.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset, 'wchar[30]')
  3300.     Return $lReturn[1]
  3301. EndFunc   ;==>GetPlayerName
  3302.  
  3303. ;~ Description: Returns the name of an agent.
  3304. Func GetAgentName($aAgent = -2)
  3305.     If IsDllStruct($aAgent) = 0 Then
  3306.         Local $lAgentID = ConvertID($aAgent)
  3307.         If $lAgentID = 0 Then Return ''
  3308.     Else
  3309.         Local $lAgentID = DllStructGetData($aAgent, 'ID')
  3310.     EndIf
  3311.  
  3312.     Local $lAddress = $mStringLogBase + 256 * $lAgentID
  3313.     Local $lName = MemoryRead($lAddress, 'wchar [128]')
  3314.  
  3315.     If $lName = '' Then
  3316.         DisplayAll(True)
  3317.         Sleep(100)
  3318.         DisplayAll(False)
  3319.     EndIf
  3320.  
  3321.     Local $lName = MemoryRead($lAddress, 'wchar [128]')
  3322.     $lName = StringRegExpReplace($lName, '[<]{1}([^>]+)[>]{1}', '')
  3323.     Return $lName
  3324. EndFunc   ;==>GetAgentName
  3325. #EndRegion AgentInfo
  3326.  
  3327. #Region Buff
  3328. ;~ Description: Returns current number of buffs being maintained.
  3329. Func GetBuffCount($aHeroNumber = 0)
  3330.     Local $lOffset[4]
  3331.     $lOffset[0] = 0
  3332.     $lOffset[1] = 0x18
  3333.     $lOffset[2] = 0x2C
  3334.     $lOffset[3] = 0x510
  3335.     Local $lCount = MemoryReadPtr($mBasePointer, $lOffset)
  3336.     ReDim $lOffset[5]
  3337.     $lOffset[3] = 0x508
  3338.     Local $lBuffer
  3339.     For $i = 0 To $lCount[1] - 1
  3340.         $lOffset[4] = 0x24 * $i
  3341.         $lBuffer = MemoryReadPtr($mBasePointer, $lOffset)
  3342.         If $lBuffer[1] == GetHeroID($aHeroNumber) Then
  3343.             Return MemoryRead($lBuffer[0] + 0xC)
  3344.         EndIf
  3345.     Next
  3346.     Return 0
  3347. EndFunc   ;==>GetBuffCount
  3348.  
  3349. ;~ Description: Tests if you are currently maintaining buff on target.
  3350. Func GetIsTargetBuffed($aSkillID, $aAgentID, $aHeroNumber = 0)
  3351.     Local $lBuffStruct = DllStructCreate('long SkillId;byte unknown1[4];long BuffId;long TargetId')
  3352.     Local $lBuffCount = GetBuffCount($aHeroNumber)
  3353.     Local $lBuffStructAddress
  3354.     Local $lOffset[4]
  3355.     $lOffset[0] = 0
  3356.     $lOffset[1] = 0x18
  3357.     $lOffset[2] = 0x2C
  3358.     $lOffset[3] = 0x510
  3359.     Local $lCount = MemoryReadPtr($mBasePointer, $lOffset)
  3360.     ReDim $lOffset[5]
  3361.     $lOffset[3] = 0x508
  3362.     Local $lBuffer
  3363.     For $i = 0 To $lCount[1] - 1
  3364.         $lOffset[4] = 0x24 * $i
  3365.         $lBuffer = MemoryReadPtr($mBasePointer, $lOffset)
  3366.         If $lBuffer[1] == GetHeroID($aHeroNumber) Then
  3367.             $lOffset[4] = 0x4 + 0x24 * $i
  3368.             ReDim $lOffset[6]
  3369.             For $j = 0 To $lBuffCount - 1
  3370.                 $lOffset[5] = 0 + 0x10 * $j
  3371.                 $lBuffStructAddress = MemoryReadPtr($mBasePointer, $lOffset)
  3372.                 DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lBuffStructAddress[0], 'ptr', DllStructGetPtr($lBuffStruct), 'int', DllStructGetSize($lBuffStruct), 'int', '')
  3373.                 If (DllStructGetData($lBuffStruct, 'SkillID') == $aSkillID) And (DllStructGetData($lBuffStruct, 'TargetId') == ConvertID($aAgentID)) Then
  3374.                     Return $j + 1
  3375.                 EndIf
  3376.             Next
  3377.         EndIf
  3378.     Next
  3379.     Return 0
  3380. EndFunc   ;==>GetIsTargetBuffed
  3381.  
  3382. ;~ Description: Returns buff struct.
  3383. Func GetBuffByIndex($aBuffNumber, $aHeroNumber = 0)
  3384.     Local $lBuffStruct = DllStructCreate('long SkillId;byte unknown1[4];long BuffId;long TargetId')
  3385.     Local $lOffset[4]
  3386.     $lOffset[0] = 0
  3387.     $lOffset[1] = 0x18
  3388.     $lOffset[2] = 0x2C
  3389.     $lOffset[3] = 0x510
  3390.     Local $lCount = MemoryReadPtr($mBasePointer, $lOffset)
  3391.     ReDim $lOffset[5]
  3392.     $lOffset[3] = 0x508
  3393.     Local $lBuffer
  3394.     For $i = 0 To $lCount[1] - 1
  3395.         $lOffset[4] = 0x24 * $i
  3396.         $lBuffer = MemoryReadPtr($mBasePointer, $lOffset)
  3397.         If $lBuffer[1] == GetHeroID($aHeroNumber) Then
  3398.             $lOffset[4] = 0x4 + 0x24 * $i
  3399.             ReDim $lOffset[6]
  3400.             $lOffset[5] = 0 + 0x10 * ($aBuffNumber - 1)
  3401.             $lBuffStructAddress = MemoryReadPtr($mBasePointer, $lOffset)
  3402.             DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lBuffStructAddress[0], 'ptr', DllStructGetPtr($lBuffStruct), 'int', DllStructGetSize($lBuffStruct), 'int', '')
  3403.             Return $lBuffStruct
  3404.         EndIf
  3405.     Next
  3406.     Return 0
  3407. EndFunc   ;==>GetBuffByIndex
  3408. #EndRegion Buff
  3409.  
  3410. #Region Misc
  3411. ;~ Description: Returns skillbar struct.
  3412. Func GetSkillbar($aHeroNumber = 0)
  3413.     Local $lSkillbarStruct = DllStructCreate('long AgentId;long AdrenalineA1;long AdrenalineB1;dword Recharge1;dword Id1;dword Event1;long AdrenalineA2;long AdrenalineB2;dword Recharge2;dword Id2;dword Event2;long AdrenalineA3;long AdrenalineB3;dword Recharge3;dword Id3;dword Event3;long AdrenalineA4;long AdrenalineB4;dword Recharge4;dword Id4;dword Event4;long AdrenalineA5;long AdrenalineB5;dword Recharge5;dword Id5;dword Event5;long AdrenalineA6;long AdrenalineB6;dword Recharge6;dword Id6;dword Event6;long AdrenalineA7;long AdrenalineB7;dword Recharge7;dword Id7;dword Event7;long AdrenalineA8;long AdrenalineB8;dword Recharge8;dword Id8;dword Event8;dword disabled;byte unknown[8];dword Casting')
  3414.     Local $lOffset[5]
  3415.     $lOffset[0] = 0
  3416.     $lOffset[1] = 0x18
  3417.     $lOffset[2] = 0x2C
  3418.     $lOffset[3] = 0x6F0
  3419.     For $i = 0 To GetHeroCount()
  3420.         $lOffset[4] = $i * 0xBC
  3421.         Local $lSkillbarStructAddress = MemoryReadPtr($mBasePointer, $lOffset)
  3422.         DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lSkillbarStructAddress[0], 'ptr', DllStructGetPtr($lSkillbarStruct), 'int', DllStructGetSize($lSkillbarStruct), 'int', '')
  3423.         If DllStructGetData($lSkillbarStruct, 'AgentId') == GetHeroID($aHeroNumber) Then Return $lSkillbarStruct
  3424.     Next
  3425. EndFunc   ;==>GetSkillbar
  3426.  
  3427. ;~ Description: Returns the skill ID of an equipped skill.
  3428. Func GetSkillbarSkillID($aSkillSlot, $aHeroNumber = 0)
  3429.     Return DllStructGetData(GetSkillbar($aHeroNumber), 'ID' & $aSkillSlot)
  3430. EndFunc   ;==>GetSkillbarSkillID
  3431.  
  3432. ;~ Description: Returns the adrenaline charge of an equipped skill.
  3433. Func GetSkillbarSkillAdrenaline($aSkillSlot, $aHeroNumber = 0)
  3434.     Return DllStructGetData(GetSkillbar($aHeroNumber), 'AdrenalineA' & $aSkillSlot)
  3435. EndFunc   ;==>GetSkillbarSkillAdrenaline
  3436.  
  3437. ;~ Description: Returns the recharge time remaining of an equipped skill in milliseconds.
  3438. Func GetSkillbarSkillRecharge($aSkillSlot, $aHeroNumber = 0)
  3439.     Local $lTimestamp = DllStructGetData(GetSkillbar($aHeroNumber), 'Recharge' & $aSkillSlot)
  3440.     If $lTimestamp == 0 Then Return 0
  3441.     Return $lTimestamp - GetSkillTimer()
  3442. EndFunc   ;==>GetSkillbarSkillRecharge
  3443.  
  3444. ;~ Description: Returns skill struct.
  3445. Func GetSkillByID($aSkillID)
  3446.     Local $lSkillStruct = DllStructCreate('long ID;byte Unknown1[4];long campaign;long Type;long Special;long ComboReq;long Effect1;long Condition;long Effect2;long WeaponReq;byte Profession;byte Attribute;byte Unknown2[2];long PvPID;byte Combo;byte Target;byte unknown3;byte EquipType;byte Unknown4;byte Energy;byte Unknown5[2];dword Adrenaline;float Activation;float Aftercast;long Duration0;long Duration15;long Recharge;byte Unknown6[12];long Scale0;long Scale15;long BonusScale0;long BonusScale15;float AoERange;float ConstEffect;byte unknown7[44]')
  3447.     Local $lSkillStructAddress = $mSkillBase + 160 * $aSkillID
  3448.     DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lSkillStructAddress, 'ptr', DllStructGetPtr($lSkillStruct), 'int', DllStructGetSize($lSkillStruct), 'int', '')
  3449.     Return $lSkillStruct
  3450. EndFunc   ;==>GetSkillByID
  3451.  
  3452. ;~ Description: Returns energy cost of a skill.
  3453. Func GetEnergyCost($aSkillId)
  3454.    Local $lInitCost = DllStructGetData(GetSkillByID($aSkillId), 'energy')
  3455.    Switch $lInitCost
  3456.          Case 11
  3457.             Return 15
  3458.          Case 12
  3459.             Return 25
  3460.          Case Else
  3461.             Return $lInitCost
  3462.     EndSwitch
  3463. EndFunc   ;==>GetEnergyCost
  3464.  
  3465. ;~ Description: Returns current morale.
  3466. Func GetMorale($aHeroNumber = 0)
  3467.     Local $lAgentID = GetHeroID($aHeroNumber)
  3468.     Local $lOffset[4]
  3469.     $lOffset[0] = 0
  3470.     $lOffset[1] = 0x18
  3471.     $lOffset[2] = 0x2C
  3472.     $lOffset[3] = 0x638
  3473.     Local $lIndex = MemoryReadPtr($mBasePointer, $lOffset)
  3474.     ReDim $lOffset[6]
  3475.     $lOffset[0] = 0
  3476.     $lOffset[1] = 0x18
  3477.     $lOffset[2] = 0x2C
  3478.     $lOffset[3] = 0x62C
  3479.     $lOffset[4] = 8 + 0xC * BitAND($lAgentID, $lIndex[1])
  3480.     $lOffset[5] = 0x18
  3481.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  3482.     Return $lReturn[1] - 100
  3483. EndFunc   ;==>GetMorale
  3484.  
  3485. ;~ Description: Returns effect struct or array of effects.
  3486. Func GetEffect($aSkillID = 0, $aHeroNumber = 0)
  3487.     Local $lEffectCount, $lEffectStructAddress
  3488.     Local $lReturnArray[1] = [0]
  3489.  
  3490.     Local $lOffset[4]
  3491.     $lOffset[0] = 0
  3492.     $lOffset[1] = 0x18
  3493.     $lOffset[2] = 0x2C
  3494.     $lOffset[3] = 0x510
  3495.     Local $lCount = MemoryReadPtr($mBasePointer, $lOffset)
  3496.     ReDim $lOffset[5]
  3497.     $lOffset[3] = 0x508
  3498.     Local $lBuffer
  3499.     For $i = 0 To $lCount[1] - 1
  3500.         $lOffset[4] = 0x24 * $i
  3501.         $lBuffer = MemoryReadPtr($mBasePointer, $lOffset)
  3502.         If $lBuffer[1] == GetHeroID($aHeroNumber) Then
  3503.             $lOffset[4] = 0x1C + 0x24 * $i
  3504.             $lEffectCount = MemoryReadPtr($mBasePointer, $lOffset)
  3505.             ReDim $lOffset[6]
  3506.             $lOffset[4] = 0x14 + 0x24 * $i
  3507.             $lOffset[5] = 0
  3508.             $lEffectStructAddress = MemoryReadPtr($mBasePointer, $lOffset)
  3509.  
  3510.             If $aSkillID = 0 Then
  3511.                 ReDim $lReturnArray[$lEffectCount[1] + 1]
  3512.                 $lReturnArray[0] = $lEffectCount[1]
  3513.  
  3514.                 For $i = 0 To $lEffectCount[1] - 1
  3515.                     $lReturnArray[$i + 1] = DllStructCreate('long SkillId;long EffectType;long EffectId;long AgentId;float Duration;long TimeStamp')
  3516.                     $lEffectStructAddress[1] = $lEffectStructAddress[0] + 24 * $i
  3517.                     DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lEffectStructAddress[1], 'ptr', DllStructGetPtr($lReturnArray[$i + 1]), 'int', 24, 'int', '')
  3518.                 Next
  3519.  
  3520.                 ExitLoop
  3521.             Else
  3522.                 Local $lReturn = DllStructCreate('long SkillId;long EffectType;long EffectId;long AgentId;float Duration;long TimeStamp')
  3523.  
  3524.                 For $i = 0 To $lEffectCount[1] - 1
  3525.                     DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lEffectStructAddress[0] + 24 * $i, 'ptr', DllStructGetPtr($lReturn), 'int', 24, 'int', '')
  3526.                     If DllStructGetData($lReturn, 'SkillID') = $aSkillID Then Return $lReturn
  3527.                 Next
  3528.             EndIf
  3529.         EndIf
  3530.     Next
  3531.     Return $lReturnArray
  3532. EndFunc   ;==>GetEffect
  3533.  
  3534. ;~ Description: Returns time remaining before an effect expires, in milliseconds.
  3535. Func GetEffectTimeRemaining($aEffect)
  3536.     If Not IsDllStruct($aEffect) Then $aEffect = GetEffect($aEffect)
  3537.     If IsArray($aEffect) Then Return 0
  3538.     Return DllStructGetData($aEffect, 'Duration') * 1000 - (GetSkillTimer() - DllStructGetData($aEffect, 'TimeStamp'))
  3539. EndFunc   ;==>GetEffectTimeRemaining
  3540.  
  3541. ;~ Description: Returns the timestamp used for effects and skills (milliseconds).
  3542. Func GetSkillTimer()
  3543.     Return MemoryRead($mSkillTimer, "long")
  3544. EndFunc   ;==>GetSkillTimer
  3545.  
  3546. ;~ Description: Returns level of an attribute.
  3547. Func GetAttributeByID($aAttributeID, $aWithRunes = False, $aHeroNumber = 0)
  3548.     Local $lAgentID = GetHeroID($aHeroNumber)
  3549.     Local $lBuffer
  3550.     Local $lOffset[5]
  3551.     $lOffset[0] = 0
  3552.     $lOffset[1] = 0x18
  3553.     $lOffset[2] = 0x2C
  3554.     $lOffset[3] = 0xAC
  3555.     For $i = 0 To GetHeroCount()
  3556.         $lOffset[4] = 0x3D8 * $i
  3557.         $lBuffer = MemoryReadPtr($mBasePointer, $lOffset)
  3558.         If $lBuffer[1] == $lAgentID Then
  3559.             If $aWithRunes Then
  3560.                 $lOffset[4] = 0x3D8 * $i + 0x14 * $aAttributeID + 0xC
  3561.             Else
  3562.                 $lOffset[4] = 0x3D8 * $i + 0x14 * $aAttributeID + 0x8
  3563.             EndIf
  3564.             $lBuffer = MemoryReadPtr($mBasePointer, $lOffset)
  3565.             Return $lBuffer[1]
  3566.         EndIf
  3567.     Next
  3568. EndFunc   ;==>GetAttributeByID
  3569.  
  3570. ;~ Description: Returns amount of experience.
  3571. Func GetExperience()
  3572.     Local $lOffset[4] = [0, 0x18, 0x2C, 0x740]
  3573.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  3574.     Return $lReturn[1]
  3575. EndFunc   ;==>GetExperience
  3576.  
  3577. ;~ Description: Tests if an area has been vanquished.
  3578. Func GetAreaVanquished()
  3579.     If GetFoesToKill() = 0 Then
  3580.         Return True
  3581.     Else
  3582.         Return False
  3583.     EndIf
  3584. EndFunc   ;==>GetAreaVanquished
  3585.  
  3586. ;~ Description: Returns number of foes that have been killed so far.
  3587. Func GetFoesKilled()
  3588.     Local $lOffset[4] = [0, 0x18, 0x2C, 0x84C]
  3589.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  3590.     Return $lReturn[1]
  3591. EndFunc   ;==>GetFoesKilled
  3592.  
  3593. ;~ Description: Returns number of enemies left to kill for vanquish.
  3594. Func GetFoesToKill()
  3595.     Local $lOffset[4] = [0, 0x18, 0x2C, 0x850]
  3596.     Local $lReturn = MemoryReadPtr($mBasePointer, $lOffset)
  3597.     Return $lReturn[1]
  3598. EndFunc   ;==>GetFoesToKill
  3599.  
  3600. ;~ Description: Returns number of agents currently loaded.
  3601. Func GetMaxAgents()
  3602.     Return MemoryRead($mMaxAgents)
  3603. EndFunc   ;==>GetMaxAgents
  3604.  
  3605. ;~ Description: Returns your agent ID.
  3606. Func GetMyID()
  3607.     Return MemoryRead($mMyID)
  3608. EndFunc   ;==>GetMyID
  3609.  
  3610. ;~ Description: Returns current target.
  3611. Func GetCurrentTarget()
  3612.     Return GetAgentByID(GetCurrentTargetID())
  3613. EndFunc   ;==>GetCurrentTarget
  3614.  
  3615. ;~ Description: Returns current target ID.
  3616. Func GetCurrentTargetID()
  3617.     Return MemoryRead($mCurrentTarget)
  3618. EndFunc   ;==>GetCurrentTargetID
  3619.  
  3620. ;~ Description: Returns current ping.
  3621. Func GetPing()
  3622.     Return MemoryRead($mPing)
  3623. EndFunc   ;==>GetPing
  3624.  
  3625. ;~ Description: Returns current map ID.
  3626. Func GetMapID()
  3627.     Return MemoryRead($mMapID)
  3628. EndFunc   ;==>GetMapID
  3629.  
  3630. ;~ Description: Returns current load-state.
  3631. Func GetMapLoading()
  3632.     Return MemoryRead($mMapLoading)
  3633. EndFunc   ;==>GetMapLoading
  3634.  
  3635. ;~ Description: Returns if map has been loaded. Reset with InitMapLoad().
  3636. Func GetMapIsLoaded()
  3637.     Return MemoryRead($mMapIsLoaded) And GetAgentExists(-2)
  3638. EndFunc   ;==>GetMapIsLoaded
  3639.  
  3640. ;~ Description: Returns current district
  3641. Func GetDistrict()
  3642.     Local $lOffset[4] = [0, 0x18, 0x44, 0x1B4]
  3643.     Local $lResult = MemoryReadPtr($mBasePointer, $lOffset)
  3644.     Return $lResult[1]
  3645. EndFunc   ;==>GetDistrict
  3646.  
  3647. ;~ Description: Internal use for travel functions.
  3648. Func GetRegion()
  3649.     Return MemoryRead($mRegion)
  3650. EndFunc   ;==>GetRegion
  3651.  
  3652. ;~ Description: Internal use for travel functions.
  3653. Func GetLanguage()
  3654.     Return MemoryRead($mLanguage)
  3655. EndFunc   ;==>GetLanguage
  3656.  
  3657. ;~ Description: Wait for map to load. Returns true if successful.
  3658. Func WaitMapLoading($aMapID = 0, $aDeadlock = 15000)
  3659. ;~  Waits $aDeadlock for load to start, and $aDeadLock for agent to load after map is loaded.
  3660.     Local $lMapLoading
  3661.     Local $lDeadlock = TimerInit()
  3662.  
  3663.     InitMapLoad()
  3664.  
  3665.     Do
  3666.         Sleep(100)
  3667.         $lMapLoading = GetMapLoading()
  3668.         If $lMapLoading == 2 Then $lDeadlock = TimerInit()
  3669.         If TimerDiff($lDeadlock) > $aDeadlock And $aDeadlock > 0 Then Return False
  3670.     Until $lMapLoading <> 2 And GetMapIsLoaded() And (GetMapID() = $aMapID Or $aMapID = 0)
  3671.  
  3672.     RndSleep(500)
  3673.  
  3674.     Return True
  3675. EndFunc   ;==>WaitMapLoading
  3676.  
  3677. ;~ Description: Returns quest struct.
  3678. Func GetQuestByID($aQuestID = 0)
  3679.     Local $lQuestStruct = DllStructCreate('long id;long LogState;byte unknown1[12];long MapFrom;float X;float Y;byte unknown2[8];long MapTo')
  3680.     Local $lQuestPtr, $lQuestLogSize, $lQuestID
  3681.     Local $lOffset[4] = [0, 0x18, 0x2C, 0x534]
  3682.  
  3683.     $lQuestLogSize = MemoryReadPtr($mBasePointer, $lOffset)
  3684.  
  3685.     If $aQuestID = 0 Then
  3686.         $lOffset[1] = 0x18
  3687.         $lOffset[2] = 0x2C
  3688.         $lOffset[3] = 0x528
  3689.         $lQuestID = MemoryReadPtr($mBasePointer, $lOffset)
  3690.         $lQuestID = $lQuestID[1]
  3691.     Else
  3692.         $lQuestID = $aQuestID
  3693.     EndIf
  3694.  
  3695.     Local $lOffset[5] = [0, 0x18, 0x2C, 0x52C, 0]
  3696.     For $i = 0 To $lQuestLogSize[1]
  3697.         $lOffset[4] = 0x34 * $i
  3698.         $lQuestPtr = MemoryReadPtr($mBasePointer, $lOffset)
  3699.         DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $lQuestPtr[0], 'ptr', DllStructGetPtr($lQuestStruct), 'int', DllStructGetSize($lQuestStruct), 'int', '')
  3700.         If DllStructGetData($lQuestStruct, 'ID') = $lQuestID Then Return $lQuestStruct
  3701.     Next
  3702. EndFunc   ;==>GetQuestByID
  3703.  
  3704. ;~ Description: Returns your characters name.
  3705. Func GetCharname()
  3706.     Return MemoryRead($mCharname, 'wchar[30]')
  3707. EndFunc   ;==>GetCharname
  3708.  
  3709. ;~ Description: Returns if you're logged in.
  3710. Func GetLoggedIn()
  3711.     Return MemoryRead($mLoggedIn)
  3712. EndFunc   ;==>GetLoggedIn
  3713.  
  3714. ;~ Description: Returns the number of character slots you have. Only works on character select.
  3715. Func GetCharacterSlots()
  3716.     Return MemoryRead($mCharslots)
  3717. EndFunc   ;==>GetLoggedIn
  3718.  
  3719. ;~ Description: Returns language currently being used.
  3720. Func GetDisplayLanguage()
  3721.     Local $lOffset[6] = [0, 0x18, 0x18, 0x194, 0x4C, 0x40]
  3722.     Local $lResult = MemoryReadPtr($mBasePointer, $lOffset)
  3723.     Return $lResult[1]
  3724. EndFunc   ;==>GetDisplayLanguage
  3725.  
  3726. ;~ Returns how long the current instance has been active, in milliseconds.
  3727. Func GetInstanceUpTime()
  3728.     Local $lOffset[4]
  3729.     $lOffset[0] = 0
  3730.     $lOffset[1] = 0x18
  3731.     $lOffset[2] = 0x8
  3732.     $lOffset[3] = 0x1AC
  3733.     Local $lTimer = MemoryReadPtr($mBasePointer, $lOffset)
  3734.     Return $lTimer[1]
  3735. EndFunc   ;==>GetInstanceUpTime
  3736.  
  3737. ;~ Returns the game client's build number
  3738. Func GetBuildNumber()
  3739.     Return $mBuildNumber
  3740. EndFunc   ;==>GetBuildNumber
  3741.  
  3742. Func GetProfPrimaryAttribute($aProfession)
  3743.     Switch $aProfession
  3744.         Case 1
  3745.             Return 17
  3746.         Case 2
  3747.             Return 23
  3748.         Case 3
  3749.             Return 16
  3750.         Case 4
  3751.             Return 6
  3752.         Case 5
  3753.             Return 0
  3754.         Case 6
  3755.             Return 12
  3756.         Case 7
  3757.             Return 35
  3758.         Case 8
  3759.             Return 36
  3760.         Case 9
  3761.             Return 40
  3762.         Case 10
  3763.             Return 44
  3764.     EndSwitch
  3765. EndFunc   ;==>GetProfPrimaryAttribute
  3766. #EndRegion Misc
  3767. #EndRegion Queries
  3768.  
  3769. #Region Other Functions
  3770. #Region Misc
  3771. ;~ Description: Sleep a random amount of time.
  3772. Func RndSleep($aAmount, $aRandom = 0.05)
  3773.     Local $lRandom = $aAmount * $aRandom
  3774.     Sleep(Random($aAmount - $lRandom, $aAmount + $lRandom))
  3775. EndFunc   ;==>RndSleep
  3776.  
  3777. ;~ Description: Sleep a period of time, plus or minus a tolerance
  3778. Func TolSleep($aAmount = 150, $aTolerance = 50)
  3779.     Sleep(Random($aAmount - $aTolerance, $aAmount + $aTolerance))
  3780. EndFunc   ;==>TolSleep
  3781.  
  3782. ;~ Description: Returns window handle of Guild Wars.
  3783. Func GetWindowHandle()
  3784.     Return $mGWWindowHandle
  3785. EndFunc   ;==>GetWindowHandle
  3786.  
  3787. ;~ Description: Returns the distance between two coordinate pairs.
  3788. Func ComputeDistance($aX1, $aY1, $aX2, $aY2)
  3789.     Return Sqrt(($aX1 - $aX2) ^ 2 + ($aY1 - $aY2) ^ 2)
  3790. EndFunc   ;==>ComputeDistance
  3791.  
  3792. ;~ Description: Returns the distance between two agents.
  3793. Func GetDistance($aAgent1 = -1, $aAgent2 = -2)
  3794.     If IsDllStruct($aAgent1) = 0 Then $aAgent1 = GetAgentByID($aAgent1)
  3795.     If IsDllStruct($aAgent2) = 0 Then $aAgent2 = GetAgentByID($aAgent2)
  3796.     Return Sqrt((DllStructGetData($aAgent1, 'X') - DllStructGetData($aAgent2, 'X')) ^ 2 + (DllStructGetData($aAgent1, 'Y') - DllStructGetData($aAgent2, 'Y')) ^ 2)
  3797. EndFunc   ;==>GetDistance
  3798.  
  3799. ;~ Description: Return the square of the distance between two agents.
  3800. Func GetPseudoDistance($aAgent1, $aAgent2)
  3801.     Return (DllStructGetData($aAgent1, 'X') - DllStructGetData($aAgent2, 'X')) ^ 2 + (DllStructGetData($aAgent1, 'Y') - DllStructGetData($aAgent2, 'Y')) ^ 2
  3802. EndFunc   ;==>GetPseudoDistance
  3803.  
  3804. ;~ Description: Checks if a point is within a polygon defined by an array
  3805. Func GetIsPointInPolygon($aAreaCoords, $aPosX = 0, $aPosY = 0)
  3806.     Local $lPosition
  3807.     Local $lEdges = UBound($aAreaCoords)
  3808.     Local $lOddNodes = False
  3809.     If $lEdges < 3 Then Return False
  3810.     If $aPosX = 0 Then
  3811.         Local $lAgent = GetAgentByID(-2)
  3812.         $aPosX = DllStructGetData($lAgent, 'X')
  3813.         $aPosY = DllStructGetData($lAgent, 'Y')
  3814.     EndIf
  3815.     $j = $lEdges - 1
  3816.     For $i = 0 To $lEdges - 1
  3817.         If (($aAreaCoords[$i][1] < $aPosY And $aAreaCoords[$j][1] >= $aPosY) _
  3818.                 Or ($aAreaCoords[$j][1] < $aPosY And $aAreaCoords[$i][1] >= $aPosY)) _
  3819.                 And ($aAreaCoords[$i][0] <= $aPosX Or $aAreaCoords[$j][0] <= $aPosX) Then
  3820.             If ($aAreaCoords[$i][0] + ($aPosY - $aAreaCoords[$i][1]) / ($aAreaCoords[$j][1] - $aAreaCoords[$i][1]) * ($aAreaCoords[$j][0] - $aAreaCoords[$i][0]) < $aPosX) Then
  3821.                 $lOddNodes = Not $lOddNodes
  3822.             EndIf
  3823.         EndIf
  3824.         $j = $i
  3825.     Next
  3826.     Return $lOddNodes
  3827. EndFunc   ;==>GetIsPointInPolygon
  3828.  
  3829. ;~ Description: Internal use for handing -1 and -2 agent IDs.
  3830. Func ConvertID($aID)
  3831.     If $aID = -2 Then
  3832.         Return GetMyID()
  3833.     ElseIf $aID = -1 Then
  3834.         Return GetCurrentTargetID()
  3835.     Else
  3836.         Return $aID
  3837.     EndIf
  3838. EndFunc   ;==>ConvertID
  3839.  
  3840. ;~ Description: Internal use only.
  3841. Func SendPacket($aSize, $aHeader, $aParam1 = 0, $aParam2 = 0, $aParam3 = 0, $aParam4 = 0, $aParam5 = 0, $aParam6 = 0, $aParam7 = 0, $aParam8 = 0, $aParam9 = 0, $aParam10 = 0)
  3842.     If GetAgentExists(-2) Then
  3843.         DllStructSetData($mPacket, 2, $aSize)
  3844.         DllStructSetData($mPacket, 3, $aHeader)
  3845.         DllStructSetData($mPacket, 4, $aParam1)
  3846.         DllStructSetData($mPacket, 5, $aParam2)
  3847.         DllStructSetData($mPacket, 6, $aParam3)
  3848.         DllStructSetData($mPacket, 7, $aParam4)
  3849.         DllStructSetData($mPacket, 8, $aParam5)
  3850.         DllStructSetData($mPacket, 9, $aParam6)
  3851.         DllStructSetData($mPacket, 10, $aParam7)
  3852.         DllStructSetData($mPacket, 11, $aParam8)
  3853.         DllStructSetData($mPacket, 12, $aParam9)
  3854.         DllStructSetData($mPacket, 13, $aParam10)
  3855.         Enqueue($mPacketPtr, 52)
  3856.         Return True
  3857.     Else
  3858.         Return False
  3859.     EndIf
  3860. EndFunc   ;==>SendPacket
  3861.  
  3862. ;~ Description: Internal use only.
  3863. Func PerformAction($aAction, $aFlag)
  3864.     If GetAgentExists(-2) Then
  3865.         DllStructSetData($mAction, 2, $aAction)
  3866.         DllStructSetData($mAction, 3, $aFlag)
  3867.         Enqueue($mActionPtr, 12)
  3868.         Return True
  3869.     Else
  3870.         Return False
  3871.     EndIf
  3872. EndFunc   ;==>PerformAction
  3873.  
  3874. ;~ Description: Internal use only.
  3875. Func Bin64ToDec($aBinary)
  3876.     Local $lReturn = 0
  3877.  
  3878.     For $i = 1 To StringLen($aBinary)
  3879.         If StringMid($aBinary, $i, 1) == 1 Then $lReturn += 2 ^ ($i - 1)
  3880.     Next
  3881.  
  3882.     Return $lReturn
  3883. EndFunc   ;==>Bin64ToDec
  3884.  
  3885. ;~ Description: Internal use only.
  3886. Func Base64ToBin64($aCharacter)
  3887.     Select
  3888.         Case $aCharacter == "A"
  3889.             Return "000000"
  3890.         Case $aCharacter == "B"
  3891.             Return "100000"
  3892.         Case $aCharacter == "C"
  3893.             Return "010000"
  3894.         Case $aCharacter == "D"
  3895.             Return "110000"
  3896.         Case $aCharacter == "E"
  3897.             Return "001000"
  3898.         Case $aCharacter == "F"
  3899.             Return "101000"
  3900.         Case $aCharacter == "G"
  3901.             Return "011000"
  3902.         Case $aCharacter == "H"
  3903.             Return "111000"
  3904.         Case $aCharacter == "I"
  3905.             Return "000100"
  3906.         Case $aCharacter == "J"
  3907.             Return "100100"
  3908.         Case $aCharacter == "K"
  3909.             Return "010100"
  3910.         Case $aCharacter == "L"
  3911.             Return "110100"
  3912.         Case $aCharacter == "M"
  3913.             Return "001100"
  3914.         Case $aCharacter == "N"
  3915.             Return "101100"
  3916.         Case $aCharacter == "O"
  3917.             Return "011100"
  3918.         Case $aCharacter == "P"
  3919.             Return "111100"
  3920.         Case $aCharacter == "Q"
  3921.             Return "000010"
  3922.         Case $aCharacter == "R"
  3923.             Return "100010"
  3924.         Case $aCharacter == "S"
  3925.             Return "010010"
  3926.         Case $aCharacter == "T"
  3927.             Return "110010"
  3928.         Case $aCharacter == "U"
  3929.             Return "001010"
  3930.         Case $aCharacter == "V"
  3931.             Return "101010"
  3932.         Case $aCharacter == "W"
  3933.             Return "011010"
  3934.         Case $aCharacter == "X"
  3935.             Return "111010"
  3936.         Case $aCharacter == "Y"
  3937.             Return "000110"
  3938.         Case $aCharacter == "Z"
  3939.             Return "100110"
  3940.         Case $aCharacter == "a"
  3941.             Return "010110"
  3942.         Case $aCharacter == "b"
  3943.             Return "110110"
  3944.         Case $aCharacter == "c"
  3945.             Return "001110"
  3946.         Case $aCharacter == "d"
  3947.             Return "101110"
  3948.         Case $aCharacter == "e"
  3949.             Return "011110"
  3950.         Case $aCharacter == "f"
  3951.             Return "111110"
  3952.         Case $aCharacter == "g"
  3953.             Return "000001"
  3954.         Case $aCharacter == "h"
  3955.             Return "100001"
  3956.         Case $aCharacter == "i"
  3957.             Return "010001"
  3958.         Case $aCharacter == "j"
  3959.             Return "110001"
  3960.         Case $aCharacter == "k"
  3961.             Return "001001"
  3962.         Case $aCharacter == "l"
  3963.             Return "101001"
  3964.         Case $aCharacter == "m"
  3965.             Return "011001"
  3966.         Case $aCharacter == "n"
  3967.             Return "111001"
  3968.         Case $aCharacter == "o"
  3969.             Return "000101"
  3970.         Case $aCharacter == "p"
  3971.             Return "100101"
  3972.         Case $aCharacter == "q"
  3973.             Return "010101"
  3974.         Case $aCharacter == "r"
  3975.             Return "110101"
  3976.         Case $aCharacter == "s"
  3977.             Return "001101"
  3978.         Case $aCharacter == "t"
  3979.             Return "101101"
  3980.         Case $aCharacter == "u"
  3981.             Return "011101"
  3982.         Case $aCharacter == "v"
  3983.             Return "111101"
  3984.         Case $aCharacter == "w"
  3985.             Return "000011"
  3986.         Case $aCharacter == "x"
  3987.             Return "100011"
  3988.         Case $aCharacter == "y"
  3989.             Return "010011"
  3990.         Case $aCharacter == "z"
  3991.             Return "110011"
  3992.         Case $aCharacter == "0"
  3993.             Return "001011"
  3994.         Case $aCharacter == "1"
  3995.             Return "101011"
  3996.         Case $aCharacter == "2"
  3997.             Return "011011"
  3998.         Case $aCharacter == "3"
  3999.             Return "111011"
  4000.         Case $aCharacter == "4"
  4001.             Return "000111"
  4002.         Case $aCharacter == "5"
  4003.             Return "100111"
  4004.         Case $aCharacter == "6"
  4005.             Return "010111"
  4006.         Case $aCharacter == "7"
  4007.             Return "110111"
  4008.         Case $aCharacter == "8"
  4009.             Return "001111"
  4010.         Case $aCharacter == "9"
  4011.             Return "101111"
  4012.         Case $aCharacter == "+"
  4013.             Return "011111"
  4014.         Case $aCharacter == "/"
  4015.             Return "111111"
  4016.     EndSelect
  4017. EndFunc   ;==>Base64ToBin64
  4018. #EndRegion Misc
  4019.  
  4020. #Region Callback
  4021. ;~ Description: Controls Event System.
  4022. Func SetEvent($aSkillActivate = '', $aSkillCancel = '', $aSkillComplete = '', $aChatReceive = '', $aLoadFinished = '')
  4023.     If $aSkillActivate <> '' Then
  4024.         WriteDetour('SkillLogStart', 'SkillLogProc')
  4025.     Else
  4026.         $mASMString = ''
  4027.         _('inc eax')
  4028.         _('mov dword[esi+10],eax')
  4029.         _('pop esi')
  4030.         WriteBinary($mASMString, GetValue('SkillLogStart'))
  4031.     EndIf
  4032.  
  4033.     If $aSkillCancel <> '' Then
  4034.         WriteDetour('SkillCancelLogStart', 'SkillCancelLogProc')
  4035.     Else
  4036.         $mASMString = ''
  4037.         _('push 0')
  4038.         _('push 42')
  4039.         _('mov ecx,esi')
  4040.         WriteBinary($mASMString, GetValue('SkillCancelLogStart'))
  4041.     EndIf
  4042.  
  4043.     If $aSkillComplete <> '' Then
  4044.         WriteDetour('SkillCompleteLogStart', 'SkillCompleteLogProc')
  4045.     Else
  4046.         $mASMString = ''
  4047.         _('mov eax,dword[edi+4]')
  4048.         _('test eax,eax')
  4049.         WriteBinary($mASMString, GetValue('SkillCompleteLogStart'))
  4050.     EndIf
  4051.  
  4052.     If $aChatReceive <> '' Then
  4053.         WriteDetour('ChatLogStart', 'ChatLogProc')
  4054.     Else
  4055.         $mASMString = ''
  4056.         _('add edi,E')
  4057.         _('cmp eax,B')
  4058.         WriteBinary($mASMString, GetValue('ChatLogStart'))
  4059.     EndIf
  4060.  
  4061.     $mSkillActivate = $aSkillActivate
  4062.     $mSkillCancel = $aSkillCancel
  4063.     $mSkillComplete = $aSkillComplete
  4064.     $mChatReceive = $aChatReceive
  4065.     $mLoadFinished = $aLoadFinished
  4066. EndFunc   ;==>SetEvent
  4067.  
  4068. ;~ Description: Internal use for event system.
  4069. ;~ modified by gigi, avoid getagentbyid, just pass agent id to callback
  4070. Func Event($hwnd, $msg, $wparam, $lparam)
  4071.     Switch $lparam
  4072.         Case 0x1
  4073.             DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $wparam, 'ptr', $mSkillLogStructPtr, 'int', 16, 'int', '')
  4074.             Call($mSkillActivate, DllStructGetData($mSkillLogStruct, 1), DllStructGetData($mSkillLogStruct, 2), DllStructGetData($mSkillLogStruct, 3), DllStructGetData($mSkillLogStruct, 4))
  4075.         Case 0x2
  4076.             DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $wparam, 'ptr', $mSkillLogStructPtr, 'int', 16, 'int', '')
  4077.             Call($mSkillCancel, DllStructGetData($mSkillLogStruct, 1), DllStructGetData($mSkillLogStruct, 2), DllStructGetData($mSkillLogStruct, 3))
  4078.         Case 0x3
  4079.             DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $wparam, 'ptr', $mSkillLogStructPtr, 'int', 16, 'int', '')
  4080.             Call($mSkillComplete, DllStructGetData($mSkillLogStruct, 1), DllStructGetData($mSkillLogStruct, 2), DllStructGetData($mSkillLogStruct, 3))
  4081.         Case 0x4
  4082.             DllCall($mKernelHandle, 'int', 'ReadProcessMemory', 'int', $mGWProcHandle, 'int', $wparam, 'ptr', $mChatLogStructPtr, 'int', 512, 'int', '')
  4083.             Local $lMessage = DllStructGetData($mChatLogStruct, 2)
  4084.             Local $lChannel
  4085.             Local $lSender
  4086.             Switch DllStructGetData($mChatLogStruct, 1)
  4087.                 Case 0
  4088.                     $lChannel = "Alliance"
  4089.                     $lSender = StringMid($lMessage, 6, StringInStr($lMessage, "</a>") - 6)
  4090.                     $lMessage = StringTrimLeft($lMessage, StringInStr($lMessage, "<quote>") + 6)
  4091.                 Case 3
  4092.                     $lChannel = "All"
  4093.                     $lSender = StringMid($lMessage, 6, StringInStr($lMessage, "</a>") - 6)
  4094.                     $lMessage = StringTrimLeft($lMessage, StringInStr($lMessage, "<quote>") + 6)
  4095.                 Case 9
  4096.                     $lChannel = "Guild"
  4097.                     $lSender = StringMid($lMessage, 6, StringInStr($lMessage, "</a>") - 6)
  4098.                     $lMessage = StringTrimLeft($lMessage, StringInStr($lMessage, "<quote>") + 6)
  4099.                 Case 11
  4100.                     $lChannel = "Team"
  4101.                     $lSender = StringMid($lMessage, 6, StringInStr($lMessage, "</a>") - 6)
  4102.                     $lMessage = StringTrimLeft($lMessage, StringInStr($lMessage, "<quote>") + 6)
  4103.                 Case 12
  4104.                     $lChannel = "Trade"
  4105.                     $lSender = StringMid($lMessage, 6, StringInStr($lMessage, "</a>") - 6)
  4106.                     $lMessage = StringTrimLeft($lMessage, StringInStr($lMessage, "<quote>") + 6)
  4107.                 Case 10
  4108.                     If StringLeft($lMessage, 3) == "-> " Then
  4109.                         $lChannel = "Sent"
  4110.                         $lSender = StringMid($lMessage, 10, StringInStr($lMessage, "</a>") - 10)
  4111.                         $lMessage = StringTrimLeft($lMessage, StringInStr($lMessage, "<quote>") + 6)
  4112.                     Else
  4113.                         $lChannel = "Global"
  4114.                         $lSender = "Guild Wars"
  4115.                     EndIf
  4116.                 Case 13
  4117.                     $lChannel = "Advisory"
  4118.                     $lSender = "Guild Wars"
  4119.                     $lMessage = StringTrimLeft($lMessage, StringInStr($lMessage, "<quote>") + 6)
  4120.                 Case 14
  4121.                     $lChannel = "Whisper"
  4122.                     $lSender = StringMid($lMessage, 7, StringInStr($lMessage, "</a>") - 7)
  4123.                     $lMessage = StringTrimLeft($lMessage, StringInStr($lMessage, "<quote>") + 6)
  4124.                 Case Else
  4125.                     $lChannel = "Other"
  4126.                     $lSender = "Other"
  4127.             EndSwitch
  4128.             Call($mChatReceive, $lChannel, $lSender, $lMessage)
  4129.         Case 0x5
  4130.             Call($mLoadFinished)
  4131.     EndSwitch
  4132. EndFunc   ;==>Event
  4133. #EndRegion Callback
  4134.  
  4135. #Region Modification
  4136. ;~ Description: Internal use only.
  4137. Func ModifyMemory()
  4138.     $mASMSize = 0
  4139.     $mASMCodeOffset = 0
  4140.     $mASMString = ''
  4141.  
  4142.     CreateData()
  4143.     CreateMain()
  4144.     CreateTargetLog()
  4145.     CreateSkillLog()
  4146.     CreateSkillCancelLog()
  4147.     CreateSkillCompleteLog()
  4148.     CreateChatLog()
  4149.     CreateTraderHook()
  4150.     CreateLoadFinished()
  4151.     CreateStringLog()
  4152.     CreateStringFilter1()
  4153.     CreateStringFilter2()
  4154.     CreateRenderingMod()
  4155.     CreateCommands()
  4156.  
  4157.     Local $lModMemory = MemoryRead(MemoryRead($mBase), 'ptr')
  4158.  
  4159.     If $lModMemory = 0 Then
  4160.         $mMemory = DllCall($mKernelHandle, 'ptr', 'VirtualAllocEx', 'handle', $mGWProcHandle, 'ptr', 0, 'ulong_ptr', $mASMSize, 'dword', 0x1000, 'dword', 0x40)
  4161.         $mMemory = $mMemory[0]
  4162.         MemoryWrite(MemoryRead($mBase), $mMemory)
  4163.     Else
  4164.         $mMemory = $lModMemory
  4165.     EndIf
  4166.  
  4167.     CompleteASMCode()
  4168.  
  4169.     If $lModMemory = 0 Then
  4170.         WriteBinary($mASMString, $mMemory + $mASMCodeOffset)
  4171.  
  4172.         WriteBinary("83F8009090", GetValue('ClickToMoveFix'))
  4173.         MemoryWrite(GetValue('QueuePtr'), GetValue('QueueBase'))
  4174.         MemoryWrite(GetValue('SkillLogPtr'), GetValue('SkillLogBase'))
  4175.         MemoryWrite(GetValue('ChatLogPtr'), GetValue('ChatLogBase'))
  4176.         MemoryWrite(GetValue('StringLogPtr'), GetValue('StringLogBase'))
  4177.     EndIf
  4178.  
  4179.     WriteDetour('MainStart', 'MainProc')
  4180.     WriteDetour('TargetLogStart', 'TargetLogProc')
  4181.     WriteDetour('TraderHookStart', 'TraderHookProc')
  4182.     WriteDetour('LoadFinishedStart', 'LoadFinishedProc')
  4183.     WriteDetour('RenderingMod', 'RenderingModProc')
  4184.     WriteDetour('StringLogStart', 'StringLogProc')
  4185.     WriteDetour('StringFilter1Start', 'StringFilter1Proc')
  4186.     WriteDetour('StringFilter2Start', 'StringFilter2Proc')
  4187. EndFunc   ;==>ModifyMemory
  4188.  
  4189. ;~ Description: Internal use only.
  4190. Func WriteDetour($aFrom, $aTo)
  4191.     WriteBinary('E9' & SwapEndian(Hex(GetLabelInfo($aTo) - GetLabelInfo($aFrom) - 5)), GetLabelInfo($aFrom))
  4192. EndFunc   ;==>WriteDetour
  4193.  
  4194. ;~ Description: Internal use only.
  4195. Func CreateData()
  4196.     _('CallbackHandle/4')
  4197.     _('QueueCounter/4')
  4198.     _('SkillLogCounter/4')
  4199.     _('ChatLogCounter/4')
  4200.     _('ChatLogLastMsg/4')
  4201.     _('MapIsLoaded/4')
  4202.     _('NextStringType/4')
  4203.     _('EnsureEnglish/4')
  4204.     _('TraderQuoteID/4')
  4205.     _('TraderCostID/4')
  4206.     _('TraderCostValue/4')
  4207.     _('DisableRendering/4')
  4208.     _('QueueBase/' & 256 * GetValue('QueueSize'))
  4209.     _('TargetLogBase/' & 4 * GetValue('TargetLogSize'))
  4210.     _('SkillLogBase/' & 16 * GetValue('SkillLogSize'))
  4211.     _('StringLogBase/' & 256 * GetValue('StringLogSize'))
  4212.     _('ChatLogBase/' & 512 * GetValue('ChatLogSize'))
  4213.     _('AgentCopyCount/4')
  4214.     _('AgentCopyBase/' & 0x1C0 * 256)
  4215. EndFunc   ;==>CreateData
  4216.  
  4217. ;~ Description: Internal use only.
  4218. Func CreateMain()
  4219.     _('MainProc:')
  4220.     _('pushad')
  4221.     _('mov eax,dword[EnsureEnglish]')
  4222.     _('test eax,eax')
  4223.     _('jz MainMain')
  4224.  
  4225.     _('mov ecx,dword[BasePointer]')
  4226.     _('mov ecx,dword[ecx+18]')
  4227.     _('mov ecx,dword[ecx+18]')
  4228.     _('mov ecx,dword[ecx+194]')
  4229.     _('mov al,byte[ecx+4f]')
  4230.     _('cmp al,f')
  4231.     _('ja MainMain')
  4232.     _('mov ecx,dword[ecx+4c]')
  4233.     _('mov al,byte[ecx+3f]')
  4234.     _('cmp al,f')
  4235.     _('ja MainMain')
  4236.     _('mov eax,dword[ecx+40]')
  4237.     _('test eax,eax')
  4238.     _('jz MainMain')
  4239.  
  4240.     _('mov ecx,dword[ActionBase]')
  4241.     _('mov ecx,dword[ecx+170]')
  4242.     _('mov ecx,dword[ecx+20]')
  4243.     _('mov ecx,dword[ecx]')
  4244.     _('push 0')
  4245.     _('push 0')
  4246.     _('push bb')
  4247.     _('mov edx,esp')
  4248.     _('push 0')
  4249.     _('push edx')
  4250.     _('push 18')
  4251.     _('call ActionFunction')
  4252.     _('pop eax')
  4253.     _('pop ebx')
  4254.     _('pop ecx')
  4255.  
  4256.     _('MainMain:')
  4257.     _('mov eax,dword[QueueCounter]')
  4258.     _('mov ecx,eax')
  4259.     _('shl eax,8')
  4260.     _('add eax,QueueBase')
  4261.     _('mov ebx,dword[eax]')
  4262.     _('test ebx,ebx')
  4263.     _('jz MainExit')
  4264.  
  4265.     _('push ecx')
  4266.     _('mov dword[eax],0')
  4267.     _('jmp ebx')
  4268.  
  4269.     _('CommandReturn:')
  4270.     _('pop eax')
  4271.     _('inc eax')
  4272.     _('cmp eax,QueueSize')
  4273.     _('jnz MainSkipReset')
  4274.     _('xor eax,eax')
  4275.     _('MainSkipReset:')
  4276.     _('mov dword[QueueCounter],eax')
  4277.  
  4278.     _('MainExit:')
  4279.     _('popad')
  4280.     _('mov ebp,esp')
  4281.     _('sub esp,14')
  4282.     _('ljmp MainReturn')
  4283. EndFunc   ;==>CreateMain
  4284.  
  4285. ;~ Description: Internal use only.
  4286. Func CreateTargetLog()
  4287.     _('TargetLogProc:')
  4288.     _('cmp ecx,4')
  4289.     _('jz TargetLogMain')
  4290.     _('cmp ecx,32')
  4291.     _('jz TargetLogMain')
  4292.     _('cmp ecx,3C')
  4293.     _('jz TargetLogMain')
  4294.     _('jmp TargetLogExit')
  4295.  
  4296.     _('TargetLogMain:')
  4297.     _('pushad')
  4298.     _('mov ecx,dword[ebp+8]')
  4299.     _('test ecx,ecx')
  4300.     _('jnz TargetLogStore')
  4301.     _('mov ecx,edx')
  4302.  
  4303.     _('TargetLogStore:')
  4304.     _('lea eax,dword[edx*4+TargetLogBase]')
  4305.     _('mov dword[eax],ecx')
  4306.     _('popad')
  4307.  
  4308.     _('TargetLogExit:')
  4309.     _('push ebx')
  4310.     _('push esi')
  4311.     _('push edi')
  4312.     _('mov edi,edx')
  4313.     _('ljmp TargetLogReturn')
  4314. EndFunc   ;==>CreateTargetLog
  4315.  
  4316. ;~ Description: Internal use only.
  4317. Func CreateSkillLog()
  4318.     _('SkillLogProc:')
  4319.     _('pushad')
  4320.  
  4321.     _('mov eax,dword[SkillLogCounter]')
  4322.     _('push eax')
  4323.     _('shl eax,4')
  4324.     _('add eax,SkillLogBase')
  4325.  
  4326.     _('mov ecx,dword[edi]')
  4327.     _('mov dword[eax],ecx')
  4328.     _('mov ecx,dword[ecx*4+TargetLogBase]')
  4329.     _('mov dword[eax+4],ecx')
  4330.     _('mov ecx,dword[edi+4]')
  4331.     _('mov dword[eax+8],ecx')
  4332.     _('mov ecx,dword[edi+8]')
  4333.     _('mov dword[eax+c],ecx')
  4334.  
  4335.     _('push 1')
  4336.     _('push eax')
  4337.     _('push CallbackEvent')
  4338.     _('push dword[CallbackHandle]')
  4339.     _('call dword[PostMessage]')
  4340.  
  4341.     _('pop eax')
  4342.     _('inc eax')
  4343.     _('cmp eax,SkillLogSize')
  4344.     _('jnz SkillLogSkipReset')
  4345.     _('xor eax,eax')
  4346.     _('SkillLogSkipReset:')
  4347.     _('mov dword[SkillLogCounter],eax')
  4348.  
  4349.     _('popad')
  4350.     _('inc eax')
  4351.     _('mov dword[esi+10],eax')
  4352.     _('pop esi')
  4353.     _('ljmp SkillLogReturn')
  4354. EndFunc   ;==>CreateSkillLog
  4355.  
  4356. ;~ Description: Internal use only.
  4357. Func CreateSkillCancelLog()
  4358.     _('SkillCancelLogProc:')
  4359.     _('pushad')
  4360.  
  4361.     _('mov eax,dword[SkillLogCounter]')
  4362.     _('push eax')
  4363.     _('shl eax,4')
  4364.     _('add eax,SkillLogBase')
  4365.  
  4366.     _('mov ecx,dword[edi]')
  4367.     _('mov dword[eax],ecx')
  4368.     _('mov ecx,dword[ecx*4+TargetLogBase]')
  4369.     _('mov dword[eax+4],ecx')
  4370.     _('mov ecx,dword[edi+4]')
  4371.     _('mov dword[eax+8],ecx')
  4372.  
  4373.     _('push 2')
  4374.     _('push eax')
  4375.     _('push CallbackEvent')
  4376.     _('push dword[CallbackHandle]')
  4377.     _('call dword[PostMessage]')
  4378.  
  4379.     _('pop eax')
  4380.     _('inc eax')
  4381.     _('cmp eax,SkillLogSize')
  4382.     _('jnz SkillCancelLogSkipReset')
  4383.     _('xor eax,eax')
  4384.     _('SkillCancelLogSkipReset:')
  4385.     _('mov dword[SkillLogCounter],eax')
  4386.  
  4387.     _('popad')
  4388.     _('push 0')
  4389.     _('push 42')
  4390.     _('mov ecx,esi')
  4391.     _('ljmp SkillCancelLogReturn')
  4392. EndFunc   ;==>CreateSkillCancelLog
  4393.  
  4394. ;~ Description: Internal use only.
  4395. Func CreateSkillCompleteLog()
  4396.     _('SkillCompleteLogProc:')
  4397.     _('pushad')
  4398.  
  4399.     _('mov eax,dword[SkillLogCounter]')
  4400.     _('push eax')
  4401.     _('shl eax,4')
  4402.     _('add eax,SkillLogBase')
  4403.  
  4404.     _('mov ecx,dword[edi]')
  4405.     _('mov dword[eax],ecx')
  4406.     _('mov ecx,dword[ecx*4+TargetLogBase]')
  4407.     _('mov dword[eax+4],ecx')
  4408.     _('mov ecx,dword[edi+4]')
  4409.     _('mov dword[eax+8],ecx')
  4410.  
  4411.     _('push 3')
  4412.     _('push eax')
  4413.     _('push CallbackEvent')
  4414.     _('push dword[CallbackHandle]')
  4415.     _('call dword[PostMessage]')
  4416.  
  4417.     _('pop eax')
  4418.     _('inc eax')
  4419.     _('cmp eax,SkillLogSize')
  4420.     _('jnz SkillCompleteLogSkipReset')
  4421.     _('xor eax,eax')
  4422.     _('SkillCompleteLogSkipReset:')
  4423.     _('mov dword[SkillLogCounter],eax')
  4424.  
  4425.     _('popad')
  4426.     _('mov eax,dword[edi+4]')
  4427.     _('test eax,eax')
  4428.     _('ljmp SkillCompleteLogReturn')
  4429. EndFunc   ;==>CreateSkillCompleteLog
  4430.  
  4431. ;~ Description: Internal use only.
  4432. Func CreateChatLog()
  4433.     _('ChatLogProc:')
  4434.  
  4435.     _('pushad')
  4436.     _('mov ecx,dword[ebx]')
  4437.     _('mov ebx,eax')
  4438.     _('mov eax,dword[ChatLogCounter]')
  4439.     _('push eax')
  4440.     _('shl eax,9')
  4441.     _('add eax,ChatLogBase')
  4442.     _('mov dword[eax],ebx')
  4443.  
  4444.     _('mov edi,eax')
  4445.     _('add eax,4')
  4446.     _('xor ebx,ebx')
  4447.  
  4448.     _('ChatLogCopyLoop:')
  4449.     _('mov dx,word[ecx]')
  4450.     _('mov word[eax],dx')
  4451.     _('add ecx,2')
  4452.     _('add eax,2')
  4453.     _('inc ebx')
  4454.     _('cmp ebx,FF')
  4455.     _('jz ChatLogCopyExit')
  4456.     _('test dx,dx')
  4457.     _('jnz ChatLogCopyLoop')
  4458.  
  4459.     _('ChatLogCopyExit:')
  4460.     _('push 4')
  4461.     _('push edi')
  4462.     _('push CallbackEvent')
  4463.     _('push dword[CallbackHandle]')
  4464.     _('call dword[PostMessage]')
  4465.  
  4466.     _('pop eax')
  4467.     _('inc eax')
  4468.     _('cmp eax,ChatLogSize')
  4469.     _('jnz ChatLogSkipReset')
  4470.     _('xor eax,eax')
  4471.     _('ChatLogSkipReset:')
  4472.     _('mov dword[ChatLogCounter],eax')
  4473.     _('popad')
  4474.  
  4475.     _('ChatLogExit:')
  4476.     _('add edi,E')
  4477.     _('cmp eax,B')
  4478.     _('ljmp ChatLogReturn')
  4479. EndFunc   ;==>CreateChatLog
  4480.  
  4481. ;~ Description: Internal use only.
  4482. Func CreateTraderHook()
  4483.     _('TraderHookProc:')
  4484.     _('mov dword[TraderCostID],ecx')
  4485.     _('mov dword[TraderCostValue],edx')
  4486.     _('push eax')
  4487.     _('mov eax,dword[TraderQuoteID]')
  4488.     _('inc eax')
  4489.     _('cmp eax,200')
  4490.     _('jnz TraderSkipReset')
  4491.     _('xor eax,eax')
  4492.     _('TraderSkipReset:')
  4493.     _('mov dword[TraderQuoteID],eax')
  4494.     _('pop eax')
  4495.     _('mov ebp,esp')
  4496.     _('sub esp,8')
  4497.     _('ljmp TraderHookReturn')
  4498. EndFunc   ;==>CreateTraderHook
  4499.  
  4500. ;~ Description: Internal use only.
  4501. Func CreateLoadFinished()
  4502.     _('LoadFinishedProc:')
  4503.     _('pushad')
  4504.  
  4505.     _('mov eax,1')
  4506.     _('mov dword[MapIsLoaded],eax')
  4507.  
  4508.     _('xor ebx,ebx')
  4509.     _('mov eax,StringLogBase')
  4510.     _('LoadClearStringsLoop:')
  4511.     _('mov dword[eax],0')
  4512.     _('inc ebx')
  4513.     _('add eax,80')
  4514.     _('cmp ebx,200')
  4515.     _('jnz LoadClearStringsLoop')
  4516.  
  4517.     _('xor ebx,ebx')
  4518.     _('mov eax,TargetLogBase')
  4519.     _('LoadClearTargetsLoop:')
  4520.     _('mov dword[eax],0')
  4521.     _('inc ebx')
  4522.     _('add eax,4')
  4523.     _('cmp ebx,200')
  4524.     _('jnz LoadClearTargetsLoop')
  4525.  
  4526.     _('push 5')
  4527.     _('push 0')
  4528.     _('push CallbackEvent')
  4529.     _('push dword[CallbackHandle]')
  4530.     _('call dword[PostMessage]')
  4531.  
  4532.     _('popad')
  4533.     _('mov esp,ebp')
  4534.     _('pop ebp')
  4535.     _('retn 10')
  4536. EndFunc   ;==>CreateLoadFinished
  4537.  
  4538. ;~ Description: Internal use only.
  4539. Func CreateStringLog()
  4540.     _('StringLogProc:')
  4541.     _('pushad')
  4542.     _('mov eax,dword[NextStringType]')
  4543.     _('test eax,eax')
  4544.     _('jz StringLogExit')
  4545.  
  4546.     _('cmp eax,1')
  4547.     _('jnz StringLogFilter2')
  4548.     _('mov eax,dword[ebp+37c]')
  4549.     _('jmp StringLogRangeCheck')
  4550.  
  4551.     _('StringLogFilter2:')
  4552.     _('cmp eax,2')
  4553.     _('jnz StringLogExit')
  4554.     _('mov eax,dword[ebp+338]')
  4555.  
  4556.     _('StringLogRangeCheck:')
  4557.     _('mov dword[NextStringType],0')
  4558.     _('cmp eax,0')
  4559.     _('jbe StringLogExit')
  4560.     _('cmp eax,StringLogSize')
  4561.     _('jae StringLogExit')
  4562.  
  4563.     _('shl eax,8')
  4564.     _('add eax,StringLogBase')
  4565.  
  4566.     _('xor ebx,ebx')
  4567.     _('StringLogCopyLoop:')
  4568.     _('mov dx,word[ecx]')
  4569.     _('mov word[eax],dx')
  4570.     _('add ecx,2')
  4571.     _('add eax,2')
  4572.     _('inc ebx')
  4573.     _('cmp ebx,80')
  4574.     _('jz StringLogExit')
  4575.     _('test dx,dx')
  4576.     _('jnz StringLogCopyLoop')
  4577.  
  4578.     _('StringLogExit:')
  4579.     _('popad')
  4580.     _('mov esp,ebp')
  4581.     _('pop ebp')
  4582.     _('retn 10')
  4583. EndFunc   ;==>CreateStringLog
  4584.  
  4585. ;~ Description: Internal use only.
  4586. Func CreateStringFilter1()
  4587.     _('StringFilter1Proc:')
  4588.     _('mov dword[NextStringType],1')
  4589.  
  4590.     _('push ebp')
  4591.     _('mov ebp,esp')
  4592.     _('push ecx')
  4593.     _('push esi')
  4594.     _('ljmp StringFilter1Return')
  4595. EndFunc   ;==>CreateStringFilter1
  4596.  
  4597. ;~ Description: Internal use only.
  4598. Func CreateStringFilter2()
  4599.     _('StringFilter2Proc:')
  4600.     _('mov dword[NextStringType],2')
  4601.  
  4602.     _('push ebp')
  4603.     _('mov ebp,esp')
  4604.     _('push ecx')
  4605.     _('push esi')
  4606.     _('ljmp StringFilter2Return')
  4607. EndFunc   ;==>CreateStringFilter2
  4608.  
  4609. ;~ Description: Internal use only.
  4610. Func CreateRenderingMod()
  4611.     _('RenderingModProc:')
  4612.     _('cmp dword[DisableRendering],1')
  4613.     _('jz RenderingModSkipCompare')
  4614.     _('cmp eax,ebx')
  4615.     _('ljne RenderingModReturn')
  4616.     _('RenderingModSkipCompare:')
  4617.     $mASMSize += 17
  4618.     $mASMString &= StringTrimLeft(MemoryRead(getvalue("RenderingMod") + 4, "byte[17]"), 2)
  4619.  
  4620.     _('cmp dword[DisableRendering],1')
  4621.     _('jz DisableRenderingProc')
  4622.     _('retn')
  4623.  
  4624.     _('DisableRenderingProc:')
  4625.     _('push 1')
  4626.     _('call dword[Sleep]')
  4627.     _('retn')
  4628. EndFunc   ;==>CreateRenderingMod
  4629.  
  4630. ;~ Description: Internal use only.
  4631. Func CreateCommands()
  4632.     _('CommandUseSkill:')
  4633.     _('mov ecx,dword[MyID]')
  4634.     _('mov edx,dword[eax+C]')
  4635.     _('push edx')
  4636.     _('mov edx,dword[eax+4]')
  4637.     _('dec edx')
  4638.     _('push dword[eax+8]')
  4639.     _('call UseSkillFunction')
  4640.     _('ljmp CommandReturn')
  4641.  
  4642.     _('CommandMove:')
  4643.     _('lea ecx,dword[eax+4]')
  4644.     _('call MoveFunction')
  4645.     _('ljmp CommandReturn')
  4646.  
  4647.     _('CommandChangeTarget:')
  4648.     _('mov ecx,dword[eax+4]')
  4649.     _('xor edx,edx')
  4650.     _('call ChangeTargetFunction')
  4651.     _('ljmp CommandReturn')
  4652.  
  4653.     _('CommandPacketSend:')
  4654.     _('mov ecx,dword[PacketLocation]')
  4655.     _('lea edx,dword[eax+8]')
  4656.     _('push edx')
  4657.     _('mov edx,dword[eax+4]')
  4658.     _('mov eax,ecx')
  4659.     _('call PacketSendFunction')
  4660.     _('ljmp CommandReturn')
  4661.  
  4662.     _('CommandWriteChat:')
  4663.     _('add eax,4')
  4664.     _('mov edx,eax')
  4665.     _('xor ecx,ecx')
  4666.     _('add eax,28')
  4667.     _('push eax')
  4668.     _('call WriteChatFunction')
  4669.     _('ljmp CommandReturn')
  4670.  
  4671.     _('CommandSellItem:')
  4672.     _('push 0')
  4673.     _('push 0')
  4674.     _('push 0')
  4675.     _('push dword[eax+4]')
  4676.     _('push 0')
  4677.     _('add eax,8')
  4678.     _('push eax')
  4679.     _('push 1')
  4680.     _('mov ecx,b')
  4681.     _('xor edx,edx')
  4682.     _('call SellItemFunction')
  4683.     _('ljmp CommandReturn')
  4684.  
  4685.     _('CommandBuyItem:')
  4686.     _('add eax,4')
  4687.     _('push eax')
  4688.     _('add eax,4')
  4689.     _('push eax')
  4690.     _('push 1')
  4691.     _('push 0')
  4692.     _('push 0')
  4693.     _('push 0')
  4694.     _('push 0')
  4695.     _('mov ecx,1')
  4696.     _('mov edx,dword[eax+4]')
  4697.     _('call BuyItemFunction')
  4698.     _('ljmp CommandReturn')
  4699.  
  4700.     _('CommandAction:')
  4701.     _('mov ecx,dword[ActionBase]')
  4702.     _('mov ecx,dword[ecx+250]')
  4703.     _('mov ecx,dword[ecx+10]')
  4704.     _('mov ecx,dword[ecx]')
  4705.     _('push 0')
  4706.     _('push 0')
  4707.     _('push dword[eax+4]')
  4708.     _('mov edx,esp')
  4709.     _('push 0')
  4710.     _('push edx')
  4711.     _('push dword[eax+8]')
  4712.     _('call ActionFunction')
  4713.     _('pop eax')
  4714.     _('pop ebx')
  4715.     _('pop ecx')
  4716.     _('ljmp CommandReturn')
  4717.  
  4718.     _('CommandToggleLanguage:')
  4719.     _('mov ecx,dword[ActionBase]')
  4720.     _('mov ecx,dword[ecx+170]')
  4721.     _('mov ecx,dword[ecx+20]')
  4722.     _('mov ecx,dword[ecx]')
  4723.     _('push 0')
  4724.     _('push 0')
  4725.     _('push bb')
  4726.     _('mov edx,esp')
  4727.     _('push 0')
  4728.     _('push edx')
  4729.     _('push dword[eax+4]')
  4730.     _('call ActionFunction')
  4731.     _('pop eax')
  4732.     _('pop ebx')
  4733.     _('pop ecx')
  4734.     _('ljmp CommandReturn')
  4735.  
  4736.     _('CommandUseHeroSkill:')
  4737.     _('mov ecx,dword[eax+4]')
  4738.     _('mov edx,dword[eax+c]')
  4739.     _('mov eax,dword[eax+8]')
  4740.     _('push eax')
  4741.     _('call UseHeroSkillFunction')
  4742.     _('ljmp CommandReturn')
  4743.  
  4744.     _('CommandSendChat:')
  4745.     _('mov ecx,dword[PacketLocation]')
  4746.     _('add eax,4')
  4747.     _('push eax')
  4748.     _('mov edx,11c')
  4749.     _('mov eax,ecx')
  4750.     _('call PacketSendFunction')
  4751.     _('ljmp CommandReturn')
  4752.  
  4753.     _('CommandRequestQuote:')
  4754.     _('mov dword[TraderCostID],0')
  4755.     _('mov dword[TraderCostValue],0')
  4756.     _('add eax,4')
  4757.     _('push eax')
  4758.     _('push 1')
  4759.     _('push 0')
  4760.     _('push 0')
  4761.     _('push 0')
  4762.     _('push 0')
  4763.     _('mov ecx,c')
  4764.     _('xor edx,edx')
  4765.     _('call RequestQuoteFunction')
  4766.     _('ljmp CommandReturn')
  4767.  
  4768.     _('CommandRequestQuoteSell:')
  4769.     _('mov dword[TraderCostID],0')
  4770.     _('mov dword[TraderCostValue],0')
  4771.     _('push 0')
  4772.     _('push 0')
  4773.     _('push 0')
  4774.     _('add eax,4')
  4775.     _('push eax')
  4776.     _('push 1')
  4777.     _('push 0')
  4778.     _('mov ecx,d')
  4779.     _('xor edx,edx')
  4780.     _('call RequestQuoteFunction')
  4781.     _('ljmp CommandReturn')
  4782.  
  4783.     _('CommandTraderBuy:')
  4784.     _('push 0')
  4785.     _('push TraderCostID')
  4786.     _('push 1')
  4787.     _('push 0')
  4788.     _('push 0')
  4789.     _('push 0')
  4790.     _('push 0')
  4791.     _('mov ecx,c')
  4792.     _('mov edx,dword[TraderCostValue]')
  4793.     _('call TraderFunction')
  4794.     _('mov dword[TraderCostID],0')
  4795.     _('mov dword[TraderCostValue],0')
  4796.     _('ljmp CommandReturn')
  4797.  
  4798.     _('CommandTraderSell:')
  4799.     _('push 0')
  4800.     _('push 0')
  4801.     _('push 0')
  4802.     _('push dword[TraderCostValue]')
  4803.     _('push 0')
  4804.     _('push TraderCostID')
  4805.     _('push 1')
  4806.     _('mov ecx,d')
  4807.     _('xor edx,edx')
  4808.     _('call TraderFunction')
  4809.     _('mov dword[TraderCostID],0')
  4810.     _('mov dword[TraderCostValue],0')
  4811.     _('ljmp CommandReturn')
  4812.  
  4813.     _('CommandSalvage:')
  4814.     _('mov ebx,SalvageGlobal')
  4815.     _('mov ecx,dword[eax+4]')
  4816.     _('mov dword[ebx],ecx')
  4817.     _('push ecx')
  4818.     _('mov ecx,dword[eax+8]')
  4819.     _('add ebx,4')
  4820.     _('mov dword[ebx],ecx')
  4821.     _('mov edx,dword[eax+c]')
  4822.     _('mov dword[ebx],ecx')
  4823.     _('call SalvageFunction')
  4824.     _('ljmp CommandReturn')
  4825.  
  4826.     _('CommandMakeAgentArray:')
  4827.     _('mov eax,dword[eax+4]')
  4828.     _('xor ebx,ebx')
  4829.     _('xor edx,edx')
  4830.     _('mov edi,AgentCopyBase')
  4831.  
  4832.     _('AgentCopyLoopStart:')
  4833.     _('inc ebx')
  4834.     _('cmp ebx,dword[MaxAgents]')
  4835.     _('jge AgentCopyLoopExit')
  4836.  
  4837.     _('mov esi,dword[AgentBase]')
  4838.     _('lea esi,dword[esi+ebx*4]')
  4839.     _('mov esi,dword[esi]')
  4840.     _('test esi,esi')
  4841.     _('jz AgentCopyLoopStart')
  4842.  
  4843.     _('cmp eax,0')
  4844.     _('jz CopyAgent')
  4845.     _('cmp eax,dword[esi+9C]')
  4846.     _('jnz AgentCopyLoopStart')
  4847.  
  4848.     _('CopyAgent:')
  4849.     _('mov ecx,1C0')
  4850.     _('clc')
  4851.     _('repe movsb')
  4852.     _('inc edx')
  4853.     _('jmp AgentCopyLoopStart')
  4854.  
  4855.     _('AgentCopyLoopExit:')
  4856.     _('mov dword[AgentCopyCount],edx')
  4857.     _('ljmp CommandReturn')
  4858.  
  4859.     _('CommandChangeStatus:')
  4860.     _('mov ecx,dword[eax+4]')
  4861.     _('call ChangeStatusFunction')
  4862.     _('ljmp CommandReturn')
  4863. EndFunc   ;==>CreateCommands
  4864. #EndRegion Modification
  4865.  
  4866. #Region Assembler
  4867. ;~ Description: Internal use only.
  4868. Func _($aASM)
  4869.     ;quick and dirty x86assembler unit:
  4870.     ;relative values stringregexp
  4871.     ;static values hardcoded
  4872.     Local $lBuffer
  4873.     Select
  4874.         Case StringRight($aASM, 1) = ':'
  4875.             SetValue('Label_' & StringLeft($aASM, StringLen($aASM) - 1), $mASMSize)
  4876.         Case StringInStr($aASM, '/') > 0
  4877.             SetValue('Label_' & StringLeft($aASM, StringInStr($aASM, '/') - 1), $mASMSize)
  4878.             Local $lOffset = StringRight($aASM, StringLen($aASM) - StringInStr($aASM, '/'))
  4879.             $mASMSize += $lOffset
  4880.             $mASMCodeOffset += $lOffset
  4881.         Case StringLeft($aASM, 5) = 'nop x'
  4882.             $lBuffer = Int(Number(StringTrimLeft($aASM, 5)))
  4883.             $mASMSize += $lBuffer
  4884.             For $i = 1 To $lBuffer
  4885.                 $mASMString &= '90'
  4886.             Next
  4887.         Case StringLeft($aASM, 5) = 'ljmp '
  4888.             $mASMSize += 5
  4889.             $mASMString &= 'E9{' & StringRight($aASM, StringLen($aASM) - 5) & '}'
  4890.         Case StringLeft($aASM, 5) = 'ljne '
  4891.             $mASMSize += 6
  4892.             $mASMString &= '0F85{' & StringRight($aASM, StringLen($aASM) - 5) & '}'
  4893.         Case StringLeft($aASM, 4) = 'jmp ' And StringLen($aASM) > 7
  4894.             $mASMSize += 2
  4895.             $mASMString &= 'EB(' & StringRight($aASM, StringLen($aASM) - 4) & ')'
  4896.         Case StringLeft($aASM, 4) = 'jae '
  4897.             $mASMSize += 2
  4898.             $mASMString &= '73(' & StringRight($aASM, StringLen($aASM) - 4) & ')'
  4899.         Case StringLeft($aASM, 3) = 'jz '
  4900.             $mASMSize += 2
  4901.             $mASMString &= '74(' & StringRight($aASM, StringLen($aASM) - 3) & ')'
  4902.         Case StringLeft($aASM, 4) = 'jnz '
  4903.             $mASMSize += 2
  4904.             $mASMString &= '75(' & StringRight($aASM, StringLen($aASM) - 4) & ')'
  4905.         Case StringLeft($aASM, 4) = 'jbe '
  4906.             $mASMSize += 2
  4907.             $mASMString &= '76(' & StringRight($aASM, StringLen($aASM) - 4) & ')'
  4908.         Case StringLeft($aASM, 3) = 'ja '
  4909.             $mASMSize += 2
  4910.             $mASMString &= '77(' & StringRight($aASM, StringLen($aASM) - 3) & ')'
  4911.         Case StringLeft($aASM, 3) = 'jl '
  4912.             $mASMSize += 2
  4913.             $mASMString &= '7C(' & StringRight($aASM, StringLen($aASM) - 3) & ')'
  4914.         Case StringLeft($aASM, 4) = 'jge '
  4915.             $mASMSize += 2
  4916.             $mASMString &= '7D(' & StringRight($aASM, StringLen($aASM) - 4) & ')'
  4917.         Case StringLeft($aASM, 4) = 'jle '
  4918.             $mASMSize += 2
  4919.             $mASMString &= '7E(' & StringRight($aASM, StringLen($aASM) - 4) & ')'
  4920.         Case StringRegExp($aASM, 'mov eax,dword[[][a-z,A-Z]{4,}[]]')
  4921.             $mASMSize += 5
  4922.             $mASMString &= 'A1[' & StringMid($aASM, 15, StringLen($aASM) - 15) & ']'
  4923.         Case StringRegExp($aASM, 'mov ebx,dword[[][a-z,A-Z]{4,}[]]')
  4924.             $mASMSize += 6
  4925.             $mASMString &= '8B1D[' & StringMid($aASM, 15, StringLen($aASM) - 15) & ']'
  4926.         Case StringRegExp($aASM, 'mov ecx,dword[[][a-z,A-Z]{4,}[]]')
  4927.             $mASMSize += 6
  4928.             $mASMString &= '8B0D[' & StringMid($aASM, 15, StringLen($aASM) - 15) & ']'
  4929.         Case StringRegExp($aASM, 'mov edx,dword[[][a-z,A-Z]{4,}[]]')
  4930.             $mASMSize += 6
  4931.             $mASMString &= '8B15[' & StringMid($aASM, 15, StringLen($aASM) - 15) & ']'
  4932.         Case StringRegExp($aASM, 'mov esi,dword[[][a-z,A-Z]{4,}[]]')
  4933.             $mASMSize += 6
  4934.             $mASMString &= '8B35[' & StringMid($aASM, 15, StringLen($aASM) - 15) & ']'
  4935.         Case StringRegExp($aASM, 'mov edi,dword[[][a-z,A-Z]{4,}[]]')
  4936.             $mASMSize += 6
  4937.             $mASMString &= '8B3D[' & StringMid($aASM, 15, StringLen($aASM) - 15) & ']'
  4938.         Case StringRegExp($aASM, 'cmp ebx,dword\[[a-z,A-Z]{4,}\]')
  4939.             $mASMSize += 6
  4940.             $mASMString &= '3B1D[' & StringMid($aASM, 15, StringLen($aASM) - 15) & ']'
  4941.         Case StringRegExp($aASM, 'lea eax,dword[[]ecx[*]8[+][a-z,A-Z]{4,}[]]')
  4942.             $mASMSize += 7
  4943.             $mASMString &= '8D04CD[' & StringMid($aASM, 21, StringLen($aASM) - 21) & ']'
  4944.         Case StringRegExp($aASM, 'lea edi,dword\[edx\+[a-z,A-Z]{4,}\]')
  4945.             $mASMSize += 7
  4946.             $mASMString &= '8D3C15[' & StringMid($aASM, 19, StringLen($aASM) - 19) & ']'
  4947.         Case StringRegExp($aASM, 'cmp dword[[][a-z,A-Z]{4,}[]],[-[:xdigit:]]')
  4948.             $lBuffer = StringInStr($aASM, ",")
  4949.             $lBuffer = ASMNumber(StringMid($aASM, $lBuffer + 1), True)
  4950.             If @extended Then
  4951.                 $mASMSize += 7
  4952.                 $mASMString &= '833D[' & StringMid($aASM, 11, StringInStr($aASM, ",") - 12) & ']' & $lBuffer
  4953.             Else
  4954.                 $mASMSize += 10
  4955.                 $mASMString &= '813D[' & StringMid($aASM, 11, StringInStr($aASM, ",") - 12) & ']' & $lBuffer
  4956.             EndIf
  4957.         Case StringRegExp($aASM, 'cmp ecx,[a-z,A-Z]{4,}') And StringInStr($aASM, ',dword') = 0
  4958.             $mASMSize += 6
  4959.             $mASMString &= '81F9[' & StringRight($aASM, StringLen($aASM) - 8) & ']'
  4960.         Case StringRegExp($aASM, 'cmp ebx,[a-z,A-Z]{4,}') And StringInStr($aASM, ',dword') = 0
  4961.             $mASMSize += 6
  4962.             $mASMString &= '81FB[' & StringRight($aASM, StringLen($aASM) - 8) & ']'
  4963.         Case StringRegExp($aASM, 'cmp eax,[a-z,A-Z]{4,}') And StringInStr($aASM, ',dword') = 0
  4964.             $mASMSize += 5
  4965.             $mASMString &= '3D[' & StringRight($aASM, StringLen($aASM) - 8) & ']'
  4966.         Case StringRegExp($aASM, 'add eax,[a-z,A-Z]{4,}') And StringInStr($aASM, ',dword') = 0
  4967.             $mASMSize += 5
  4968.             $mASMString &= '05[' & StringRight($aASM, StringLen($aASM) - 8) & ']'
  4969.         Case StringRegExp($aASM, 'mov eax,[a-z,A-Z]{4,}') And StringInStr($aASM, ',dword') = 0
  4970.             $mASMSize += 5
  4971.             $mASMString &= 'B8[' & StringRight($aASM, StringLen($aASM) - 8) & ']'
  4972.         Case StringRegExp($aASM, 'mov ebx,[a-z,A-Z]{4,}') And StringInStr($aASM, ',dword') = 0
  4973.             $mASMSize += 5
  4974.             $mASMString &= 'BB[' & StringRight($aASM, StringLen($aASM) - 8) & ']'
  4975.         Case StringRegExp($aASM, 'mov esi,[a-z,A-Z]{4,}') And StringInStr($aASM, ',dword') = 0
  4976.             $mASMSize += 5
  4977.             $mASMString &= 'BE[' & StringRight($aASM, StringLen($aASM) - 8) & ']'
  4978.         Case StringRegExp($aASM, 'mov edi,[a-z,A-Z]{4,}') And StringInStr($aASM, ',dword') = 0
  4979.             $mASMSize += 5
  4980.             $mASMString &= 'BF[' & StringRight($aASM, StringLen($aASM) - 8) & ']'
  4981.         Case StringRegExp($aASM, 'mov edx,[a-z,A-Z]{4,}') And StringInStr($aASM, ',dword') = 0
  4982.             $mASMSize += 5
  4983.             $mASMString &= 'BA[' & StringRight($aASM, StringLen($aASM) - 8) & ']'
  4984.         Case StringRegExp($aASM, 'mov dword[[][a-z,A-Z]{4,}[]],ecx')
  4985.             $mASMSize += 6
  4986.             $mASMString &= '890D[' & StringMid($aASM, 11, StringLen($aASM) - 15) & ']'
  4987.         Case StringRegExp($aASM, 'fstp dword[[][a-z,A-Z]{4,}[]]')
  4988.             $mASMSize += 6
  4989.             $mASMString &= 'D91D[' & StringMid($aASM, 12, StringLen($aASM) - 12) & ']'
  4990.         Case StringRegExp($aASM, 'mov dword[[][a-z,A-Z]{4,}[]],edx')
  4991.             $mASMSize += 6
  4992.             $mASMString &= '8915[' & StringMid($aASM, 11, StringLen($aASM) - 15) & ']'
  4993.         Case StringRegExp($aASM, 'mov dword[[][a-z,A-Z]{4,}[]],eax')
  4994.             $mASMSize += 5
  4995.             $mASMString &= 'A3[' & StringMid($aASM, 11, StringLen($aASM) - 15) & ']'
  4996.         Case StringRegExp($aASM, 'lea eax,dword[[]edx[*]4[+][a-z,A-Z]{4,}[]]')
  4997.             $mASMSize += 7
  4998.             $mASMString &= '8D0495[' & StringMid($aASM, 21, StringLen($aASM) - 21) & ']'
  4999.         Case StringRegExp($aASM, 'mov eax,dword[[]ecx[*]4[+][a-z,A-Z]{4,}[]]')
  5000.             $mASMSize += 7
  5001.             $mASMString &= '8B048D[' & StringMid($aASM, 21, StringLen($aASM) - 21) & ']'
  5002.         Case StringRegExp($aASM, 'mov ecx,dword[[]ecx[*]4[+][a-z,A-Z]{4,}[]]')
  5003.             $mASMSize += 7
  5004.             $mASMString &= '8B0C8D[' & StringMid($aASM, 21, StringLen($aASM) - 21) & ']'
  5005.         Case StringRegExp($aASM, 'push dword[[][a-z,A-Z]{4,}[]]')
  5006.             $mASMSize += 6
  5007.             $mASMString &= 'FF35[' & StringMid($aASM, 12, StringLen($aASM) - 12) & ']'
  5008.         Case StringRegExp($aASM, 'push [a-z,A-Z]{4,}\z')
  5009.             $mASMSize += 5
  5010.             $mASMString &= '68[' & StringMid($aASM, 6, StringLen($aASM) - 5) & ']'
  5011.         Case StringRegExp($aASM, 'call dword[[][a-z,A-Z]{4,}[]]')
  5012.             $mASMSize += 6
  5013.             $mASMString &= 'FF15[' & StringMid($aASM, 12, StringLen($aASM) - 12) & ']'
  5014.         Case StringLeft($aASM, 5) = 'call ' And StringLen($aASM) > 8
  5015.             $mASMSize += 5
  5016.             $mASMString &= 'E8{' & StringMid($aASM, 6, StringLen($aASM) - 5) & '}'
  5017.         Case StringRegExp($aASM, 'mov dword\[[a-z,A-Z]{4,}\],[-[:xdigit:]]{1,8}\z')
  5018.             $lBuffer = StringInStr($aASM, ",")
  5019.             $mASMSize += 10
  5020.             $mASMString &= 'C705[' & StringMid($aASM, 11, $lBuffer - 12) & ']' & ASMNumber(StringMid($aASM, $lBuffer + 1))
  5021.         Case StringRegExp($aASM, 'push [-[:xdigit:]]{1,8}\z')
  5022.             $lBuffer = ASMNumber(StringMid($aASM, 6), True)
  5023.             If @extended Then
  5024.                 $mASMSize += 2
  5025.                 $mASMString &= '6A' & $lBuffer
  5026.             Else
  5027.                 $mASMSize += 5
  5028.                 $mASMString &= '68' & $lBuffer
  5029.             EndIf
  5030.         Case StringRegExp($aASM, 'mov eax,[-[:xdigit:]]{1,8}\z')
  5031.             $mASMSize += 5
  5032.             $mASMString &= 'B8' & ASMNumber(StringMid($aASM, 9))
  5033.         Case StringRegExp($aASM, 'mov ebx,[-[:xdigit:]]{1,8}\z')
  5034.             $mASMSize += 5
  5035.             $mASMString &= 'BB' & ASMNumber(StringMid($aASM, 9))
  5036.         Case StringRegExp($aASM, 'mov ecx,[-[:xdigit:]]{1,8}\z')
  5037.             $mASMSize += 5
  5038.             $mASMString &= 'B9' & ASMNumber(StringMid($aASM, 9))
  5039.         Case StringRegExp($aASM, 'mov edx,[-[:xdigit:]]{1,8}\z')
  5040.             $mASMSize += 5
  5041.             $mASMString &= 'BA' & ASMNumber(StringMid($aASM, 9))
  5042.         Case StringRegExp($aASM, 'add eax,[-[:xdigit:]]{1,8}\z')
  5043.             $lBuffer = ASMNumber(StringMid($aASM, 9), True)
  5044.             If @extended Then
  5045.                 $mASMSize += 3
  5046.                 $mASMString &= '83C0' & $lBuffer
  5047.             Else
  5048.                 $mASMSize += 5
  5049.                 $mASMString &= '05' & $lBuffer
  5050.             EndIf
  5051.         Case StringRegExp($aASM, 'add ebx,[-[:xdigit:]]{1,8}\z')
  5052.             $lBuffer = ASMNumber(StringMid($aASM, 9), True)
  5053.             If @extended Then
  5054.                 $mASMSize += 3
  5055.                 $mASMString &= '83C3' & $lBuffer
  5056.             Else
  5057.                 $mASMSize += 6
  5058.                 $mASMString &= '81C3' & $lBuffer
  5059.             EndIf
  5060.         Case StringRegExp($aASM, 'add ecx,[-[:xdigit:]]{1,8}\z')
  5061.             $lBuffer = ASMNumber(StringMid($aASM, 9), True)
  5062.             If @extended Then
  5063.                 $mASMSize += 3
  5064.                 $mASMString &= '83C1' & $lBuffer
  5065.             Else
  5066.                 $mASMSize += 6
  5067.                 $mASMString &= '81C1' & $lBuffer
  5068.             EndIf
  5069.         Case StringRegExp($aASM, 'add edx,[-[:xdigit:]]{1,8}\z')
  5070.             $lBuffer = ASMNumber(StringMid($aASM, 9), True)
  5071.             If @extended Then
  5072.                 $mASMSize += 3
  5073.                 $mASMString &= '83C2' & $lBuffer
  5074.             Else
  5075.                 $mASMSize += 6
  5076.                 $mASMString &= '81C2' & $lBuffer
  5077.             EndIf
  5078.         Case StringRegExp($aASM, 'add edi,[-[:xdigit:]]{1,8}\z')
  5079.             $lBuffer = ASMNumber(StringMid($aASM, 9), True)
  5080.             If @extended Then
  5081.                 $mASMSize += 3
  5082.                 $mASMString &= '83C7' & $lBuffer
  5083.             Else
  5084.                 $mASMSize += 6
  5085.                 $mASMString &= '81C7' & $lBuffer
  5086.             EndIf
  5087.         Case StringRegExp($aASM, 'cmp ebx,[-[:xdigit:]]{1,8}\z')
  5088.             $lBuffer = ASMNumber(StringMid($aASM, 9), True)
  5089.             If @extended Then
  5090.                 $mASMSize += 3
  5091.                 $mASMString &= '83FB' & $lBuffer
  5092.             Else
  5093.                 $mASMSize += 6
  5094.                 $mASMString &= '81FB' & $lBuffer
  5095.             EndIf
  5096.         Case Else
  5097.             Local $lOpCode
  5098.             Switch $aASM
  5099.                 Case 'nop'
  5100.                     $lOpCode = '90'
  5101.                 Case 'pushad'
  5102.                     $lOpCode = '60'
  5103.                 Case 'popad'
  5104.                     $lOpCode = '61'
  5105.                 Case 'mov ebx,dword[eax]'
  5106.                     $lOpCode = '8B18'
  5107.                 Case 'test eax,eax'
  5108.                     $lOpCode = '85C0'
  5109.                 Case 'test ebx,ebx'
  5110.                     $lOpCode = '85DB'
  5111.                 Case 'test ecx,ecx'
  5112.                     $lOpCode = '85C9'
  5113.                 Case 'mov dword[eax],0'
  5114.                     $lOpCode = 'C70000000000'
  5115.                 Case 'push eax'
  5116.                     $lOpCode = '50'
  5117.                 Case 'push ebx'
  5118.                     $lOpCode = '53'
  5119.                 Case 'push ecx'
  5120.                     $lOpCode = '51'
  5121.                 Case 'push edx'
  5122.                     $lOpCode = '52'
  5123.                 Case 'push ebp'
  5124.                     $lOpCode = '55'
  5125.                 Case 'push esi'
  5126.                     $lOpCode = '56'
  5127.                 Case 'push edi'
  5128.                     $lOpCode = '57'
  5129.                 Case 'jmp ebx'
  5130.                     $lOpCode = 'FFE3'
  5131.                 Case 'pop eax'
  5132.                     $lOpCode = '58'
  5133.                 Case 'pop ebx'
  5134.                     $lOpCode = '5B'
  5135.                 Case 'pop edx'
  5136.                     $lOpCode = '5A'
  5137.                 Case 'pop ecx'
  5138.                     $lOpCode = '59'
  5139.                 Case 'pop esi'
  5140.                     $lOpCode = '5E'
  5141.                 Case 'inc eax'
  5142.                     $lOpCode = '40'
  5143.                 Case 'inc ecx'
  5144.                     $lOpCode = '41'
  5145.                 Case 'inc ebx'
  5146.                     $lOpCode = '43'
  5147.                 Case 'dec edx'
  5148.                     $lOpCode = '4A'
  5149.                 Case 'mov edi,edx'
  5150.                     $lOpCode = '8BFA'
  5151.                 Case 'mov ecx,esi'
  5152.                     $lOpCode = '8BCE'
  5153.                 Case 'mov ecx,edi'
  5154.                     $lOpCode = '8BCF'
  5155.                 Case 'xor eax,eax'
  5156.                     $lOpCode = '33C0'
  5157.                 Case 'xor ecx,ecx'
  5158.                     $lOpCode = '33C9'
  5159.                 Case 'xor edx,edx'
  5160.                     $lOpCode = '33D2'
  5161.                 Case 'xor ebx,ebx'
  5162.                     $lOpCode = '33DB'
  5163.                 Case 'mov edx,eax'
  5164.                     $lOpCode = '8BD0'
  5165.                 Case 'mov ebp,esp'
  5166.                     $lOpCode = '8BEC'
  5167.                 Case 'sub esp,8'
  5168.                     $lOpCode = '83EC08'
  5169.                 Case 'sub esp,14'
  5170.                     $lOpCode = '83EC14'
  5171.                 Case 'cmp ecx,4'
  5172.                     $lOpCode = '83F904'
  5173.                 Case 'cmp ecx,32'
  5174.                     $lOpCode = '83F932'
  5175.                 Case 'cmp ecx,3C'
  5176.                     $lOpCode = '83F93C'
  5177.                 Case 'mov ecx,edx'
  5178.                     $lOpCode = '8BCA'
  5179.                 Case 'mov eax,ecx'
  5180.                     $lOpCode = '8BC1'
  5181.                 Case 'mov ecx,dword[ebp+8]'
  5182.                     $lOpCode = '8B4D08'
  5183.                 Case 'mov ecx,dword[esp+1F4]'
  5184.                     $lOpCode = '8B8C24F4010000'
  5185.                 Case 'mov ecx,dword[edi+4]'
  5186.                     $lOpCode = '8B4F04'
  5187.                 Case 'mov ecx,dword[edi+8]'
  5188.                     $lOpCode = '8B4F08'
  5189.                 Case 'mov eax,dword[edi+4]'
  5190.                     $lOpCode = '8B4704'
  5191.                 Case 'mov dword[eax+4],ecx'
  5192.                     $lOpCode = '894804'
  5193.                 Case 'mov dword[eax+8],ecx'
  5194.                     $lOpCode = '894808'
  5195.                 Case 'mov dword[eax+C],ecx'
  5196.                     $lOpCode = '89480C'
  5197.                 Case 'mov dword[esi+10],eax'
  5198.                     $lOpCode = '894610'
  5199.                 Case 'mov ecx,dword[edi]'
  5200.                     $lOpCode = '8B0F'
  5201.                 Case 'mov dword[eax],ecx'
  5202.                     $lOpCode = '8908'
  5203.                 Case 'mov dword[eax],ebx'
  5204.                     $lOpCode = '8918'
  5205.                 Case 'mov edx,dword[eax+4]'
  5206.                     $lOpCode = '8B5004'
  5207.                 Case 'mov edx,dword[eax+c]'
  5208.                     $lOpCode = '8B500C'
  5209.                 Case 'mov edx,dword[esi+1c]'
  5210.                     $lOpCode = '8B561C'
  5211.                 Case 'push dword[eax+8]'
  5212.                     $lOpCode = 'FF7008'
  5213.                 Case 'lea eax,dword[eax+18]'
  5214.                     $lOpCode = '8D4018'
  5215.                 Case 'lea ecx,dword[eax+4]'
  5216.                     $lOpCode = '8D4804'
  5217.                 Case 'lea edx,dword[eax+4]'
  5218.                     $lOpCode = '8D5004'
  5219.                 Case 'lea edx,dword[eax+8]'
  5220.                     $lOpCode = '8D5008'
  5221.                 Case 'mov ecx,dword[eax+4]'
  5222.                     $lOpCode = '8B4804'
  5223.                 Case 'mov ecx,dword[eax+8]'
  5224.                     $lOpCode = '8B4808'
  5225.                 Case 'mov eax,dword[eax+8]'
  5226.                     $lOpCode = '8B4008'
  5227.                 Case 'mov eax,dword[eax+4]'
  5228.                     $lOpCode = '8B4004'
  5229.                 Case 'push dword[eax+4]'
  5230.                     $lOpCode = 'FF7004'
  5231.                 Case 'push dword[eax+c]'
  5232.                     $lOpCode = 'FF700C'
  5233.                 Case 'mov esp,ebp'
  5234.                     $lOpCode = '8BE5'
  5235.                 Case 'mov esp,ebp'
  5236.                     $lOpCode = '8BE5'
  5237.                 Case 'pop ebp'
  5238.                     $lOpCode = '5D'
  5239.                 Case 'retn 10'
  5240.                     $lOpCode = 'C21000'
  5241.                 Case 'cmp eax,2'
  5242.                     $lOpCode = '83F802'
  5243.                 Case 'cmp eax,0'
  5244.                     $lOpCode = '83F800'
  5245.                 Case 'cmp eax,B'
  5246.                     $lOpCode = '83F80B'
  5247.                 Case 'cmp eax,200'
  5248.                     $lOpCode = '3D00020000'
  5249.                 Case 'shl eax,4'
  5250.                     $lOpCode = 'C1E004'
  5251.                 Case 'shl eax,8'
  5252.                     $lOpCode = 'C1E008'
  5253.                 Case 'shl eax,6'
  5254.                     $lOpCode = 'C1E006'
  5255.                 Case 'shl eax,7'
  5256.                     $lOpCode = 'C1E007'
  5257.                 Case 'shl eax,8'
  5258.                     $lOpCode = 'C1E008'
  5259.                 Case 'shl eax,9'
  5260.                     $lOpCode = 'C1E009'
  5261.                 Case 'mov edi,eax'
  5262.                     $lOpCode = '8BF8'
  5263.                 Case 'mov dx,word[ecx]'
  5264.                     $lOpCode = '668B11'
  5265.                 Case 'mov dx,word[edx]'
  5266.                     $lOpCode = '668B12'
  5267.                 Case 'mov word[eax],dx'
  5268.                     $lOpCode = '668910'
  5269.                 Case 'test dx,dx'
  5270.                     $lOpCode = '6685D2'
  5271.                 Case 'cmp word[edx],0'
  5272.                     $lOpCode = '66833A00'
  5273.                 Case 'cmp eax,ebx'
  5274.                     $lOpCode = '3BC3'
  5275.                 Case 'cmp eax,ecx'
  5276.                     $lOpCode = '3BC1'
  5277.                 Case 'mov eax,dword[esi+8]'
  5278.                     $lOpCode = '8B4608'
  5279.                 Case 'mov ecx,dword[eax]'
  5280.                     $lOpCode = '8B08'
  5281.                 Case 'mov ebx,edi'
  5282.                     $lOpCode = '8BDF'
  5283.                 Case 'mov ebx,eax'
  5284.                     $lOpCode = '8BD8'
  5285.                 Case 'mov eax,edi'
  5286.                     $lOpCode = '8BC7'
  5287.                 Case 'mov al,byte[ebx]'
  5288.                     $lOpCode = '8A03'
  5289.                 Case 'test al,al'
  5290.                     $lOpCode = '84C0'
  5291.                 Case 'mov eax,dword[ecx]'
  5292.                     $lOpCode = '8B01'
  5293.                 Case 'lea ecx,dword[eax+180]'
  5294.                     $lOpCode = '8D8880010000'
  5295.                 Case 'mov ebx,dword[ecx+14]'
  5296.                     $lOpCode = '8B5914'
  5297.                 Case 'mov eax,dword[ebx+c]'
  5298.                     $lOpCode = '8B430C'
  5299.                 Case 'mov ecx,eax'
  5300.                     $lOpCode = '8BC8'
  5301.                 Case 'cmp eax,-1'
  5302.                     $lOpCode = '83F8FF'
  5303.                 Case 'mov al,byte[ecx]'
  5304.                     $lOpCode = '8A01'
  5305.                 Case 'mov ebx,dword[edx]'
  5306.                     $lOpCode = '8B1A'
  5307.                 Case 'lea edi,dword[edx+ebx]'
  5308.                     $lOpCode = '8D3C1A'
  5309.                 Case 'mov ah,byte[edi]'
  5310.                     $lOpCode = '8A27'
  5311.                 Case 'cmp al,ah'
  5312.                     $lOpCode = '3AC4'
  5313.                 Case 'mov dword[edx],0'
  5314.                     $lOpCode = 'C70200000000'
  5315.                 Case 'mov dword[ebx],ecx'
  5316.                     $lOpCode = '890B'
  5317.                 Case 'cmp edx,esi'
  5318.                     $lOpCode = '3BD6'
  5319.                 Case 'cmp ecx,900000'
  5320.                     $lOpCode = '81F900009000'
  5321.                 Case 'mov edi,dword[edx+4]'
  5322.                     $lOpCode = '8B7A04'
  5323.                 Case 'cmp ebx,edi'
  5324.                     $lOpCode = '3BDF'
  5325.                 Case 'mov dword[edx],ebx'
  5326.                     $lOpCode = '891A'
  5327.                 Case 'lea edi,dword[edx+8]'
  5328.                     $lOpCode = '8D7A08'
  5329.                 Case 'mov dword[edi],ecx'
  5330.                     $lOpCode = '890F'
  5331.                 Case 'retn'
  5332.                     $lOpCode = 'C3'
  5333.                 Case 'mov dword[edx],-1'
  5334.                     $lOpCode = 'C702FFFFFFFF'
  5335.                 Case 'cmp eax,1'
  5336.                     $lOpCode = '83F801'
  5337.                 Case 'mov eax,dword[ebp+37c]'
  5338.                     $lOpCode = '8B857C030000'
  5339.                 Case 'mov eax,dword[ebp+338]'
  5340.                     $lOpCode = '8B8538030000'
  5341.                 Case 'mov ecx,dword[ebx+250]'
  5342.                     $lOpCode = '8B8B50020000'
  5343.                 Case 'mov ecx,dword[ebx+194]'
  5344.                     $lOpCode = '8B8B94010000'
  5345.                 Case 'mov ecx,dword[ebx+18]'
  5346.                     $lOpCode = '8B5918'
  5347.                 Case 'mov ecx,dword[ebx+40]'
  5348.                     $lOpCode = '8B5940'
  5349.                 Case 'mov ebx,dword[ecx+10]'
  5350.                     $lOpCode = '8B5910'
  5351.                 Case 'mov ebx,dword[ecx+18]'
  5352.                     $lOpCode = '8B5918'
  5353.                 Case 'mov ebx,dword[ecx+4c]'
  5354.                     $lOpCode = '8B594C'
  5355.                 Case 'mov ecx,dword[ebx]'
  5356.                     $lOpCode = '8B0B'
  5357.                 Case 'mov edx,esp'
  5358.                     $lOpCode = '8BD4'
  5359.                 Case 'mov ecx,dword[ebx+170]'
  5360.                     $lOpCode = '8B8B70010000'
  5361.                 Case 'cmp eax,dword[esi+9C]'
  5362.                     $lOpCode = '3B869C000000'
  5363.                 Case 'mov ebx,dword[ecx+20]'
  5364.                     $lOpCode = '8B5920'
  5365.                 Case 'mov ecx,dword[ecx]'
  5366.                     $lOpCode = '8B09'
  5367.                 Case 'mov eax,dword[ecx+40]'
  5368.                     $lOpCode = '8B4140'
  5369.                 Case 'mov ecx,dword[ecx+10]'
  5370.                     $lOpCode = '8B4910'
  5371.                 Case 'mov ecx,dword[ecx+18]'
  5372.                     $lOpCode = '8B4918'
  5373.                 Case 'mov ecx,dword[ecx+20]'
  5374.                     $lOpCode = '8B4920'
  5375.                 Case 'mov ecx,dword[ecx+4c]'
  5376.                     $lOpCode = '8B494C'
  5377.                 Case 'mov ecx,dword[ecx+170]'
  5378.                     $lOpCode = '8B8970010000'
  5379.                 Case 'mov ecx,dword[ecx+194]'
  5380.                     $lOpCode = '8B8994010000'
  5381.                 Case 'mov ecx,dword[ecx+250]'
  5382.                     $lOpCode = '8B8950020000'
  5383.                 Case 'mov al,byte[ecx+4f]'
  5384.                     $lOpCode = '8A414F'
  5385.                 Case 'mov al,byte[ecx+3f]'
  5386.                     $lOpCode = '8A413F'
  5387.                 Case 'cmp al,f'
  5388.                     $lOpCode = '3C0F'
  5389.                 Case 'lea esi,dword[esi+ebx*4]'
  5390.                     $lOpCode = '8D349E'
  5391.                 Case 'mov esi,dword[esi]'
  5392.                     $lOpCode = '8B36'
  5393.                 Case 'test esi,esi'
  5394.                     $lOpCode = '85F6'
  5395.                 Case 'clc'
  5396.                     $lOpCode = 'F8'
  5397.                 Case 'repe movsb'
  5398.                     $lOpCode = 'F3A4'
  5399.                 Case 'inc edx'
  5400.                     $lOpCode = '42'
  5401.                 Case Else
  5402.                     MsgBox(0, 'ASM', 'Could not assemble: ' & $aASM)
  5403.                     Exit
  5404.             EndSwitch
  5405.             $mASMSize += 0.5 * StringLen($lOpCode)
  5406.             $mASMString &= $lOpCode
  5407.     EndSelect
  5408. EndFunc   ;==>_
  5409.  
  5410. ;~ Description: Internal use only.
  5411. Func CompleteASMCode()
  5412.     Local $lInExpression = False
  5413.     Local $lExpression
  5414.     Local $lTempASM = $mASMString
  5415.     Local $lCurrentOffset = Dec(Hex($mMemory)) + $mASMCodeOffset
  5416.     Local $lToken
  5417.  
  5418.     For $i = 1 To $mLabels[0][0]
  5419.         If StringLeft($mLabels[$i][0], 6) = 'Label_' Then
  5420.             $mLabels[$i][0] = StringTrimLeft($mLabels[$i][0], 6)
  5421.             $mLabels[$i][1] = $mMemory + $mLabels[$i][1]
  5422.         EndIf
  5423.     Next
  5424.  
  5425.     $mASMString = ''
  5426.     For $i = 1 To StringLen($lTempASM)
  5427.         $lToken = StringMid($lTempASM, $i, 1)
  5428.         Switch $lToken
  5429.             Case '(', '[', '{'
  5430.                 $lInExpression = True
  5431.             Case ')'
  5432.                 $mASMString &= Hex(GetLabelInfo($lExpression) - Int($lCurrentOffset) - 1, 2)
  5433.                 $lCurrentOffset += 1
  5434.                 $lInExpression = False
  5435.                 $lExpression = ''
  5436.             Case ']'
  5437.                 $mASMString &= SwapEndian(Hex(GetLabelInfo($lExpression), 8))
  5438.                 $lCurrentOffset += 4
  5439.                 $lInExpression = False
  5440.                 $lExpression = ''
  5441.             Case '}'
  5442.                 $mASMString &= SwapEndian(Hex(GetLabelInfo($lExpression) - Int($lCurrentOffset) - 4, 8))
  5443.                 $lCurrentOffset += 4
  5444.                 $lInExpression = False
  5445.                 $lExpression = ''
  5446.             Case Else
  5447.                 If $lInExpression Then
  5448.                     $lExpression &= $lToken
  5449.                 Else
  5450.                     $mASMString &= $lToken
  5451.                     $lCurrentOffset += 0.5
  5452.                 EndIf
  5453.         EndSwitch
  5454.     Next
  5455. EndFunc   ;==>CompleteASMCode
  5456.  
  5457. ;~ Description: Internal use only.
  5458. Func GetLabelInfo($aLabel)
  5459.     Local $lValue = GetValue($aLabel)
  5460.     If $lValue = -1 Then Exit MsgBox(0, 'Label', 'Label: ' & $aLabel & ' not provided')
  5461.     Return $lValue ;Dec(StringRight($lValue, 8))
  5462. EndFunc   ;==>GetLabelInfo
  5463.  
  5464. ;~ Description: Internal use only.
  5465. Func ASMNumber($aNumber, $aSmall = False)
  5466.     If $aNumber >= 0 Then
  5467.         $aNumber = Dec($aNumber)
  5468.     EndIf
  5469.     If $aSmall And $aNumber <= 127 And $aNumber >= -128 Then
  5470.         Return SetExtended(1, Hex($aNumber, 2))
  5471.     Else
  5472.         Return SetExtended(0, SwapEndian(Hex($aNumber, 8)))
  5473.     EndIf
  5474. EndFunc   ;==>ASMNumber
  5475. #EndRegion Assembler
  5476.  
  5477. Func ToggleRendering()
  5478.     If $Rendering Then
  5479.         DisableRendering()
  5480.         WinSetState(GetWindowHandle(), "", @SW_HIDE)
  5481.         ClearMemory()
  5482.     Else
  5483.         EnableRendering()
  5484.         WinSetState(GetWindowHandle(), "", @SW_SHOW)
  5485.     EndIf
  5486.     $Rendering = Not $Rendering
  5487. EndFunc
  5488.  
  5489. Func GetNumberOfFoesInRangeOfAgent($aAgent = -2, $aRange = 1250)
  5490.     Local $lAgent, $lDistance
  5491.     Local $lCount = 0
  5492.  
  5493.     If Not IsDllStruct($aAgent) Then $aAgent = GetAgentByID($aAgent)
  5494.  
  5495.     For $i = 1 To GetMaxAgents()
  5496.         $lAgent = GetAgentByID($i)
  5497.         If BitAND(DllStructGetData($lAgent, 'typemap'), 262144) Then ContinueLoop
  5498.         If DllStructGetData($lAgent, 'Type') <> 0xDB Then ContinueLoop
  5499.         If DllStructGetData($lAgent, 'Allegiance') <> 3 Then ContinueLoop
  5500.  
  5501.              If DllStructGetData($lAgent, 'HP') <= 0 Then ContinueLoop
  5502.         If BitAND(DllStructGetData($lAgent, 'Effects'), 0x0010) > 0 Then ContinueLoop
  5503.         $lDistance = GetDistance($lAgent)
  5504.  
  5505.         If $lDistance > $aRange Then ContinueLoop
  5506.         $lCount += 1
  5507.     Next
  5508.     Return $lCount
  5509.  EndFunc   ;==>GetNumberOfFoesInRangeOfAgent
  5510.  
  5511. Func IsRecharged($lSkill)
  5512.     Return GetSkillbarSkillRecharge($lSkill) == 0
  5513. EndFunc   ;==>IsRecharged
  5514.  
  5515.  
  5516. Func _PurgeHook()
  5517.     ; ToggleRendering()
  5518.     Sleep(Random(4000, 5000))
  5519.     ; ToggleRendering()
  5520. EndFunc   ;==>_PurgeHook
  5521.  
  5522. #EndRegion Other Functions
Add Comment
Please, Sign In to add comment