Advertisement
NJ5SkwAg

CH Save Decoder and JSON Interpreter for AHK

Aug 29th, 2015
601
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #NoEnv  ; Recommended for performance and compatibility with future AutoHotkey releases.
  2. ; #Warn  ; Enable warnings to assist with detecting common errors.
  3. SendMode Input  ; Recommended for new scripts due to its superior speed and reliability.
  4. SetWorkingDir %A_ScriptDir%  ; Ensures a consistent starting directory.
  5.  
  6. EncodedSaveState := Clipboard
  7.  
  8. StringCaseSense On
  9. Chars = ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/
  10. Seperator_String := "Fe12NAfA3R6z4k0z"
  11. StringLeft, EncodedSaveState_LessSplitAndHash, EncodedSaveState, InStr(EncodedSaveState, Seperator_String)
  12. StringSplit, temp, EncodedSaveState_LessSplitAndHash
  13. Length := StrLen(EncodedSaveState_LessSplitAndHash) - 1
  14. loop % Length
  15. {
  16.     if (mod(A_Index, 2) = 0)
  17.         continue
  18.     tempstr := tempstr . temp%A_Index%
  19. }
  20. DecodedString := InvBase64(tempstr)
  21. ; FileAppend, %DecodedString%, DecodedSaveState.txt
  22.  
  23. titanDamage := json(DecodedString, "titanDamage")
  24. rubies := json(DecodedString, "rubies")
  25. FormatTime, timeVar, A_Now, ddd, h:mmt
  26. FileAppend, % timeVar . "`t" . A_TickCount . "`t" . titanDamage . "`t" . rubies . "`n", titanDamage.txt
  27.  
  28.  
  29. Solomon_Level := json(DecodedString, "ancients.ancients.3.level")
  30.  
  31. Solomon_Level_plus5 := Solomon_Level + 5
  32. if (Solomon_Level <= 20)
  33.     Solomon_Modifier := 1 + Solomon_Level * 5 / 100
  34. else if (Solomon_Level <= 40)
  35.     Solomon_Modifier := 1 + (100 + (Solomon_Level - 20) * 4) / 100
  36. else if (Solomon_Level <= 60)
  37.     Solomon_Modifier := 1 + (180 + (Solomon_Level - 40) * 3) / 100
  38. else if (Solomon_Level <= 80)
  39.     Solomon_Modifier := 1 + (240 + (Solomon_Level - 60) * 2) / 100
  40. else
  41.     Solomon_Modifier := 1 + (200 + Solomon_Level) / 100
  42. if (Solomon_Level_plus5 <= 20)
  43.     Solomon_Modifier_plus5 := 1 + Solomon_Level_plus5 * 5 / 100
  44. else if (Solomon_Level_plus5 <= 40)
  45.     Solomon_Modifier_plus5 := 1 + (100 + (Solomon_Level_plus5 - 20) * 4) / 100
  46. else if (Solomon_Level_plus5 <= 60)
  47.     Solomon_Modifier_plus5 := 1 + (180 + (Solomon_Level_plus5 - 40) * 3) / 100
  48. else if (Solomon_Level_plus5 <= 80)
  49.     Solomon_Modifier_plus5 := 1 + (240 + (Solomon_Level_plus5 - 60) * 2) / 100
  50. else
  51.     Solomon_Modifier_plus5 := 1 + (200 + Solomon_Level_plus5) / 100
  52.  
  53. ; Value list in terms of increase in HS/hr per point
  54. bonusType1Value := 0 ; Siyalatas, Ancient of Abandonment +X% DPS when idle (no clicks for 60 seconds)
  55. bonusType2Value := 0 ; Fragsworth, Ancient of Wrath +X% Click Damage
  56. bonusType3Value := 0 ; Chronos, Ancient of Time +X seconds to Boss Fight timers
  57. bonusType4Value := 0 ; Chawedo, Ancient of Agitation +X seconds to duration of Clickstorm
  58. bonusType5Value := 0.8 ; Revolc, Ancient of Luck +X% Chance of double rubies from clickable treasures, when you get a ruby.
  59. bonusType6Value := 0 ; Iris, Ancient of Vision +X to starting zone after Ascension
  60. bonusType7Value := 0 ; Argaiv, Ancient of Enhancement +X% to Gilded damage bonus (per Gild)
  61. bonusType8Value := 0 ; Energon, Ancient of Battery Life +X seconds to duration of Metal Detector
  62. bonusType9Value := 0.0006 ; Kleptos, Ancient of Thieves +X seconds to duration of Golden Clicks
  63. bonusType10Value := 0.0006 ; Sniperino, Ancient of Accuracy +X seconds to duration of Lucky Strikes
  64. bonusType11Value := 0 ; Berserker, Ancient of Rage +X seconds to duration of Powersurge
  65. bonusType12Value := 0 ; Hecatoncheir, Ancient of Wallops +X seconds to duration of Super Clicks
  66. bonusType13Value := 0.015625 ; Bubos, Ancient of Diseases -X% Boss Life
  67. bonusType14Value := 0 ; Morgulis, Ancient of Death +X% to Hero Soul DPS (additive)
  68. bonusType15Value := 0 ; Bhaal, Ancient of Murder +X% damage to Critical Clicks
  69. bonusType16Value := 0.015625 ; (PER10) Dora, Ancient of Discovery +X% more Treasure Chests
  70. bonusType17Value := 1.9 ; Atman, Ancient of Souls +X% Chance of Primal Bosses
  71. bonusType18Value := 0.034375 ; Fortuna, Ancient of Chance +X% Chance of 10x Gold
  72. bonusType19Value := 0.121875 ; Dogcog, Ancient of Thrift -X% Hero Hiring and Level-Up cost
  73. bonusType20Value := 0 ; Pluto, Ancient of Wealth +X% Gold from Golden Clicks
  74. bonusType21Value := 0 ; Mimzee, Ancient of Riches +X% Gold From Treasure Chests
  75. bonusType22Value := 0 ; Mammon, Ancient of Greed +X% Gold Dropped
  76. bonusType24Value := 0 ; Libertas, Ancient of Freedom +X% Gold gained from monsters when idle
  77. bonusType25Value := ((Solomon_Modifier_plus5 / Solomon_Modifier) - 1) * 100 ; (PER5)Solomon, Ancient of Wisdom +X% Primal Hero Souls
  78.  
  79. /*
  80. relic<1-5> = relic's id
  81. relic<1-5>bonus<1-4>Type = 0-25 (0 doesn't exist)
  82. relic<1-5>bonus<1-4>Level = 0-50 (0 doesn't exist)
  83. relic<1-5>Value = relic<1-5>bonus<1-4>Level * bonusType<1-25>Value
  84. */
  85.  
  86. filename := "relicSummary.txt"
  87. FileDelete, %filename%
  88. loop 5
  89. {
  90.     rID := A_Index
  91.     relic%rID% := json(DecodedString, "items.slots." . rID) ; the relic's ID
  92.     FileAppend, % "relic" . rID . "'s JSON ID:  " . relic%rID% . "`n", %filename%
  93.     relic%rID%Value := 0
  94.     loop 4
  95.     {
  96.         bNum := A_index ; which bonus
  97.         Relic%rID%bonus%bNum%Type := json(DecodedString, "items.items." . relic%rID% . ".bonusType" . bNum)
  98.         FileAppend, % "relic" . rID . "bonus" . bNum . "Type:`  " . relic%rID%bonus%bNum%Type . "`n", %filename%
  99.         Relic%rID%bonus%bNum%Level := json(DecodedString, "items.items." . relic%rID% . ".bonus" . bNum . "Level")
  100.         FileAppend, % "relic" . rID . "bonus" . bNum . "Level: " . relic%rID%bonus%bNum%Level . "`n", %filename%
  101.         tType := relic%rID%bonus%bNum%Type
  102.         relic%rID%Value += relic%rID%bonus%bNum%Level * bonusType%tType%Value
  103.     }
  104.     FileAppend, % "relic" . rID . "Value: " . relic%rID%Value . "`n`n", %filename%
  105. }
  106. Return_Value := 0 ; 1-4 means swap 5 with 1-4, 0 means no swaps necessary
  107. loop 4
  108. {
  109.     if (relic%A_Index%Value < relic5Value)
  110.     {
  111.         if Return_Value ; checks which is lowest if there are multiple that are worse then relic5
  112.         {
  113.             if (relic%A_Index%Value < relic%Return_Value%Value)
  114.                 Return_Value := A_Index
  115.         }
  116.         else
  117.             Return_Value := A_Index
  118.     }
  119. }
  120. if (not Return_Value = 0)
  121.     FileAppend, % "relic" . RelicNum . " swapped!`n", ClickerHeroesLog.txt
  122. ; I use a message system, a function return would work just as easily
  123. SetTitleMatchMode, 2
  124. DetectHiddenWindows, on
  125. SendMessage, 0x9200, Return_Value,,, ClickerHeroes.ahk - AutoHotkey v
  126. return
  127.  
  128.  
  129. ; http://www.autohotkey.com/board/topic/5545-base64-coderdecoder/
  130. InvBase64(code)
  131. {
  132.    StringReplace code, code, =,,All
  133.    Loop Parse, code
  134.    {
  135.       If Mod(A_Index,4) = 1
  136.          buffer := DeCode(A_LoopField) << 18
  137.       Else If Mod(A_Index,4) = 2
  138.          buffer += DeCode(A_LoopField) << 12
  139.       Else If Mod(A_Index,4) = 3
  140.          buffer += DeCode(A_LoopField) << 6
  141.       Else {
  142.          buffer += DeCode(A_LoopField)
  143.          out := out . Chr(buffer>>16) . Chr(255 & buffer>>8) . Chr(255 & buffer)
  144.       }
  145.    }
  146.    If Mod(StrLen(code),4) = 0
  147.       Return out
  148.    If Mod(StrLen(code),4) = 2
  149.       Return out . Chr(buffer>>16)
  150.    Return out . Chr(buffer>>16) . Chr(255 & buffer>>8)
  151. }
  152.  
  153. Code(i)     ; <== Chars[i & 63], 0-base index
  154. {
  155.    Global Chars
  156.    StringMid i, Chars, (i&63)+1, 1
  157.    Return i
  158. }
  159.  
  160. DeCode(c)   ; c = a char in Chars ==> position [0,63]
  161. {
  162.    Global Chars
  163.    Return InStr(Chars,c,1) - 1
  164. }
  165.  
  166. ; http://www.autohotkey.com/board/topic/31619-json-readwrite-parser/
  167. ; https://github.com/polyethene/AutoHotkey-Scripts/blob/master/json.ahk
  168. json(ByRef js, s, v = "") {
  169.     j = %js%
  170.     Loop, Parse, s, .
  171.     {
  172.         p = 2
  173.         RegExMatch(A_LoopField, "([+\-]?)([^[]+)((?:\[\d+\])*)", q)
  174.         Loop {
  175.             If (!p := RegExMatch(j, "(?<!\\)(""|')([^\1]+?)(?<!\\)(?-1)\s*:\s*((\{(?:[^{}]++|(?-1))*\})|(\[(?:[^[\]]++|(?-1))*\])|"
  176.                 . "(?<!\\)(""|')[^\7]*?(?<!\\)(?-1)|[+\-]?\d+(?:\.\d*)?|true|false|null?)\s*(?:,|$|\})", x, p))
  177.                 Return
  178.             Else If (x2 == q2 or q2 == "*") {
  179.                 j = %x3%
  180.                 z += p + StrLen(x2) - 2
  181.                 If (q3 != "" and InStr(j, "[") == 1) {
  182.                     StringTrimRight, q3, q3, 1
  183.                     Loop, Parse, q3, ], [
  184.                     {
  185.                         z += 1 + RegExMatch(SubStr(j, 2, -1), "^(?:\s*((\[(?:[^[\]]++|(?-1))*\])|(\{(?:[^{\}]++|(?-1))*\})|[^,]*?)\s*(?:,|$)){" . SubStr(A_LoopField, 1) + 1 . "}", x)
  186.                         j = %x1%
  187.                     }
  188.                 }
  189.                 Break
  190.             }
  191.             Else p += StrLen(x)
  192.         }
  193.     }
  194.     If v !=
  195.     {
  196.         vs = " ;" just to fix my text editor coloring
  197.         If (RegExMatch(v, "^\s*(?:""|')*\s*([+\-]?\d+(?:\.\d*)?|true|false|null?)\s*(?:""|')*\s*$", vx)
  198.             and (vx1 + 0 or vx1 == 0 or vx1 == "true" or vx1 == "false" or vx1 == "null" or vx1 == "nul"))
  199.             vs := "", v := vx1
  200.         StringReplace, v, v, ", \", All
  201.         js := SubStr(js, 1, z := RegExMatch(js, ":\s*", zx, z) + StrLen(zx) - 1) . vs . v . vs . SubStr(js, z + StrLen(x3) + 1)
  202.     }
  203.     Return, j == "false" ? 0 : j == "true" ? 1 : j == "null" or j == "nul"
  204.         ? "" : SubStr(j, 1, 1) == """" ? SubStr(j, 2, -1) : j
  205. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement