Skip to content

Commit

Permalink
Merge dev to master (#141)
Browse files Browse the repository at this point in the history
* added fallback (error msg + exit app) for failed league parsing

* changed error msg box options (league parsing)

* changed default hotkey for "show item age"

* Added a separate low/high mod range modifier

* Fixed elemental dps not being displayed on advanced search GUI

* Changed min width of advacned search window

* updated version/notes

* fixed typo
  • Loading branch information
Eruyome authored Dec 16, 2016
1 parent 260352e commit 83d11be
Show file tree
Hide file tree
Showing 9 changed files with 286 additions and 42 deletions.
84 changes: 84 additions & 0 deletions Lib/CalcChecksum.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
HashFile(filePath,hashType=2) ; By Deo, http://www.autohotkey.com/forum/viewtopic.php?t=71133
{
PROV_RSA_AES := 24
CRYPT_VERIFYCONTEXT := 0xF0000000
BUFF_SIZE := 1024 * 1024 ; 1 MB
HP_HASHVAL := 0x0002
HP_HASHSIZE := 0x0004

HASH_ALG := (hashType = 1 OR hashType = "MD2") ? (CALG_MD2 := 32769) : HASH_ALG
HASH_ALG := (hashType = 2 OR hashType = "MD5") ? (CALG_MD5 := 32771) : HASH_ALG
HASH_ALG := (hashType = 3 OR hashType = "SHA") ? (CALG_SHA := 32772) : HASH_ALG
HASH_ALG := (hashType = 4 OR hashType = "SHA256") ? (CALG_SHA_256 := 32780) : HASH_ALG ;Vista+ only
HASH_ALG := (hashType = 5 OR hashType = "SHA384") ? (CALG_SHA_384 := 32781) : HASH_ALG ;Vista+ only
HASH_ALG := (hashType = 6 OR hashType = "SHA512") ? (CALG_SHA_512 := 32782) : HASH_ALG ;Vista+ only

f := FileOpen(filePath,"r","CP0")
if !IsObject(f)
return 0
if !hModule := DllCall( "GetModuleHandleW", "str", "Advapi32.dll", "Ptr" )
hModule := DllCall( "LoadLibraryW", "str", "Advapi32.dll", "Ptr" )
if !dllCall("Advapi32\CryptAcquireContextW"
,"Ptr*",hCryptProv
,"Uint",0
,"Uint",0
,"Uint",PROV_RSA_AES
,"UInt",CRYPT_VERIFYCONTEXT )
Gosub,HashTypeFreeHandles

if !dllCall("Advapi32\CryptCreateHash"
,"Ptr",hCryptProv
,"Uint",HASH_ALG
,"Uint",0
,"Uint",0
,"Ptr*",hHash )
Gosub, HashTypeFreeHandles

VarSetCapacity(read_buf,BUFF_SIZE,0)

hCryptHashData := DllCall("GetProcAddress", "Ptr", hModule, "AStr", "CryptHashData", "Ptr")
While (cbCount := f.RawRead(read_buf, BUFF_SIZE))
{
if (cbCount = 0)
break

if !dllCall(hCryptHashData
,"Ptr",hHash
,"Ptr",&read_buf
,"Uint",cbCount
,"Uint",0 )
Gosub, HashTypeFreeHandles
}

if !dllCall("Advapi32\CryptGetHashParam"
,"Ptr",hHash
,"Uint",HP_HASHSIZE
,"Uint*",HashLen
,"Uint*",HashLenSize := 4
,"UInt",0 )
Gosub, HashTypeFreeHandles

VarSetCapacity(pbHash,HashLen,0)
if !dllCall("Advapi32\CryptGetHashParam"
,"Ptr",hHash
,"Uint",HP_HASHVAL
,"Ptr",&pbHash
,"Uint*",HashLen
,"UInt",0 )
Gosub, HashTypeFreeHandles

SetFormat,integer,Hex
loop,%HashLen%
{
num := numget(pbHash,A_index-1,"UChar")
hashval .= substr((num >> 4),0) . substr((num & 0xf),0)
}
SetFormat,integer,D

HashTypeFreeHandles:
f.Close()
DllCall("FreeLibrary", "Ptr", hModule)
dllCall("Advapi32\CryptDestroyHash","Ptr",hHash)
dllCall("Advapi32\CryptReleaseContext","Ptr",hCryptProv,"UInt",0)
return hashval
}
105 changes: 105 additions & 0 deletions Lib/PoEScripts_UserSettings.ahk
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
#Include CalcChecksum.ahk

PoEScripts_UserSettings(ProjectName, External, FilesToCopy, Dir = "") {
If (!StrLen(Dir)) {
Dir := A_MyDocuments . "\" . ProjectName
}

; External is set if the user settings folder is handled by another script
If (External) {
; copy files after checking if it's neccessary (files do not exist, files were changed in latest update)
; copy .ini files and additionalMacros.txt to A_MyDocuments/ProjectName
PoEScripts_CopyFiles(FilesToCopy, Dir)
}
Else {
If (!InStr(FileExist(Dir), "D")) {
;FileCreateDir, %Dir%
}

; copy files after checking if it's neccessary (files do not exist, files were changed in latest update)
; this handles the external scripts files
;PoEScripts_CopyFiles(FilesToCopy, Dir)
}

}

PoEScripts_CopyFiles(Files, Dir) {
For key, file in Files {
If (FileExist(file)) {
If(PoEScripts_CopyNeeded(file, Dir)) {
FileCopy, %file%, %Dir%
SplitPath, file, name
; hash copied file
targetHash := HashFile(Dir . "\" . name, "SHA")

; write hash to a text file
If (!FileExist(Dir . "\FileHashes.txt")) {
FileAppend, %name%:%targetHash%`n, %Dir%\FileHashes.txt
}
Else {
hashes := {}
; parse file line by line and write names/hashes to array/object
FileRead, fileData, %Dir%\FileHashes.txt
MsgBox % "data: " fileData
Loop, Parse, fileData, `n, `r
{
RegExMatch(A_LoopField, "(.*):(.*)", match)
hashes[Trim(match1)] := Trim(match2)
}

; delete file and write it new with array/object contents
FileDelete, %Dir%\FileHashes.txt
For key, hash in hashes {
MsgBox % key ", " hash
If (key == name) {
hashes[key] := targetHash
}
FileAppend, %key%:%hash%`n, %Dir%\FileHashes.txt
}
}
}
}
}
}

PoEScripts_CopyNeeded(file, targetDir) {
SplitPath, file, name, dir, ext, name_no_ext, drive

If (FileExist(targetDir . "\" . name)) {
MsgBox file exists already in target folder
If (PoEScripts_CompareFileHashes(file, targetDir . "\" . name, targetDir)) {
MsgBox file hashes are different = file was changed
return 1
}
Else {
return 0
}
}
Else {
MsgBox file doesn't exist in target folder
return 1
}
}

PoEScripts_CompareFileHashes(sourceFile, targetFile, targetDir) {
sourceHash := HashFile(sourceFile, "SHA")

hashes := {}
; parse file line by line and write names/hashes to array/object
FileRead, fileData, %targetDir%\FileHashes.txt
Loop, Parse, fileData, `n, `r
{
RegExMatch(A_LoopField, "(.*):(.*)", match)
hashes[Trim(match1)] := Trim(match2)
}

For key, hash in hashes {
If (key == name) {
If (sourceHash != hash) {
return 1
}
}
}

return 0
}
8 changes: 8 additions & 0 deletions TradeUpdates.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
The following is a list of what has been updated, starting with 1.1.0

1.2.12
================================================================================================
Changed default hotkey for "Show item age" to "ctrl + e" because "ctrl + a" is the default for "select all".
Added a seperate low/high mod range modifier instead of a single value for both.
Fixed elemental dps not being displayed on advanced search GUI.
Added error handling for PoE API not being available to parse the current leagues.
Laid some groundwork to implement an auto-updater/"installer" in the future.

1.2.11
================================================================================================
Updated ItemInfo script.
Expand Down
6 changes: 4 additions & 2 deletions trade_config.ini
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ CustomInputSearchHotkey =^i
; Defaults to ctrl + i if not set.
OpenSearchOnPoeTradeHotKey =^q
; Defaults to ctrl + q if not set
ShowItemAgeHotKey =^a
ShowItemAgeHotKey =^e
; Defaults to ctrl + e if not set

[HotkeyStates]
PriceCheckEnabled =1
Expand Down Expand Up @@ -59,7 +60,8 @@ BuyoutOnly =1
Corrupted =Either
; yes, no, either; This setting gets ignored when you use the search on corrupted items.
CorruptedOverride =0
AdvancedSearchModValueRange =20
AdvancedSearchModValueRangeMin =20
AdvancedSearchModValueRangeMax =20
; Advanced search lets you select the items mods to include in your search and lets you set ther min/max values .
; These min/max values are pre-filled, to calculate them we look at the difference between the mods theoretical max and min value and treat it as 100%.
; We then use AdvancedSearchModValueRange as a percentage of this differences to create a range (min/max value) to search.
Expand Down
55 changes: 35 additions & 20 deletions trade_data/TradeMacro.ahk
Original file line number Diff line number Diff line change
Expand Up @@ -907,18 +907,31 @@ TradeFunc_ParseItemOffenseStats(Stats, mods){
iStats.EleDps := {}
iStats.EleDps.Name := "Elemental Dps"
iStats.EleDps.Value := Stats.EleDps
iStats.EleDps.Min := ((min_affixFlatFireLow + min_affixFlatFireHi + min_affixFlatColdLow + min_affixFlatColdHi + min_affixFlatLightningLow + min_affixFlatLightningHi) / 2) * minAPS
iStats.EleDps.Max := ((max_affixFlatFireLow + max_affixFlatFireHi + max_affixFlatColdLow + max_affixFlatColdHi + max_affixFlatLightningLow + max_affixFlatLightningHi) / 2) * maxAPS
iStats.EleDps.Min := TradeFunc_CalculateEleDps(min_affixFlatFireLow, min_affixFlatFireHi, min_affixFlatColdLow, min_affixFlatColdHi, min_affixFlatLightningLow, min_affixFlatLightningHi, minAPS)
iStats.EleDps.Max := TradeFunc_CalculateEleDps(max_affixFlatFireLow, max_affixFlatFireHi, max_affixFlatColdLow, max_affixFlatColdHi, max_affixFlatLightningLow, max_affixFlatLightningHi, maxAPS)

debugOutput .= "Phys DPS: " iStats.PhysDps.Value "`n" "Phys Min: " iStats.PhysDps.Min "`n" "Phys Max: " iStats.PhysDps.Max "`n" "EleDps: " iStats.EleDps.Value "`n" "Ele Min: " iStats.EleDps.Min "`n" "Ele Max: " iStats.EleDps.Max

If (TradeOpts.Debug) {
;console.log(debugOutput)
}

Return iStats
}

TradeFunc_CalculateEleDps(fireLo, fireHi, coldLo, coldHi, lightLo, lightHi, aps) {
dps := 0
fireLo := fireLo > 0 ? fireLo : 0
fireHi := fireHi > 0 ? fireHi : 0
coldLo := coldLo > 0 ? coldLo : 0
coldHi := coldHi > 0 ? coldHi : 0
lightLo := lightLo > 0 ? lightLo : 0
lightHi := lightHi > 0 ? lightHi : 0

dps := ((fireLo + fireHi + coldLo + coldHi + lightLo + lightHi) / 2) * aps

return dps
}

TradeFunc_GetUniqueStats(name){
items := TradeGlobals.Get("VariableUniqueData")
For i, uitem in items {
Expand Down Expand Up @@ -2494,14 +2507,16 @@ TradeFunc_AdvancedPriceCheckGui(advItem, Stats, Sockets, Links, UniqueStats = ""
}

TradeFunc_ResetGUI()
ValueRange := advItem.IsUnique ? TradeOpts.AdvancedSearchModValueRange : TradeOpts.AdvancedSearchModValueRange / 2
ValueRangeMin := advItem.IsUnique ? TradeOpts.AdvancedSearchModValueRangeMin : TradeOpts.AdvancedSearchModValueRangeMin / 2
ValueRangeMax := advItem.IsUnique ? TradeOpts.AdvancedSearchModValueRangeMax : TradeOpts.AdvancedSearchModValueRangeMax / 2

Gui, SelectModsGui:Destroy
Gui, SelectModsGui:Add, Text, x10 y12, Percentage to pre-calculate min/max values:
Gui, SelectModsGui:Add, Text, x+5 yp+0 cGreen, % ValueRange "`%" (lowered for non-unique items)
Gui, SelectModsGui:Add, Text, x+5 yp+0 cGreen, % ValueRangeMin "`% / " ValueRangeMax "`%" (lowered for non-unique items)
Gui, SelectModsGui:Add, Text, x10 y+8, This calculation considers the (unique) item's mods difference between their min and max value as 100`%.

ValueRange := ValueRange / 100
ValueRangeMin := ValueRangeMin / 100
ValueRangeMax := ValueRangeMax / 100

; calculate length of first column
modLengthMax := 0
Expand Down Expand Up @@ -2566,12 +2581,12 @@ TradeFunc_AdvancedPriceCheckGui(advItem, Stats, Sockets, Links, UniqueStats = ""
; calculate values to prefill min/max fields
; assume the difference between the theoretical max and min value as 100%
If (advItem.IsUnique) {
statValueMin := Round(statValueQ20 - ((stat.max - stat.min) * valueRange))
statValueMax := Round(statValueQ20 + ((stat.max - stat.min) * valueRange))
statValueMin := Round(statValueQ20 - ((stat.max - stat.min) * valueRangeMin))
statValueMax := Round(statValueQ20 + ((stat.max - stat.min) * valueRangeMax))
}
Else {
statValueMin := Round(statValueQ20 - (statValueQ20 * valueRange))
statValueMax := Round(statValueQ20 + (statValueQ20 * valueRange))
statValueMin := Round(statValueQ20 - (statValueQ20 * valueRangeMin))
statValueMax := Round(statValueQ20 + (statValueQ20 * valueRangeMax))
}

; prevent calculated values being smaller than the lowest possible min value or being higher than the highest max values
Expand Down Expand Up @@ -2608,7 +2623,7 @@ TradeFunc_AdvancedPriceCheckGui(advItem, Stats, Sockets, Links, UniqueStats = ""
If (j > 1) {
Gui, SelectModsGui:Add, Text, x0 w700 yp+18 cc9cacd, %line%
}

k := 1
;add dmg stats
For i, stat in Stats.Offense {
Expand All @@ -2623,12 +2638,12 @@ TradeFunc_AdvancedPriceCheckGui(advItem, Stats, Sockets, Links, UniqueStats = ""
; calculate values to prefill min/max fields
; assume the difference between the theoretical max and min value as 100%
If (advItem.IsUnique) {
statValueMin := Round(stat.value - ((stat.max - stat.min) * valueRange))
statValueMax := Round(stat.value + ((stat.max - stat.min) * valueRange))
statValueMin := Round(stat.value - ((stat.max - stat.min) * valueRangeMin))
statValueMax := Round(stat.value + ((stat.max - stat.min) * valueRangeMax))
}
Else {
statValueMin := Round(stat.value - (stat.value * valueRange))
statValueMax := Round(stat.value + (stat.value * valueRange))
statValueMin := Round(stat.value - (stat.value * valueRangeMin))
statValueMax := Round(stat.value + (stat.value * valueRangeMax))
}

; prevent calculated values being smaller than the lowest possible min value or being higher than the highest max values
Expand Down Expand Up @@ -2752,12 +2767,12 @@ TradeFunc_AdvancedPriceCheckGui(advItem, Stats, Sockets, Links, UniqueStats = ""
; calculate values to prefill min/max fields
; assume the difference between the theoretical max and min value as 100%
If (advItem.mods[A_Index].ranges[1]) {
modValueMin := modValue - ((theoreticalMaxValue - theoreticalMinValue) * valueRange)
modValueMax := modValue + ((theoreticalMaxValue - theoreticalMinValue) * valueRange)
modValueMin := modValue - ((theoreticalMaxValue - theoreticalMinValue) * valueRangeMin)
modValueMax := modValue + ((theoreticalMaxValue - theoreticalMinValue) * valueRangeMax)
}
Else {
modValueMin := modValue - (modValue * valueRange)
modValueMax := modValue + (modValue * valueRange)
modValueMin := modValue - (modValue * valueRangeMin)
modValueMax := modValue + (modValue * valueRangeMax)
}
; floor values only If greater than 2, in case of leech/regen mods
modValueMin := (modValueMin > 2) ? Floor(modValueMin) : modValueMin
Expand Down Expand Up @@ -2872,7 +2887,7 @@ TradeFunc_AdvancedPriceCheckGui(advItem, Stats, Sockets, Links, UniqueStats = ""
Gui, SelectModsGui:Add, Link, x+5 yp+0 cBlue, <a href="https://poe.trade">visit</a>

windowWidth := modGroupBox + 40 + 5 + 45 + 10 + 45 + 10 +40 + 5 + 45 + 10 + 65
windowWidth := (windowWidth > 420) ? windowWidth : 420
windowWidth := (windowWidth > 450) ? windowWidth : 450
Gui, SelectModsGui:Show, w%windowWidth% , Select Mods to include in Search
}

Expand Down
Loading

0 comments on commit 83d11be

Please sign in to comment.