-
Notifications
You must be signed in to change notification settings - Fork 31
/
Copy pathD2Stats.au3
2104 lines (1673 loc) · 72 KB
/
D2Stats.au3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#RequireAdmin
#include <Array.au3>
#include <File.au3>
#include <GuiEdit.au3>
#include <GuiSlider.au3>
#include <HotKey.au3>
#include <HotKeyInput.au3>
#include <Misc.au3>
#include <NomadMemory.au3>
#include <WinAPI.au3>
#include <AutoItConstants.au3>
#include <ComboConstants.au3>
#include <FileConstants.au3>
#include <GUIConstantsEx.au3>
#include <MemoryConstants.au3>
#include <MsgBoxConstants.au3>
#include <StringConstants.au3>
#include <StaticConstants.au3>
#include <TabConstants.au3>
#include <WindowsConstants.au3>
#pragma compile(Icon, Assets/icon.ico)
#pragma compile(FileDescription, Diablo II Stats reader)
#pragma compile(ProductName, D2Stats)
#pragma compile(ProductVersion, 3.11.5)
#pragma compile(FileVersion, 3.11.5)
#pragma compile(Comments, 20.04.2022)
#pragma compile(UPX, True) ;compression
#pragma compile(inputboxres, True)
;#pragma compile(ExecLevel, requireAdministrator)
;#pragma compile(Compatibility, win7)
;#pragma compile(x64, True)
;#pragma compile(Out, D2Stats.exe)
;#pragma compile(LegalCopyright, Legal stuff here)
;#pragma compile(LegalTrademarks, '"Trademark something, and some text in "quotes" and stuff')
if ($CmdLine[0] == 3 and $CmdLine[1] == "sound") then ; Notifier sounds
SoundSetWaveVolume($CmdLine[3])
SoundPlay(StringFormat("%s\Sounds\%s.mp3", @ScriptDir, $CmdLine[2]), $SOUND_WAIT)
SoundPlay("")
exit
elseif (not _Singleton("D2Stats-Singleton")) then
exit
elseif (@AutoItExe == @DesktopDir or @AutoItExe == @DesktopCommonDir) then
MsgBox($MB_ICONERROR, "D2Stats", "Don't place D2Stats.exe on the desktop.")
exit
elseif (not IsAdmin()) then
MsgBox($MB_ICONERROR, "D2Stats", "Admin rights needed!")
exit
elseif (not @Compiled) then
HotKeySet("+{INS}", "HotKey_CopyStatsToClipboard")
HotKeySet("+{PgUp}", "HotKey_CopyItemsToClipboard")
endif
Opt("MustDeclareVars", 1)
Opt("GUICloseOnESC", 0)
Opt("GUIOnEventMode", 1)
DefineGlobals()
OnAutoItExitRegister("_Exit")
CreateGUI()
Main()
#Region Main
func Main()
_HotKey_Disable($HK_FLAG_D2STATS)
local $hTimerUpdateDelay = TimerInit()
local $bIsIngame, $bShowItems
while 1
Sleep(20)
if (TimerDiff($hTimerUpdateDelay) > 250) then
$hTimerUpdateDelay = TimerInit()
UpdateHandle()
UpdateGUIOptions()
if (IsIngame()) then
if (not $bIsIngame) then $g_bNotifyCache = True
InjectFunctions()
if (_GUI_Option("mousefix") <> IsMouseFixEnabled()) then ToggleMouseFix()
if (IsShowItemsEnabled()) then
if (_GUI_Option("toggleMsg")) then
if (_MemoryRead($g_hD2Client + 0xFADB4, $g_ahD2Handle) == 0) then
if ($bShowItems) then PrintString("Not showing items.", $ePrintBlue)
$bShowItems = False
else
$bShowItems = True
endif
endif
if (not _GUI_Option("toggle")) then ToggleShowItems()
else
$bShowItems = False
endif
if (_GUI_Option("nopickup") and not $bIsIngame) then _MemoryWrite($g_hD2Client + 0x11C2F0, $g_ahD2Handle, 1, "byte")
if (_GUI_Option("notify-enabled")) then NotifierMain()
$bIsIngame = True
else
$bIsIngame = False
$g_hTimerCopyName = 0
endif
if ($g_hTimerCopyName and TimerDiff($g_hTimerCopyName) > 10000) then
$g_hTimerCopyName = 0
if ($bIsIngame) then PrintString("Item name multi-copy expired.")
endif
endif
wend
endfunc
func _Exit()
if (IsDeclared("g_idNotifySave") and BitAND(GUICtrlGetState($g_idNotifySave), $GUI_ENABLE)) then
local $iButton = MsgBox(BitOR($MB_ICONQUESTION, $MB_YESNO), "D2Stats", "There are unsaved changes in the notifier rules. Save?", 0, $g_hGUI)
if ($iButton == $IDYES) then OnClick_NotifySave()
endif
OnAutoItExitUnRegister("_Exit")
_GUICtrlHKI_Release()
GUIDelete()
_CloseHandle()
_LogSave()
exit
endfunc
func _CloseHandle()
if ($g_ahD2Handle) then
_MemoryClose($g_ahD2Handle)
$g_ahD2Handle = 0
$g_iD2pid = 0
endif
endfunc
func UpdateHandle()
local $hWnd = WinGetHandle("[CLASS:Diablo II]")
local $iPID = WinGetProcess($hWnd)
if ($iPID == -1) then return _CloseHandle()
if ($iPID == $g_iD2pid) then return
_CloseHandle()
$g_iUpdateFailCounter += 1
$g_ahD2Handle = _MemoryOpen($iPID)
if (@error) then return _Debug("UpdateHandle", "Couldn't open Diablo II memory handle.")
if (not UpdateDllHandles()) then
_CloseHandle()
return _Debug("UpdateHandle", "Couldn't update dll handles.")
endif
if (not InjectFunctions()) then
_CloseHandle()
return _Debug("UpdateHandle", "Couldn't inject functions.")
endif
$g_iUpdateFailCounter = 0
$g_iD2pid = $iPID
$g_pD2sgpt = _MemoryRead($g_hD2Common + 0x99E1C, $g_ahD2Handle)
endfunc
func IsIngame()
if (not $g_iD2pid) then return False
return _MemoryRead($g_hD2Client + 0x11BBFC, $g_ahD2Handle) <> 0
endfunc
func _Debug($sFuncName, $sMessage, $iError = @error, $iExtended = @extended)
_Log($sFuncName, $sMessage, $iError, $iExtended)
PrintString($sMessage, $ePrintRed)
endfunc
func _Log($sFuncName, $sMessage, $iError = @error, $iExtended = @extended)
$g_sLog &= StringFormat("[%s] %s (error: %s; extended: %s)%s", $sFuncName, $sMessage, $iError, $iExtended, @CRLF)
if ($g_iUpdateFailCounter >= 10) then
MsgBox($MB_ICONERROR, "D2Stats", "Failed too many times in a row. Check log for details. Closing D2Stats...", 0, $g_hGUI)
exit
endif
endfunc
func _LogSave()
if ($g_sLog <> "") then
local $hFile = FileOpen("D2Stats-log.txt", $FO_OVERWRITE)
FileWrite($hFile, $g_sLog)
FileFlush($hFile)
FileClose($hFile)
endif
endfunc
#EndRegion
#Region Hotkeys
func HotKey_CopyStatsToClipboard()
if (not IsIngame()) then return
UpdateStatValues()
local $sOutput = ""
for $i = 0 to $g_iNumStats - 1
local $iVal = GetStatValue($i)
if ($iVal) then
$sOutput &= StringFormat("%s = %s%s", $i, $iVal, @CRLF)
endif
next
ClipPut($sOutput)
PrintString("Stats copied to clipboard.")
endfunc
func HotKey_CopyItemsToClipboard()
if (not IsIngame()) then return
local $iItemsTxt = _MemoryRead($g_hD2Common + 0x9FB94, $g_ahD2Handle)
local $pItemsTxt = _MemoryRead($g_hD2Common + 0x9FB98, $g_ahD2Handle)
local $pBaseAddr, $iNameID, $sName, $iMisc
local $sOutput = ""
for $iClass = 0 to $iItemsTxt - 1
$pBaseAddr = $pItemsTxt + 0x1A8 * $iClass
$iMisc = _MemoryRead($pBaseAddr + 0x84, $g_ahD2Handle, "dword")
$iNameID = _MemoryRead($pBaseAddr + 0xF4, $g_ahD2Handle, "word")
$sName = RemoteThread($g_pD2InjectGetString, $iNameID)
$sName = _MemoryRead($sName, $g_ahD2Handle, "wchar[100]")
$sName = StringReplace($sName, @LF, "|")
$sOutput &= StringFormat("[class:%04i] [misc:%s] <%s>%s", $iClass, $iMisc ? 0 : 1, $sName, @CRLF)
next
ClipPut($sOutput)
PrintString("Items copied to clipboard.")
endfunc
func HotKey_CopyItem($TEST = False)
if ($TEST or not IsIngame()) then return
local $hTimerRetry = TimerInit()
local $sOutput = ""
local $aiOffsets[2] = [0, 0]
while ($sOutput == "" and TimerDiff($hTimerRetry) < 10)
$sOutput = _MemoryPointerRead($g_hD2Win + 0x1191F, $g_ahD2Handle, $aiOffsets, "wchar[8192]")
; $sOutput = _MemoryRead(0x00191FA4, $g_ahD2Handle, "wchar[2048]") ; Magic?
wend
if (StringLen($sOutput) == 0) then
PrintString("Hover the cursor over an item first.", $ePrintRed)
return
endif
$sOutput = StringRegExpReplace($sOutput, "ÿc.", "")
local $asLines = StringSplit($sOutput, @LF)
if (_GUI_Option("copy-name")) then
if ($g_hTimerCopyName == 0 or not (ClipGet() == $g_sCopyName)) then $g_sCopyName = ""
$g_hTimerCopyName = TimerInit()
$g_sCopyName &= $asLines[$asLines[0]] & @CRLF
ClipPut($g_sCopyName)
local $avItems = StringRegExp($g_sCopyName, @CRLF, $STR_REGEXPARRAYGLOBALMATCH)
PrintString(StringFormat("%s item name(s) copied.", UBound($avItems)))
return
endif
$sOutput = ""
for $i = $asLines[0] to 1 step -1
if ($asLines[$i] <> "") then $sOutput &= $asLines[$i] & @CRLF
next
ClipPut($sOutput)
PrintString("Item text copied.")
endfunc
func HotKey_DropFilter($TEST = False)
if ($TEST or not IsIngame()) then return
local $hDropFilter = GetDropFilterHandle()
if ($hDropFilter) then
if (EjectDropFilter($hDropFilter)) then
PrintString("Ejected DropFilter.", $ePrintGreen)
_Log("HotKey_DropFilter", "Ejected DropFilter.")
else
_Debug("HotKey_DropFilter", "Failed to eject DropFilter.")
endif
else
if (InjectDropFilter()) then
PrintString("Injected DropFilter.", $ePrintGreen)
_Log("HotKey_DropFilter", "Injected DropFilter.")
else
_Debug("HotKey_DropFilter", "Failed to inject DropFilter.")
endif
endif
endfunc
func HotKey_ToggleShowItems($TEST = False)
if ($TEST or not IsIngame()) then return
ToggleShowItems()
endfunc
func HotKey_ReadStats()
OnClick_ReadStats()
endfunc
#EndRegion
#Region Stat reading
func GetUnitToRead()
local $bMercenary = BitAND(GUICtrlRead($g_idReadMercenary), $GUI_CHECKED) ? True : False
return $g_hD2Client + ($bMercenary ? 0x10A80C : 0x11BBFC)
endfunc
func UpdateStatValueMem($iVector)
if ($iVector <> 0 and $iVector <> 1) then _Debug("UpdateStatValueMem", "Invalid $iVector value.")
local $pUnitAddress = GetUnitToRead()
local $aiOffsets[3] = [0, 0x5C, ($iVector+1)*0x24]
local $pStatList = _MemoryPointerRead($pUnitAddress, $g_ahD2Handle, $aiOffsets)
$aiOffsets[2] += 0x4
local $iStatCount = _MemoryPointerRead($pUnitAddress, $g_ahD2Handle, $aiOffsets, "word") - 1
local $tagStat = "word wSubIndex;word wStatIndex;int dwStatValue;", $tagStatsAll
for $i = 0 to $iStatCount
$tagStatsAll &= $tagStat
next
local $tStats = DllStructCreate($tagStatsAll)
_WinAPI_ReadProcessMemory($g_ahD2Handle[1], $pStatList, DllStructGetPtr($tStats), DllStructGetSize($tStats), 0)
local $iStatIndex, $iStatValue
for $i = 0 to $iStatCount
$iStatIndex = DllStructGetData($tStats, 2 + (3 * $i))
if ($iStatIndex >= $g_iNumStats) then
continueloop ; Should never happen
endif
$iStatValue = DllStructGetData($tStats, 3 + (3 * $i))
switch $iStatIndex
case 6 to 11
$g_aiStatsCache[$iVector][$iStatIndex] += $iStatValue / 256
case else
$g_aiStatsCache[$iVector][$iStatIndex] += $iStatValue
endswitch
next
endfunc
func UpdateStatValues()
for $i = 0 to $g_iNumStats - 1
$g_aiStatsCache[0][$i] = 0
$g_aiStatsCache[1][$i] = 0
next
if (IsIngame()) then
UpdateStatValueMem(0)
UpdateStatValueMem(1)
FixStats()
FixVeteranToken()
CalculateWeaponDamage()
; Poison damage to damage/second
$g_aiStatsCache[1][57] *= (25/256)
$g_aiStatsCache[1][58] *= (25/256)
; Bonus stats from items; str, dex, vit, ene
local $aiStats[] = [0, 359, 2, 360, 3, 362, 1, 361]
local $iBase, $iTotal, $iPercent
for $i = 0 to 3
$iBase = GetStatValue($aiStats[$i*2 + 0])
$iTotal = GetStatValue($aiStats[$i*2 + 0], 1)
$iPercent = GetStatValue($aiStats[$i*2 + 1])
$g_aiStatsCache[1][900+$i] = Ceiling($iTotal / (1 + $iPercent / 100) - $iBase)
next
; Factor cap
local $iFactor = Floor((GetStatValue(278) * GetStatValue(0, 1) + GetStatValue(485) * GetStatValue(1, 1)) / 3e6 * 100)
$g_aiStatsCache[1][904] = $iFactor > 100 ? 100 : $iFactor
endif
endfunc
func GetUnitWeapon($pUnit)
local $pInventory = _MemoryRead($pUnit + 0x60, $g_ahD2Handle)
local $pItem = _MemoryRead($pInventory + 0x0C, $g_ahD2Handle)
local $iWeaponID = _MemoryRead($pInventory + 0x1C, $g_ahD2Handle)
local $pItemData, $pWeapon = 0
while $pItem
if ($iWeaponID == _MemoryRead($pItem + 0x0C, $g_ahD2Handle)) then
$pWeapon = $pItem
exitloop
endif
$pItemData = _MemoryRead($pItem + 0x14, $g_ahD2Handle)
$pItem = _MemoryRead($pItemData + 0x64, $g_ahD2Handle)
wend
return $pWeapon
endfunc
func CalculateWeaponDamage()
local $pUnitAddress = GetUnitToRead()
local $pUnit = _MemoryRead($pUnitAddress, $g_ahD2Handle)
local $pWeapon = GetUnitWeapon($pUnit)
if (not $pWeapon) then return
local $iWeaponClass = _MemoryRead($pWeapon + 0x04, $g_ahD2Handle)
local $pItemsTxt = _MemoryRead($g_hD2Common + 0x9FB98, $g_ahD2Handle)
local $pBaseAddr = $pItemsTxt + 0x1A8 * $iWeaponClass
local $iStrBonus = _MemoryRead($pBaseAddr + 0x106, $g_ahD2Handle, "word")
local $iDexBonus = _MemoryRead($pBaseAddr + 0x108, $g_ahD2Handle, "word")
local $bIs2H = _MemoryRead($pBaseAddr + 0x11C, $g_ahD2Handle, "byte")
local $bIs1H = $bIs2H ? _MemoryRead($pBaseAddr + 0x13D, $g_ahD2Handle, "byte") : 1
local $iMinDamage1 = 0, $iMinDamage2 = 0, $iMaxDamage1 = 0, $iMaxDamage2 = 0
if ($bIs2H) then
; 2h weapon
$iMinDamage2 = GetStatValue(23)
$iMaxDamage2 = GetStatValue(24)
endif
if ($bIs1H) then
; 1h weapon
$iMinDamage1 = GetStatValue(21)
$iMaxDamage1 = GetStatValue(22)
if (not $bIs2H) then
; thrown weapon
$iMinDamage2 = GetStatValue(159)
$iMaxDamage2 = GetStatValue(160)
endif
endif
if ($iMaxDamage1 < $iMinDamage1) then $iMaxDamage1 = $iMinDamage1 + 1
if ($iMaxDamage2 < $iMinDamage2) then $iMaxDamage2 = $iMinDamage2 + 1
local $iStatBonus = Floor((GetStatValue(0, 1) * $iStrBonus + GetStatValue(2, 1) * $iDexBonus) / 100) - 1
local $iEWD = GetStatValue(25) + GetStatValue(343) ; global EWD, itemtype-specific EWD
local $fTotalMult = 1 + $iEWD / 100 + $iStatBonus / 100
local $aiDamage[4] = [$iMinDamage1, $iMaxDamage1, $iMinDamage2, $iMaxDamage2]
for $i = 0 to 3
$g_aiStatsCache[1][21+$i] = Floor($aiDamage[$i] * $fTotalMult)
next
endfunc
func FixStats() ; This game is stupid
for $i = 67 to 69 ; Velocities
$g_aiStatsCache[1][$i] = 0
next
$g_aiStatsCache[1][343] = 0 ; itemtype-specific EWD (Elfin Weapons, Shadow Dancer)
local $pSkillsTxt = _MemoryRead($g_pD2sgpt + 0xB98, $g_ahD2Handle)
local $iSkillID, $pStats, $iStatCount, $pSkill, $iStatIndex, $iStatValue, $iOwnerType, $iStateID
local $pItemTypesTxt = _MemoryRead($g_pD2sgpt + 0xBF8, $g_ahD2Handle)
local $pItemsTxt = _MemoryRead($g_hD2Common + 0x9FB98, $g_ahD2Handle)
local $iWeaponClass, $pWeapon, $iWeaponType, $iItemType
local $pUnitAddress = GetUnitToRead()
local $pUnit = _MemoryRead($pUnitAddress, $g_ahD2Handle)
local $aiOffsets[3] = [0, 0x5C, 0x3C]
local $pStatList = _MemoryPointerRead($pUnitAddress, $g_ahD2Handle, $aiOffsets)
while $pStatList
$iOwnerType = _MemoryRead($pStatList + 0x08, $g_ahD2Handle)
$pStats = _MemoryRead($pStatList + 0x24, $g_ahD2Handle)
$iStatCount = _MemoryRead($pStatList + 0x28, $g_ahD2Handle, "word")
$pStatList = _MemoryRead($pStatList + 0x2C, $g_ahD2Handle)
$iSkillID = 0
for $i = 0 to $iStatCount - 1
$iStatIndex = _MemoryRead($pStats + $i*8 + 2, $g_ahD2Handle, "word")
$iStatValue = _MemoryRead($pStats + $i*8 + 4, $g_ahD2Handle, "int")
if ($iStatIndex == 350 and $iStatValue <> 511) then $iSkillID = $iStatValue
if ($iOwnerType == 4 and $iStatIndex == 67) then $g_aiStatsCache[1][$iStatIndex] += $iStatValue ; Armor FRW penalty
next
if ($iOwnerType == 4) then continueloop
$iStateID = _MemoryRead($pStatList + 0x14, $g_ahD2Handle)
switch $iStateID
case 195 ; Dark Power, Tome of Possession aura
$iSkillID = 687 ; Dark Power
endswitch
local $bHasVelocity[3] = [False,False,False]
if ($iSkillID) then ; Game doesn't even bother setting the skill id for some skills, so we'll just have to hope the state is correct or the stat list isn't lying...
$pSkill = $pSkillsTxt + 0x23C*$iSkillID
for $i = 0 to 4
$iStatIndex = _MemoryRead($pSkill + 0x98 + $i*2, $g_ahD2Handle, "word")
switch $iStatIndex
case 67 to 69
$bHasVelocity[$iStatIndex-67] = True
endswitch
next
for $i = 0 to 5
$iStatIndex = _MemoryRead($pSkill + 0x54 + $i*2, $g_ahD2Handle, "word")
switch $iStatIndex
case 67 to 69
$bHasVelocity[$iStatIndex-67] = True
endswitch
next
endif
for $i = 0 to $iStatCount - 1
$iStatIndex = _MemoryRead($pStats + $i*8 + 2, $g_ahD2Handle, "word")
$iStatValue = _MemoryRead($pStats + $i*8 + 4, $g_ahD2Handle, "int")
switch $iStatIndex
case 67 to 69
if (not $iSkillID or $bHasVelocity[$iStatIndex-67]) then $g_aiStatsCache[1][$iStatIndex] += $iStatValue
case 343
$iItemType = _MemoryRead($pStats + $i*8 + 0, $g_ahD2Handle, "word")
$pWeapon = GetUnitWeapon($pUnit)
if (not $pWeapon or not $iItemType) then continueloop
$iWeaponClass = _MemoryRead($pWeapon + 0x04, $g_ahD2Handle)
$iWeaponType = _MemoryRead($pItemsTxt + 0x1A8 * $iWeaponClass + 0x11E, $g_ahD2Handle, "word")
local $bApply = False
local $aiItemTypes[256] = [1, $iWeaponType]
local $iEquiv
local $j = 1
while ($j <= $aiItemTypes[0])
if ($aiItemTypes[$j] == $iItemType) then
$bApply = True
exitloop
endif
for $k = 0 to 1
$iEquiv = _MemoryRead($pItemTypesTxt + 0xE4 * $aiItemTypes[$j] + 0x04 + $k*2, $g_ahD2Handle, "word")
if ($iEquiv) then
$aiItemTypes[0] += 1
$aiItemTypes[ $aiItemTypes[0] ] = $iEquiv
endif
next
$j += 1
wend
if ($bApply) then $g_aiStatsCache[1][343] += $iStatValue
endswitch
next
wend
endfunc
func FixVeteranToken()
$g_aiStatsCache[1][219] = 0 ; Veteran token
local $pUnitAddress = GetUnitToRead()
local $aiOffsets[3] = [0, 0x60, 0x0C]
local $pItem = _MemoryPointerRead($pUnitAddress, $g_ahD2Handle, $aiOffsets)
local $pItemData, $pStatsEx, $pStats, $iStatCount, $iStatIndex, $iVeteranTokenCounter
while $pItem
$pItemData = _MemoryRead($pItem + 0x14, $g_ahD2Handle)
$pStatsEx = _MemoryRead($pItem + 0x5C, $g_ahD2Handle)
$pItem = _MemoryRead($pItemData + 0x64, $g_ahD2Handle)
if (not $pStatsEx) then continueloop
$pStats = _MemoryRead($pStatsEx + 0x48, $g_ahD2Handle)
if (not $pStats) then continueloop
$iStatCount = _MemoryRead($pStatsEx + 0x4C, $g_ahD2Handle, "word")
$iVeteranTokenCounter = 0
for $i = 0 to $iStatCount - 1
$iStatIndex = _MemoryRead($pStats + $i*8 + 2, $g_ahD2Handle, "word")
switch $iStatIndex
case 83, 85, 219
$iVeteranTokenCounter += 1
endswitch
next
if ($iVeteranTokenCounter == 3) then
$g_aiStatsCache[1][219] = 1 ; Veteran token
return
endif
wend
endfunc
func GetStatValue($iStatID, $iVector = default)
if ($iVector == default) then $iVector = $iStatID < 4 ? 0 : 1
local $iStatValue = $g_aiStatsCache[$iVector][$iStatID]
return Floor($iStatValue ? $iStatValue : 0)
endfunc
#EndRegion
#Region Drop notifier
func NotifierFlag($sFlag)
for $i = 0 to $eNotifyFlagsLast - 1
for $j = 0 to UBound($g_asNotifyFlags, $UBOUND_COLUMNS) - 1
if ($g_asNotifyFlags[$i][$j] == "") then
exitloop
elseif ($g_asNotifyFlags[$i][$j] == $sFlag) then
return $i > $eNotifyFlagsNoMask ? $j : BitRotate(1, $j, "D")
endif
next
next
return SetError(1, 0, 0)
endfunc
func NotifierFlagRef($sFlag, ByRef $iFlag, ByRef $iGroup)
$iFlag = 0
$iGroup = 0
for $i = 0 to $eNotifyFlagsLast - 1
for $j = 0 to UBound($g_asNotifyFlags, $UBOUND_COLUMNS) - 1
if ($g_asNotifyFlags[$i][$j] == "") then
exitloop
elseif ($g_asNotifyFlags[$i][$j] == $sFlag) then
$iGroup = $i
$iFlag = $j
return 1
endif
next
next
return SetError(1, 0, 0)
endfunc
func NotifierCache()
if (not $g_bNotifyCache) then return
$g_bNotifyCache = False
local $iItemsTxt = _MemoryRead($g_hD2Common + 0x9FB94, $g_ahD2Handle)
local $pItemsTxt = _MemoryRead($g_hD2Common + 0x9FB98, $g_ahD2Handle)
local $pBaseAddr, $iNameID, $sName, $asMatch, $sTier
redim $g_avNotifyCache[$iItemsTxt][3]
for $iClass = 0 to $iItemsTxt - 1
$pBaseAddr = $pItemsTxt + 0x1A8 * $iClass
$iNameID = _MemoryRead($pBaseAddr + 0xF4, $g_ahD2Handle, "word")
$sName = RemoteThread($g_pD2InjectGetString, $iNameID)
$sName = _MemoryRead($sName, $g_ahD2Handle, "wchar[100]")
$sName = StringReplace($sName, @LF, "|")
$sName = StringRegExpReplace($sName, "ÿc.", "")
$sTier = "0"
if (_MemoryRead($pBaseAddr + 0x84, $g_ahD2Handle)) then ; Weapon / Armor
$asMatch = StringRegExp($sName, "[1-4]|\Q(Sacred)\E", $STR_REGEXPARRAYGLOBALMATCH)
if (not @error) then $sTier = $asMatch[0] == "(Sacred)" ? "sacred" : $asMatch[0]
endif
$g_avNotifyCache[$iClass][0] = $sName
$g_avNotifyCache[$iClass][1] = NotifierFlag($sTier)
$g_avNotifyCache[$iClass][2] = StringRegExpReplace($sName, ".+\|", "")
if (@error) then
_Debug("NotifierCache", StringFormat("Invalid tier flag '%s'", $sTier))
exit
endif
next
endfunc
func NotifierCompileFlag($sFlag, ByRef $avRet, $sLine)
if ($sFlag == "") then return False
local $iFlag, $iGroup
if (not NotifierFlagRef($sFlag, $iFlag, $iGroup)) then
MsgBox($MB_ICONWARNING, "D2Stats", StringFormat("Unknown notifier flag '%s' in line:%s%s", $sFlag, @CRLF, $sLine))
return False
endif
if ($iGroup < $eNotifyFlagsNoMask) then $iFlag = BitOR(BitRotate(1, $iFlag, "D"), $avRet[$iGroup])
$avRet[$iGroup] = $iFlag
return $iGroup <> $eNotifyFlagsColour
endfunc
func NotifierCompileLine($sLine, ByRef $avRet)
$sLine = StringStripWS(StringRegExpReplace($sLine, "#.*", ""), BitOR($STR_STRIPLEADING, $STR_STRIPTRAILING, $STR_STRIPSPACES))
local $iLineLength = StringLen($sLine)
local $sArg = "", $sChar
local $bQuoted = False, $bHasFlags = False
redim $avRet[0]
redim $avRet[$eNotifyFlagsLast]
for $i = 1 to $iLineLength
$sChar = StringMid($sLine, $i, 1)
if ($sChar == '"') then
if ($bQuoted) then
$avRet[$eNotifyFlagsMatch] = $sArg
$sArg = ""
endif
$bQuoted = not $bQuoted
elseif ($sChar == " " and not $bQuoted) then
if (NotifierCompileFlag($sArg, $avRet, $sLine)) then $bHasFlags = True
$sArg = ""
else
$sArg &= $sChar
endif
next
if (NotifierCompileFlag($sArg, $avRet, $sLine)) then $bHasFlags = True
if ($avRet[$eNotifyFlagsMatch] == "") then
if (not $bHasFlags) then return False
$avRet[$eNotifyFlagsMatch] = ".+"
endif
return True
endfunc
func NotifierCompile()
if (not $g_bNotifyCompile) then return
$g_bNotifyCompile = False
$g_bNotifierChanged = True
local $asLines = StringSplit(_GUI_Option("notify-text"), @LF)
local $iLines = $asLines[0]
redim $g_avNotifyCompile[0][0]
redim $g_avNotifyCompile[$iLines][$eNotifyFlagsLast]
local $avRet[0]
local $iCount = 0
for $i = 1 to $iLines
if (NotifierCompileLine($asLines[$i], $avRet)) then
for $j = 0 to $eNotifyFlagsLast - 1
$g_avNotifyCompile[$iCount][$j] = $avRet[$j]
next
$iCount += 1
endif
next
redim $g_avNotifyCompile[$iCount][$eNotifyFlagsLast]
endfunc
func NotifierHelp($sInput)
NotifierCache()
local $iItems = UBound($g_avNotifyCache)
local $asMatches[$iItems][2]
local $iCount = 0
local $avRet[0]
if (NotifierCompileLine($sInput, $avRet)) then
local $sMatch = $avRet[$eNotifyFlagsMatch]
local $iFlagsTier = $avRet[$eNotifyFlagsTier]
local $sName, $iTierFlag
for $i = 0 to $iItems - 1
$sName = $g_avNotifyCache[$i][0]
$iTierFlag = $g_avNotifyCache[$i][1]
if (StringRegExp($sName, $sMatch)) then
if ($iFlagsTier and not BitAND($iFlagsTier, $iTierFlag)) then continueloop
$asMatches[$iCount][0] = $sName
$asMatches[$iCount][1] = $g_avNotifyCache[$i][2]
$iCount += 1
endif
next
endif
redim $asMatches[$iCount][2]
_ArrayDisplay($asMatches, "Notifier Help", default, 32, @LF, "Item|Text")
endfunc
func NotifierMain()
NotifierCache()
NotifierCompile()
local $aiOffsets[4] = [0, 0x2C, 0x1C, 0x0]
local $pPaths = _MemoryPointerRead($g_hD2Client + 0x11BBFC, $g_ahD2Handle, $aiOffsets)
$aiOffsets[3] = 0x24
local $iPaths = _MemoryPointerRead($g_hD2Client + 0x11BBFC, $g_ahD2Handle, $aiOffsets)
if (not $pPaths or not $iPaths) then return
local $pPath, $pUnit, $pUnitData
local $iUnitType, $iClass, $iQuality, $iEarLevel, $iNewEarLevel, $iFlags, $sName, $iTierFlag
local $bIsNewItem, $bIsSocketed, $bIsEthereal
local $iFlagsTier, $iFlagsQuality, $iFlagsMisc, $iFlagsColour, $iFlagsSound
local $bNotify, $sText, $iColor
local $bNotifySuperior = _GUI_Option("notify-superior")
local $tUnitAny = DllStructCreate("dword iUnitType;dword iClass;dword pad1[3];dword pUnitData;dword pad2[52];dword pUnit;")
local $tItemData = DllStructCreate("dword iQuality;dword pad1[5];dword iFlags;dword pad2[11];byte iEarLevel;")
for $i = 0 to $iPaths - 1
$pPath = _MemoryRead($pPaths + 4*$i, $g_ahD2Handle)
$pUnit = _MemoryRead($pPath + 0x74, $g_ahD2Handle)
while $pUnit
_WinAPI_ReadProcessMemory($g_ahD2Handle[1], $pUnit, DllStructGetPtr($tUnitAny), DllStructGetSize($tUnitAny), 0)
$iUnitType = DllStructGetData($tUnitAny, "iUnitType")
$pUnitData = DllStructGetData($tUnitAny, "pUnitData")
$iClass = DllStructGetData($tUnitAny, "iClass")
$pUnit = DllStructGetData($tUnitAny, "pUnit")
; iUnitType 4 = item
if ($iUnitType == 4) then
_WinAPI_ReadProcessMemory($g_ahD2Handle[1], $pUnitData, DllStructGetPtr($tItemData), DllStructGetSize($tItemData), 0)
$iQuality = DllStructGetData($tItemData, "iQuality")
$iFlags = DllStructGetData($tItemData, "iFlags")
$iEarLevel = DllStructGetData($tItemData, "iEarLevel")
; Using the ear level field to check if we've seen this item on the ground before
; Resets when the item is picked up or we move too far away
if (not $g_bNotifierChanged and $iEarLevel <> 0) then continueloop
$iNewEarLevel = 1
$bIsNewItem = BitAND(0x2000, $iFlags) <> 0
$bIsSocketed = BitAND(0x800, $iFlags) <> 0
$bIsEthereal = BitAND(0x400000, $iFlags) <> 0
$sName = $g_avNotifyCache[$iClass][0]
$iTierFlag = $g_avNotifyCache[$iClass][1]
$sText = $g_avNotifyCache[$iClass][2]
$bNotify = False
for $j = 0 to UBound($g_avNotifyCompile) - 1
if (StringRegExp($sName, $g_avNotifyCompile[$j][$eNotifyFlagsMatch])) then
$iFlagsTier = $g_avNotifyCompile[$j][$eNotifyFlagsTier]
$iFlagsQuality = $g_avNotifyCompile[$j][$eNotifyFlagsQuality]
$iFlagsMisc = $g_avNotifyCompile[$j][$eNotifyFlagsMisc]
$iFlagsColour = $g_avNotifyCompile[$j][$eNotifyFlagsColour]
$iFlagsSound = $g_avNotifyCompile[$j][$eNotifyFlagsSound]
if ($iFlagsTier and not BitAND($iFlagsTier, $iTierFlag)) then continueloop
if ($iFlagsQuality and not BitAND($iFlagsQuality, BitRotate(1, $iQuality - 1, "D"))) then continueloop
if (not $bIsSocketed and BitAND($iFlagsMisc, NotifierFlag("socket"))) then continueloop
if ($bIsEthereal) then
$sText &= " (Eth)"
elseif (BitAND($iFlagsMisc, NotifierFlag("eth"))) then
continueloop
endif
if ($iFlagsColour == NotifierFlag("hide")) then
$iNewEarLevel = 2
elseif ($iFlagsColour <> NotifierFlag("show")) then
$bNotify = True
endif
exitloop
endif
next
_MemoryWrite($pUnitData + 0x48, $g_ahD2Handle, $iNewEarLevel, "byte")
if ($bNotify) then
if ($iFlagsColour) then
$iColor = $iFlagsColour - 1
elseif ($iQuality == $eQualityNormal and $iTierFlag == NotifierFlag("0")) then
$iColor = $ePrintOrange
else
$iColor = $g_iQualityColor[$iQuality]
endif
if ($bNotifySuperior and $iQuality == $eQualitySuperior) then $sText = "Superior " & $sText
PrintString("- " & $sText, $iColor)
if ($iFlagsSound <> NotifierFlag("sound_none")) then NotifierPlaySound($iFlagsSound)
endif
endif
wend
next
$g_bNotifierChanged = False
endfunc
func NotifierPlaySound($iSound)
local $iVolume = _GUI_Volume($iSound - 1) * 10
if ($iVolume > 0) then
local $sScriptFile = @Compiled ? "" : StringFormat(' "%s"', @ScriptFullPath)
local $sRun = StringFormat('"%s"%s %s %s %s', @AutoItExe, $sScriptFile, "sound", $iSound, $iVolume)
Run($sRun)
endif
endfunc
#EndRegion
#Region GUI helper functions
func _GUI_StringWidth($sText)
return 2 + 7 * StringLen($sText)
endfunc
func _GUI_LineY($iLine)
return 28 + 15*$iLine
endfunc
func _GUI_GroupX($iX = default)
if ($iX <> default) then $g_avGUI[0][1] = $iX
return $g_avGUI[0][1]
endfunc
func _GUI_GroupFirst()
$g_avGUI[0][1] = $g_iGroupXStart
endfunc
func _GUI_GroupNext()
$g_avGUI[0][1] += $g_iGroupWidth
endfunc
func _GUI_ItemCount()
return $g_avGUI[0][0]
endfunc
func _GUI_NewItem($iLine, $sText, $sTip = default, $iColor = default)
$g_avGUI[0][0] += 1
local $iCount = $g_avGUI[0][0]
$g_avGUI[$iCount][0] = $sText
$g_avGUI[$iCount][1] = _GUI_GroupX()
$g_avGUI[$iCount][2] = _GUI_NewText($iLine, $sText, $sTip, $iColor)
endfunc
func _GUI_NewText($iLine, $sText, $sTip = default, $iColor = default)
local $idRet = _GUI_NewTextBasic($iLine, $sText)
; GUICtrlSetBkColor(-1, Random(0, 2147483647, 1))
if ($sTip <> default) then
GUICtrlSetTip(-1, StringReplace($sTip, "|", @LF), default, default, $TIP_CENTER)
endif
if ($iColor >= default) then
GUICtrlSetColor(-1, $iColor)
endif
return $idRet
endfunc
func _GUI_NewTextBasic($iLine, $sText, $bCentered = True)
local $iWidth = _GUI_StringWidth($sText)
local $iX = _GUI_GroupX() - ($bCentered ? $iWidth/2 : 0)
return GUICtrlCreateLabel($sText, $iX, _GUI_LineY($iLine), $iWidth, 15, $bCentered ? $SS_CENTER : $SS_LEFT)
endfunc
func _GUI_ItemByRef($iItem, byref $sText, byref $iX, byref $idControl)
$sText = $g_avGUI[$iItem][0]
$iX = $g_avGUI[$iItem][1]
$idControl = $g_avGUI[$iItem][2]
endfunc
func _GUI_OptionCount()
return $g_avGUIOption[0][0]
endfunc
func _GUI_NewOption($iLine, $sOption, $sText, $sFunc = "")
local $iY = _GUI_LineY($iLine)*2 - _GUI_LineY(0)
local $idControl
local $sOptionType = _GUI_OptionType($sOption)
switch $sOptionType
case null
_Log("_GUI_NewOption", "Invalid option '" & $sOption & "'")
exit
case "hk"
Call($sFunc, True)
if (@error == 0xDEAD and @extended == 0xBEEF) then
_Log("_GUI_NewOption", StringFormat("No hotkey function '%s' for option '%s'", $sFunc, $sOption))
exit