Advertisement
Guest User

Untitled

a guest
Oct 13th, 2015
148
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.42 KB | None | 0 0
  1. ; POE Simple Price Check
  2. ; Version: 5.1 (2015/08/11)
  3. ;
  4. ; Written by Pete Waterman aka trackpete on reddit, pwx* in game
  5. ; http://exiletools.com (used to be http://poe.pwx.me)
  6. ;
  7. ; CONFIGURATION NOTE: You must configure the LeagueName properly. Otherwise it will default to
  8. ; "Standard" - press ^F and search for LeagueName and you will find where to set it.
  9. ;
  10. ; For a list of valid leagues, go here and scroll down to "Active Leagues:"
  11. ; http://api.exiletools.com/ladder
  12. ;
  13. ; USAGE NOTE: This requires your Path of Exile to be in Windowed (or Windowed Full Screen)
  14. ; to work properly, otherwise the popup will just show in the background and you won't
  15. ; see it. Also, you *must* use the AHK from http://ahkscript.org NOT NOT autohotkey.com!
  16. ;
  17. ; WINDOWS 10 NOTE: You may need to run this .ahk file as an Administrator in order for the popups
  18. ; to show properly.
  19. ;
  20. ; INDEXER NOTE: I do not use poe.trade in any way. I run my own indexer, which lets me
  21. ; provide far more in-depth and advanced statistics than I could get from using
  22. ; poe.trade. The results will not always exactly match poe.trade. You can read more
  23. ; about this here: http://exiletools.com/blog
  24. ;
  25. ; CURRENCY NOTE: The "Chaos" values you see in this data are "Chaos Equivalent Values."
  26. ; These values are *FIXED* and do not fluctuate with the actual rates you will get
  27. ; in trade/etc. They are for *reference* only, because people hated this macro when it
  28. ; returned prices in a bunch of different currency types. You can see the rates I
  29. ; use to create these reference values here: http://exiletools.com/rates
  30. ;
  31. ; AUTHOR'S NOTE: I'm not an AHK programmer, I learned everything on the fly. There is a
  32. ; good chance this code will look sloppy to experienced AHK programmers, if you have any
  33. ; advice or would like to re-write it, please feel free and let me know.
  34. ;
  35. ; Wow, I clearly need to add some more NOTES. Maybe a NOTE on the weather? It's raining
  36. ; outside right now.
  37. ;
  38. ; ===================================================
  39. ; Change Log
  40. ; v1 (2014/07/29): Initial Release
  41. ; v2 (2014/08/18): +Features
  42. ; v3 (2014/08/19): +Features
  43. ; v4 (2014/09/25): +Features
  44. ; v5 (2015/07/06): An all-new release!
  45. ; v5.1 (2015/08/11): Added proper encoding for item post data so my server sees + signs
  46. ;
  47. ; Version 5 works in a completely different way from previous versions:
  48. ; It now sends the raw item data to my service via POST and simply displays the results.
  49. ;
  50. ; The big reason for this is that I can now do all item processing server-side. This allows
  51. ; me to increment parsing options, such as adding Divination Card capability/etc., without
  52. ; needing to push new versions to clients.
  53. ;
  54. ;
  55.  
  56. ; == Startup Options ===========================================
  57. #SingleInstance force
  58. #NoEnv
  59. #Persistent ; Stay open in background
  60. SendMode Input
  61. StringCaseSense, On ; Match strings with case.
  62. Menu, tray, Tip, Exile Tools Price Check
  63.  
  64. If (A_AhkVersion <= "1.1.22")
  65. {
  66. msgbox, You need AutoHotkey v1.1.22 or later to run this script. `n`nPlease go to http://ahkscript.org/download and download a recent version.
  67. exit
  68. }
  69.  
  70. ; == Variables and Options and Stuff ===========================
  71.  
  72. ; *******************************************************************
  73. ; *******************************************************************
  74. ; SET LEAGUENAME BELOW!!
  75. ; *******************************************************************
  76. ; *******************************************************************
  77. ; Option for LeagueName - this must be specified.
  78. ; Remove the ; from in front of the line that has the leaguename you
  79. ; want, or just change the uncommented line to say what you want.
  80. ; Make sure all other LeagueName lines have a ; in front of them (commented)
  81. ; or are removed
  82.  
  83. global LeagueName := "flashback2"
  84. ;global LeagueName := "tempest"
  85. ;global LeagueName := "standard"
  86. ;global LeagueName := "hardcore"
  87.  
  88. ; showDays - This filters results to items that are in shops which have been updated
  89. ; without the last # of days. The default is 7. There is not really any need to change
  90. ; this unless you really want the freshest prices, then you can try setting this to 3 or 4.
  91. ; Any lower and it will start to return a much smaller result set.
  92. global showDays := "7"
  93.  
  94. ; runVersion - Sets the internal run version so that I can warn you if this macro
  95. ; is out of date.
  96. global runVersion := "5.1"
  97.  
  98. ; Decoder URL - DO NOT CHANGE THIS! This is a development option.
  99. ; Instead of doing all the processing in AHK, this script simply sends basic
  100. ; item information to a decoder service which checks for price information against
  101. ; my own item index.
  102. Global URL = "http://api.exiletools.com/item-report-text"
  103.  
  104. ; How much the mouse needs to move before the hotkey goes away, not a big deal, change to whatever
  105. MouseMoveThreshold := 40
  106. CoordMode, Mouse, Screen
  107. CoordMode, ToolTip, Screen
  108.  
  109. ; There are multiple hotkeys to run this script now, defaults set as follows:
  110. ; ^p (CTRL-p) - Sends the item information to my server, where a price check is performed. Levels and quality will be automatically processed.
  111. ; ^i (CTRL-i) - Pulls up an interactive search box that goes away after 30s or when you hit enter/ok
  112. ;
  113. ; To modify these, you will need to modify the function call headers below
  114. ; see http://www.autohotkey.com/docs/Hotkeys.htm for hotkey options
  115.  
  116.  
  117. ; Price check w/ auto filters
  118. ^p::
  119. IfWinActive, Path of Exile ahk_class Direct3DWindowClass
  120. {
  121. FunctionReadItemFromClipboard()
  122. }
  123. return
  124.  
  125. ; Custom Input String Search
  126. ^i::
  127. IfWinActive, Path of Exile ahk_class Direct3DWindowClass
  128. {
  129. ; This grabs a text message from my server so that I can add functionality
  130. ; to the interactive search and document it without users having to download
  131. ; a new macro.
  132. gettxt := ComObjCreate("WinHttp.WinHttpRequest.5.1")
  133. gettxt.Open("GET", "http://exiletools.com/price-macro-input.txt")
  134. gettxt.Send
  135. macroprompt := gettxt.ResponseText
  136.  
  137. Prompt := macroprompt
  138. Global X
  139. Global Y
  140. MouseGetPos, X, Y
  141. InputBox,ItemName,Interactive Price Search,%Prompt%,,500,300,X-160,Y - 250,,30,
  142. if ItemName {
  143. Global PostData = "v=" . runVersion . "&interactiveSearch=" . ItemName . "&league=" . LeagueName . "&showDays=" . showDays . ""
  144. FunctionPostItemData(URL, "null", "isInteractive")
  145. }
  146. }
  147. return
  148.  
  149.  
  150. ; == Function Stuff =======================================
  151.  
  152. FunctionPostItemData(URL, ItemData, InteractiveCheck)
  153. {
  154. ; This is for debug purposes, it should be commented out in normal use
  155. ; MsgBox, %URL%
  156. ; MsgBox, %ItemData%
  157.  
  158. ; URI Encode ItemData to avoid any problem
  159. ItemData := FunctionUriEncode(ItemData)
  160.  
  161. if (InteractiveCheck = "isInteractive") {
  162. temporaryContent = Submitting interactive search to exiletools.com...
  163. FunctionShowToolTipPriceInfo(temporaryContent)
  164. } else {
  165. temporaryContent = Submitting item information to exiletools.com...
  166. FunctionShowToolTipPriceInfo(temporaryContent)
  167. ; Create PostData
  168. Global PostData = "v=" . runVersion . "&itemData=" . ItemData . "&league=" . LeagueName . "&showDays=" . showDays . ""
  169. }
  170.  
  171. ; Send the PostData to my server and check the response!
  172. whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
  173. whr.Open("POST", URL)
  174. whr.SetRequestHeader("Content-Type","application/x-www-form-urlencoded")
  175. whr.Send(PostData)
  176. rawcontent := whr.ResponseText
  177.  
  178. ; The return data has a special line that can be pasted into chat/etc., this
  179. ; separates that out and copies it to the clipboard.
  180. StringSplit, responsecontent, rawcontent,^
  181. clipboard = %responsecontent2%
  182.  
  183. FunctionShowToolTipPriceInfo(responsecontent1)
  184. }
  185.  
  186. ; This is for the tooltip, so it shows it and starts a timer that watches mouse movement.
  187. ; I imagine there's a better way of doing this. The crazy long name is to avoid
  188. ; overlap with other scripts in case people try to combine these into one big script.
  189.  
  190. FunctionShowToolTipPriceInfo(responsecontent)
  191. {
  192. ; Get position of mouse cursor
  193. Sleep, 2
  194. Global X
  195. Global Y
  196. MouseGetPos, X, Y
  197. gui, font, s15, Verdana
  198. ToolTip, %responsecontent%, X - 135, Y + 30
  199. SetTimer, SubWatchCursorPrice, 100
  200.  
  201. }
  202.  
  203. ; == The Goods =====================================
  204.  
  205. ; Watches the mouse cursor to get rid of the tooltip after too much movement
  206. SubWatchCursorPrice:
  207. MouseGetPos, CurrX, CurrY
  208. MouseMoved := (CurrX - X)**2 + (CurrY - Y)**2 > MouseMoveThreshold**2
  209. If (MouseMoved)
  210. {
  211. SetTimer, SubWatchCursorPrice, Off
  212. ToolTip
  213. }
  214. return
  215.  
  216.  
  217. FunctionReadItemFromClipboard() {
  218. ; Only does anything if POE is the window with focus
  219. IfWinActive, Path of Exile ahk_class Direct3DWindowClass
  220. {
  221. ; Send a ^C to copy the item information to the clipboard
  222. ; Note: This will trigger any Item Info/etc. script that monitors the clipboard
  223. Send ^c
  224. ; Wait 250ms - without this the item information doesn't get to the clipboard in time
  225. Sleep 250
  226. ; Get what's on the clipboard
  227. ClipBoardData = %clipboard%
  228. ; Split the clipboard data into strings to make sure it looks like a properly
  229. ; formatted item, looking for the Rarity: tag in the first line. Just in case
  230. ; something weird got copied to the clipboard.
  231. StringSplit, data, ClipBoardData, `n, `r
  232.  
  233. ; Strip out extra CR chars so my unix side server doesn't do weird things
  234. StringReplace RawItemData, ClipBoardData, `r, , A
  235.  
  236. ; If the first line on the clipboard has Rarity: it is probably some item
  237. ; information from POE, so we'll send it to my server to process. Otherwise
  238. ; we just don't do anything at all.
  239. IfInString, data1, Rarity:
  240. {
  241. ; Do POST / etc.
  242. FunctionPostItemData(URL, RawItemData, "notInteractive")
  243.  
  244. }
  245. }
  246. }
  247.  
  248.  
  249.  
  250. ; Stole this from here: http://www.autohotkey.com/board/topic/75390-ahk-l-unicode-uri-encode-url-encode-function/
  251. ; Hopefully it works right!
  252. FunctionUriEncode(Uri, Enc = "UTF-8")
  253. {
  254. StrPutVar(Uri, Var, Enc)
  255. f := A_FormatInteger
  256. SetFormat, IntegerFast, H
  257. Loop
  258. {
  259. Code := NumGet(Var, A_Index - 1, "UChar")
  260. If (!Code)
  261. Break
  262. If (Code >= 0x30 && Code <= 0x39 ; 0-9
  263. || Code >= 0x41 && Code <= 0x5A ; A-Z
  264. || Code >= 0x61 && Code <= 0x7A) ; a-z
  265. Res .= Chr(Code)
  266. Else
  267. Res .= "%" . SubStr(Code + 0x100, -1)
  268. }
  269. SetFormat, IntegerFast, %f%
  270. Return, Res
  271. }
  272. StrPutVar(Str, ByRef Var, Enc = "")
  273. {
  274. Len := StrPut(Str, Enc) * (Enc = "UTF-16" || Enc = "CP1200" ? 2 : 1)
  275. VarSetCapacity(Var, Len, 0)
  276. Return, StrPut(Str, &Var, Enc)
  277. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement