forked from RedGuides/MQ2DPSAdv
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMQ2DPSAdv.cpp
More file actions
1883 lines (1723 loc) · 59 KB
/
MQ2DPSAdv.cpp
File metadata and controls
1883 lines (1723 loc) · 59 KB
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
// DPS ADV CREATED BY WARNEN 2008-2009
// MQ2DPSAdv.cpp
#include <mq/Plugin.h>
#include "MQ2DPSAdv.h"
PreSetup("MQ2DPSAdv");
PLUGIN_VERSION(1.6);
// ############################### DPSEntry Start ############################################
DPSMob::DPSEntry::DPSEntry() {
Init();
}
DPSMob::DPSEntry::DPSEntry(CHAR EntName[], DPSMob* pParent, bool PCOnly /* = false */) {
Init();
Parent = pParent;
strncpy_s(Name, EntName, sizeof(Name) - 1);
GetSpawn(PCOnly);
}
void DPSMob::DPSEntry::Init() {
Parent = nullptr;
SpawnType = -1;
Mercenary = false;
Class = 0;
Spawn = nullptr;
Master = nullptr;
DoSort = false;
Pets = false;
CheckPetName = false;
UsingPetName = false;
strcpy_s(Name, "");
Damage.Total = 0;
Damage.First = 0;
Damage.Last = 0;
Damage.AddTime = 0;
}
void DPSMob::DPSEntry::GetSpawn(bool PCOnly /* = false */) {
PSPAWNINFO pSpawn = (PSPAWNINFO)pSpawnList;
while (pSpawn) {
if (!_stricmp(pSpawn->DisplayedName, Name) && (!PCOnly || pSpawn->Type == SPAWN_PLAYER)) {
if (pSpawn->Type != SPAWN_CORPSE) {
Spawn = pSpawn;
SpawnType = Spawn->Type;
Class = Spawn->mActorClient.Class;
Mercenary = pSpawn->Mercenary;
return;
}
}
pSpawn = pSpawn->pNext;
}
if (Debug && !Spawn) WriteChatf("\arError: Could not find Ent Spawn (%s)", Name);
}
bool DPSMob::DPSEntry::CheckMaster() {
if (DoSort) return Master ? true : false;
if (UsingPetName) return true;
if (!CheckPetName) {
CheckPetName = true;
if (strstr(Name, "`s pet")) {
UsingPetName = true;
CHAR szMaster[MAX_STRING] = { 0 };
strcpy_s(szMaster, Name);
if (char* pDest = strstr(szMaster, "`s pet")) {
pDest[0] = '\0';
}
Master = Parent->GetEntry(szMaster);
return true;
}
}
if (Master != nullptr && (Spawn == nullptr || Spawn->MasterID <= 0 || Master->Spawn == nullptr || Master->Spawn->SpawnID != Spawn->MasterID)) Master = nullptr;
if (Master != nullptr) return true;
if (Spawn && Spawn->MasterID > 0) {
PSPAWNINFO NewMaster = (PSPAWNINFO)GetSpawnByID(Spawn->MasterID);
if (NewMaster) {
Master = Parent->GetEntry(NewMaster->DisplayedName, true, true);
return Master != nullptr;
}
}
return false;
}
void DPSMob::DPSEntry::AddDamage(int Damage1) {
if (CheckMaster()) {
Master->Pets = true;
Master->AddDamage(Damage1);
DoSort = true;
return;
}
DoSort = true;
time_t timenow = time(nullptr);
if (Damage.First && (timenow - Damage.Last >= EntTO)) {
Damage.AddTime += (int)(Damage.Last - Damage.First) + 1;
Damage.First = 0;
}
Damage.Total += Damage1;
if (!Damage.First)
Damage.First = timenow;
Damage.Last = timenow;
Parent->AddDamage(Damage1);
}
uint64_t DPSMob::DPSEntry::GetDPS() {
uint64_t dividetotal = (((Damage.Last - Damage.First) + 1) + Damage.AddTime);
if (dividetotal == 0)
return 0;
return (Damage.Total / dividetotal);
}
uint64_t DPSMob::DPSEntry::GetSDPS() {
uint64_t dividetotal = ((CurListMob->Damage.Last - CurListMob->Damage.First) + 1) + CurListMob->Damage.AddTime;
if (dividetotal == 0)
return 0;
return (Damage.Total / dividetotal);
}
void DPSMob::DPSEntry::Sort() {
DoSort = false;
if (Master && Master->DoSort) Master->Sort();
if (Damage.Total == 0) return;
int i = 0, x = -1;
bool Inserted = false;
for (i = 0; i < (int)Parent->EntList.size(); i++) {
if (Parent->EntList[i] == this) {
Inserted = true;
if (x == -1) break;
Parent->EntList.erase(Parent->EntList.begin() + i);
Parent->EntList.insert(Parent->EntList.begin() + x, this);
break;
}
else if (x == -1 && Parent->EntList[i]->Damage.Total < Damage.Total) x = i;
}
if (!Inserted)
if (x != -1) Parent->EntList.insert(Parent->EntList.begin() + x, this);
else Parent->EntList.push_back(this);
if (LiveUpdate && Parent == CurListMob && !CurListMob->Dead) DPSWnd->DrawList();
};
// ############################### DPSMob START ############################################
DPSMob::DPSMob() {
Init();
}
DPSMob::DPSMob(const char* MobName, size_t MobLen) {
Init();
strncpy_s(Name, MobName, sizeof(Name) - 1);
GetSpawn();
if (strstr(Name, "`s pet"))
PetName = true;
}
void DPSMob::Init() {
strcpy_s(Name, "");
Damage.Total = 0;
Damage.First = 0;
Damage.Last = 0;
LastEntry = 0;
SpawnType = -1;
Mercenary = false;
Spawn = 0;
Active = false;
Dead = false;
PetName = false;
}
void DPSMob::GetSpawn() {
PSPAWNINFO pSpawn = (PSPAWNINFO)pSpawnList;
while (pSpawn) {
if (!_stricmp(pSpawn->DisplayedName, Name)) {
SpawnType = pSpawn->Type;
Mercenary = pSpawn->Mercenary;
Spawn = pSpawn;
if (SpawnType != SPAWN_CORPSE) {
Dead = false;
return;
}
Dead = true;
}
pSpawn = pSpawn->pNext;
}
if (Debug && !Spawn) WriteChatf("\arError: Could not find Mob Spawn (%s)", Name);
}
bool DPSMob::IsPet() {
return PetName || (Spawn && Spawn->MasterID > 0);
}
void DPSMob::AddDamage(int Damage1) {
Damage.Total += Damage1;
time_t timenow = time(nullptr);
if (!Damage.First)
Damage.First = timenow;
Damage.Last = timenow;
if (!Active) {
Active = true;
sprintf_s(Tag, "[A] ");
if (!IsPet() && !Mercenary)
DPSWnd->DrawCombo();
}
}
DPSMob::DPSEntry* DPSMob::GetEntry(char EntName[], bool Create /* = true */, bool PCOnly /* = false */) {
char szBuffer[256] = { 0 };
strcpy_s(szBuffer, 256, EntName);
if (!_stricmp(szBuffer, "You")) {
strcpy_s(szBuffer, 256, ((PSPAWNINFO)pLocalPlayer)->Name);
}
if (LastEntry && !strcmp(LastEntry->Name, szBuffer) && (!PCOnly || LastEntry->SpawnType == SPAWN_PLAYER)) return LastEntry;
if (LastEntry && LastEntry->DoSort) LastEntry->Sort();
// TODO: This and other areas like this should probably be range based for loops.
for (int i = 0; i < (int)EntList.size(); i++) {
if (EntList[i] != nullptr && !strcmp(EntList[i]->Name, szBuffer) && (!PCOnly || EntList[i]->SpawnType == SPAWN_PLAYER)) {
LastEntry = EntList[i];
return LastEntry;
}
}
if (Create) {
LastEntry = new DPSEntry(szBuffer, this, PCOnly);
EntList.push_back(LastEntry);
return LastEntry;
}
return nullptr;
}
// ############################### CDPSAdvWnd START ############################################
CDPSAdvWnd::CDPSAdvWnd() :CCustomWnd("DPSAdvWnd") {
// TODO: This looks like it can all be done with WrongUI
bool CheckUI = false;
// Tabs holder exists?
if (!(Tabs = (CTabWnd*)GetChildItem("DPS_Tabs"))) CheckUI = true;
// DPS Settings Tab
if (!(CShowMeTop = (CCheckBoxWnd*)GetChildItem("DPS_ShowMeTopBox"))) CheckUI = true;
if (!(CShowMeMin = (CCheckBoxWnd*)GetChildItem("DPS_ShowMeMinBox"))) CheckUI = true;
if (!(TShowMeMin = (CEditWnd*)GetChildItem("DPS_ShowMeMinInput"))) CheckUI = true;
if (!(CUseRaidColors = (CCheckBoxWnd*)GetChildItem("DPS_UseRaidColorsBox"))) CheckUI = true;
if (!(CLiveUpdate = (CCheckBoxWnd*)GetChildItem("DPS_LiveUpdateBox"))) CheckUI = true;
if (!(CUseTBMKOutput = (CCheckBoxWnd*)GetChildItem("DPS_UseTBMKOutputBox"))) CheckUI = true;
if (!(TFightIA = (CEditWnd*)GetChildItem("DPS_FightIAInput"))) CheckUI = true;
if (!(TFightTO = (CEditWnd*)GetChildItem("DPS_FightTOInput"))) CheckUI = true;
if (!(TEntTO = (CEditWnd*)GetChildItem("DPS_EntTOInput"))) CheckUI = true;
if (!(THistoryLimit = (CEditWnd*)GetChildItem("DPS_HistoryLimitInput"))) CheckUI = true;
if (!(CShowTotal = (CComboWnd*)GetChildItem("DPS_ShowTotal"))) CheckUI = true;
// End DPS Settings Tab
// DPS Tab
if (!(LTopList = (CListWnd*)GetChildItem("DPS_TopList"))) CheckUI = true;
if (!(CMobList = (CComboWnd*)GetChildItem("DPS_MobList"))) CheckUI = true;
// Setting this here sets it for the entire window. Setting everything individually was blacking out the checkboxes!
this->SetBGColor(MQColor(0, 0, 0));
if (CheckUI) {
WriteChatf("\ar[MQ2DPSAdv] Incorrect UI File in use. Please update to latest and reload plugin.");
WrongUI = true;
}
else
{
WrongUI = false;
LoadLoc();
CMobList->SetColors(MQColor(204, 51, 51), MQColor(102, 102, 102), MQColor(0, 0, 0));
Tabs->UpdatePage();
DrawCombo();
}
}
CDPSAdvWnd::~CDPSAdvWnd() {}
void CDPSAdvWnd::DrawCombo() {
int CurSel = CMobList->GetCurChoice();
CMobList->DeleteAll();
CHAR szTemp[MAX_STRING] = { 0 };
// TODO: There's probably a better way to do this since this code is duplicated, but this moves the previous ternaries into a more readable format.
strcpy_s(szTemp, "<Target> ");
if (CListType == CLISTTARGET && CurListMob != nullptr)
{
strcat_s(szTemp, CurListMob->Tag);
strcat_s(szTemp, CurListMob->Name);
}
else
{
strcat_s(szTemp, "None");
}
CMobList->InsertChoice(szTemp);
strcpy_s(szTemp, "<MaxDmg> ");
if (CListType == CLISTMAXDMG && CurListMob != nullptr)
{
strcat_s(szTemp, CurListMob->Tag);
strcat_s(szTemp, CurListMob->Name);
}
else
{
strcat_s(szTemp, "None");
}
CMobList->InsertChoice(szTemp);
DPSMob* Mob = nullptr;
int ListSize = 0;
for (int i = 0; i < (int)MobList.size(); ++i) {
Mob = MobList[i];
if (Mob->SpawnType == 1 && Mob->Active && !Mob->IsPet() && !Mob->Mercenary) {
ListSize++;
sprintf_s(szTemp, "%s(%i) %s", Mob->Tag, ListSize, Mob->Name);
CMobList->InsertChoice(szTemp);
}
}
if (ListSize < 6) CMobList->InsertChoice("");
if (CListType == CLISTTARGET) CMobList->SetChoice(0);
else if (CListType == CLISTMAXDMG) CMobList->SetChoice(1);
else CMobList->SetChoice(CurSel >= 0 ? CurSel : 0);
}
void CDPSAdvWnd::SetTotal(int LineNum, DPSMob* Mob) {
CHAR szTemp[MAX_STRING] = { 0 };
SetLineColors(LineNum, 0, true);
//Index
LTopList->SetItemText(LineNum, 0, "-");
//Name
LTopList->SetItemText(LineNum, 1, "Total");
//Total
sprintf_s(szTemp, "%llu", CurListMob->Damage.Total);
if (!UseTBMKOutputs)
PrettifyNumber(szTemp, sizeof(szTemp));
else {
MakeItTBMK(szTemp);
//Need to turn the strings from like 125556 to 125.5k
}
LTopList->SetItemText(LineNum, 2, szTemp);
//DPS
sprintf_s(szTemp, "%llu", CurListMob->Damage.Total / (int)((CurListMob->Damage.Last - CurListMob->Damage.First) + 1));
if (!UseTBMKOutputs)
PrettifyNumber(szTemp, sizeof(szTemp));
else {
MakeItTBMK(szTemp);
//Need to turn the strings from like 125556 to 125.5k
}
LTopList->SetItemText(LineNum, 3, szTemp);
//Time
sprintf_s(szTemp, "%I64is", CurListMob->Damage.Last - CurListMob->Damage.First);
LTopList->SetItemText(LineNum, 4, szTemp);
//This is where Percentage would go, if it wasn't always going to be 100%, if more columns are added, make sure to skip 5!
}
void MakeItTBMK(char* szLine) {
uint64_t value = GetInt64FromString(szLine, 0);
if (value >= 1000000000000) {
value = value / 100000000000;
_i64toa_s(value, szLine, MAX_STRING, 10);
std::string temp = szLine;
temp.insert(temp.end() - 1, '.');
sprintf_s(szLine, MAX_STRING, temp.c_str());
strcat_s(szLine, MAX_STRING, " t");
}
else if (value >= 1000000000) {
value = value / 100000000;
_i64toa_s(value, szLine, MAX_STRING, 10);
std::string temp = szLine;
temp.insert(temp.end() - 1, '.');
sprintf_s(szLine, MAX_STRING, temp.c_str());
strcat_s(szLine, MAX_STRING, " b");
}
else if (value >= 1000000) {
value = value / 100000;
_i64toa_s(value, szLine, MAX_STRING, 10);
std::string temp = szLine;
temp.insert(temp.end() - 1, '.');
sprintf_s(szLine, MAX_STRING, temp.c_str());
strcat_s(szLine, MAX_STRING, " m");
}
else if (value >= 1000) {
value = value / 100;
_i64toa_s(value, szLine, MAX_STRING, 10);
std::string temp = szLine;
temp.insert(temp.end() - 1, '.');
sprintf_s(szLine, MAX_STRING, temp.c_str());
strcat_s(szLine, MAX_STRING, " k");
}
}
void CDPSAdvWnd::DrawList(bool DoDead) {
if (!CurListMob || (!DoDead && CurListMob->Dead)) return;
int ScrollPos = LTopList->GetVScrollPos();
int CurSel = LTopList->GetCurSel();
CHAR szTemp[MAX_STRING] = { 0 };
LTopList->DeleteAll();
int i = 0, LineNum = 0, RankAdj = 0, ShowMeLineNum = 0;
bool FoundMe = false, ThisMe = false;
if (ShowTotal == TOTALABOVE) {
LineNum = LTopList->AddString(CXStr(""), 0, 0, 0);
SetTotal(LineNum, CurListMob);
RankAdj++;
}
if (ShowMeTop) {
ShowMeLineNum = LTopList->AddString(CXStr(""), 0, 0, 0);
SetLineColors(ShowMeLineNum, 0, false, true);
RankAdj++;
}
if (ShowTotal == TOTALSECOND) {
LineNum = LTopList->AddString(CXStr(""), 0, 0, 0);
SetTotal(LineNum, CurListMob);
RankAdj++;
}
for (i = 0; i < (int)CurListMob->EntList.size(); i++) {
DPSMob::DPSEntry* Ent = CurListMob->EntList[i];
if (Ent->Damage.Total == 0) break;
if (ShowMeTop && !strcmp(Ent->Name, pLocalPlayer->DisplayedName)) {
if (!ShowMeMin || (LineNum - RankAdj + 1) > ShowMeMinNum) FoundMe = true;
ThisMe = true;
}
else ThisMe = false;
LineNum = LTopList->AddString(CXStr(""), 0, 0, 0);
SetLineColors(LineNum, Ent);
//Placement Index
sprintf_s(szTemp, "%i", LineNum - RankAdj + 1);
LTopList->SetItemText(LineNum, 0, szTemp);
if (ThisMe) LTopList->SetItemText(ShowMeLineNum, 0, szTemp);
sprintf_s(szTemp, "%s%s%s", Ent->Mercenary ? "[M] " : "", Ent->Name, Ent->Pets ? "*" : "");
LTopList->SetItemText(LineNum, 1, szTemp);
if (ThisMe) LTopList->SetItemText(ShowMeLineNum, 1, szTemp);
//Total Damage
sprintf_s(szTemp, "%llu", Ent->Damage.Total);
if (!UseTBMKOutputs)
PrettifyNumber(szTemp, sizeof(szTemp));
else {
MakeItTBMK(szTemp);
//Need to turn the strings from like 125556 to 125.5k
}
LTopList->SetItemText(LineNum, 2, szTemp);
if (ThisMe) LTopList->SetItemText(ShowMeLineNum, 2, szTemp);
//DPS
char DPSoutput[MAX_STRING] = { 0 };
sprintf_s(DPSoutput, "%llu", Ent->GetDPS());
if (!UseTBMKOutputs)
PrettifyNumber(DPSoutput, sizeof(DPSoutput));
else {
MakeItTBMK(DPSoutput);
//Need to turn the strings from like 125556 to 125.5k
}
//SDPS (DPS over duration of entire fight?)
char SDPSoutput[MAX_STRING] = { 0 };
sprintf_s(SDPSoutput, "%llu", Ent->GetSDPS());
if (!UseTBMKOutputs)
PrettifyNumber(SDPSoutput, sizeof(SDPSoutput));
else {
MakeItTBMK(SDPSoutput);
//Need to turn the strings from like 125556 to 125.5k
}
sprintf_s(szTemp, "%s (%s)", DPSoutput, SDPSoutput);
LTopList->SetItemText(LineNum, 3, szTemp);
if (ThisMe) LTopList->SetItemText(ShowMeLineNum, 3, szTemp);
//Time
sprintf_s(szTemp, "%I64is", Ent->Damage.Last - Ent->Damage.First);
LTopList->SetItemText(LineNum, 4, szTemp);
if (ThisMe) LTopList->SetItemText(ShowMeLineNum, 4, szTemp);
//Percentage of Damage
sprintf_s(szTemp, "%2.0f", (((float)Ent->Damage.Total / (float)CurListMob->Damage.Total) * 100.0f));
strcat_s(szTemp, "%");
LTopList->SetItemText(LineNum, 5, szTemp);
if (ThisMe) LTopList->SetItemText(ShowMeLineNum, 5, szTemp);
}
if (ShowTotal == TOTALBOTTOM) {
LineNum = LTopList->AddString(CXStr(""), 0, 0, 0);
SetTotal(LineNum, CurListMob);
}
if (ShowMeTop && !FoundMe) LTopList->RemoveLine(ShowMeLineNum);
LTopList->SetVScrollPos(ScrollPos);
LTopList->CalculateFirstVisibleLine();
LTopList->SetCurSel(CurSel);
}
void CDPSAdvWnd::SetLineColors(int LineNum, DPSMob::DPSEntry* Ent, bool Total, bool MeTop) {
if (MeTop) {
LTopList->SetItemColor(LineNum, 0, MeTopColor);
LTopList->SetItemColor(LineNum, 1, MeTopColor);
LTopList->SetItemColor(LineNum, 2, MeTopColor);
LTopList->SetItemColor(LineNum, 3, MeTopColor);
LTopList->SetItemColor(LineNum, 4, MeTopColor);
LTopList->SetItemColor(LineNum, 5, MeTopColor);
}
else if (Total) {
LTopList->SetItemColor(LineNum, 0, TotalColor);
LTopList->SetItemColor(LineNum, 1, TotalColor);
LTopList->SetItemColor(LineNum, 2, TotalColor);
LTopList->SetItemColor(LineNum, 3, TotalColor);
LTopList->SetItemColor(LineNum, 4, TotalColor);
LTopList->SetItemColor(LineNum, 5, TotalColor);
}
else if (!strcmp(Ent->Name, pLocalPlayer->DisplayedName)) {
LTopList->SetItemColor(LineNum, 0, MeColor);
LTopList->SetItemColor(LineNum, 1, MeColor);
LTopList->SetItemColor(LineNum, 2, MeColor);
LTopList->SetItemColor(LineNum, 3, MeColor);
LTopList->SetItemColor(LineNum, 4, MeColor);
LTopList->SetItemColor(LineNum, 5, MeColor);
}
else if (UseRaidColors && Ent->Class && (Ent->SpawnType == SPAWN_PLAYER || Ent->Mercenary)) {
LTopList->SetItemColor(LineNum, 0, NormalColor);
LTopList->SetItemColor(LineNum, 1, pRaidWnd->ClassColors[ClassInfo[Ent->Class].RaidColorOrder]);
LTopList->SetItemColor(LineNum, 2, NormalColor);
LTopList->SetItemColor(LineNum, 3, NormalColor);
LTopList->SetItemColor(LineNum, 4, NormalColor);
LTopList->SetItemColor(LineNum, 5, NormalColor);
}
else {
LTopList->SetItemColor(LineNum, 0, NormalColor);
LTopList->SetItemColor(LineNum, 1, NPCColor);
LTopList->SetItemColor(LineNum, 2, NormalColor);
LTopList->SetItemColor(LineNum, 3, NormalColor);
LTopList->SetItemColor(LineNum, 4, NormalColor);
LTopList->SetItemColor(LineNum, 5, NormalColor);
}
}
void CDPSAdvWnd::SaveLoc() {
if (!pLocalPC || pLocalPC->Name[0] == '\0')
return;
WritePrivateProfileString(pLocalPC->Name, "Saved", "1", INIFileName);
WritePrivateProfileInt(pLocalPC->Name, "Top", GetLocation().top, INIFileName);
WritePrivateProfileInt(pLocalPC->Name, "Bottom", GetLocation().bottom, INIFileName);
WritePrivateProfileInt(pLocalPC->Name, "Left", GetLocation().left, INIFileName);
WritePrivateProfileInt(pLocalPC->Name, "Right", GetLocation().right, INIFileName);
WritePrivateProfileInt(pLocalPC->Name, "Alpha", GetAlpha(), INIFileName);
WritePrivateProfileInt(pLocalPC->Name, "FadeToAlpha", GetFadeToAlpha(), INIFileName);
WritePrivateProfileInt(pLocalPC->Name, "CListType", CListType, INIFileName);
WritePrivateProfileBool(pLocalPC->Name, "LiveUpdate", LiveUpdate, INIFileName);
WritePrivateProfileBool(pLocalPC->Name, "Show", IsVisible(), INIFileName);
WritePrivateProfileBool(pLocalPC->Name, "ShowMeTop", ShowMeTop, INIFileName);
WritePrivateProfileBool(pLocalPC->Name, "ShowMeMin", ShowMeMin, INIFileName);
WritePrivateProfileInt(pLocalPC->Name, "ShowMeMinNum", ShowMeMinNum, INIFileName);
WritePrivateProfileBool(pLocalPC->Name, "UseRaidColors", UseRaidColors, INIFileName);
WritePrivateProfileInt(pLocalPC->Name, "ShowTotal", ShowTotal, INIFileName);
WritePrivateProfileInt(pLocalPC->Name, "FightIA", FightIA, INIFileName);
WritePrivateProfileInt(pLocalPC->Name, "FightTO", FightTO, INIFileName);
WritePrivateProfileInt(pLocalPC->Name, "EntTO", EntTO, INIFileName);
WritePrivateProfileBool(pLocalPC->Name, "UseTBMKOutputs", UseTBMKOutputs, INIFileName);
WritePrivateProfileInt(pLocalPC->Name, "HistoryLimit", HistoryLimit, INIFileName);
//Save the column widths
for (int i = 0; i <= 5; i++) {
char szColumn[16] = { 0 };
sprintf_s(szColumn, 16, "Column%iWidth", i);
WritePrivateProfileInt(pLocalPC->Name, szColumn, LTopList->GetColumnWidth(i), INIFileName);
}
}
void CDPSAdvWnd::LoadSettings() {
//Set the check boxes to their current settings.
CShowMeTop->SetCheck(ShowMeTop);
CShowMeMin->SetCheck(ShowMeMin);
CUseRaidColors->SetCheck(UseRaidColors);
CLiveUpdate->SetCheck(LiveUpdate);
CUseTBMKOutput->SetCheck(UseTBMKOutputs);
//Set the text in the Inputboxes to their current setting.
TShowMeMin->InputText = std::to_string(ShowMeMinNum);
TFightIA->InputText = std::to_string(FightIA);
TFightTO->InputText = std::to_string(FightTO);
TEntTO->InputText = std::to_string(EntTO);
THistoryLimit->InputText = std::to_string(HistoryLimit);
//Clear and populate the ComboBox options for Show Total
CShowTotal->DeleteAll();
CShowTotal->InsertChoice("Don't Show Total");
CShowTotal->InsertChoice("Above ShowMeTop");
CShowTotal->InsertChoice("Below ShowMeTop");
CShowTotal->InsertChoice("Show Bottom");
CShowTotal->InsertChoice("");
CShowTotal->SetChoice(ShowTotal);
//Make Columns resizable.
LTopList->SetColumnsSizable(true);
}
void CDPSAdvWnd::LoadLoc(char szChar[256]) {
if (!pLocalPC) return;
if (WrongUI)
return;
char szName[256] = { 0 };
if (!szChar) strcpy_s(szName, pLocalPC->Name);
else strcpy_s(szName, szChar);
Saved = GetPrivateProfileBool(szName, "Saved", false, INIFileName);
if (Saved) {
SetLocation({
GetPrivateProfileInt(szName, "Left", 0, INIFileName),
GetPrivateProfileInt(szName, "Top", 0, INIFileName),
GetPrivateProfileInt(szName, "Right", 0, INIFileName),
GetPrivateProfileInt(szName, "Bottom", 0, INIFileName)
});
SetAlpha((uint8_t)GetPrivateProfileInt(szName, "Alpha", 0, INIFileName));
SetFadeToAlpha((uint8_t)GetPrivateProfileInt(szName, "FadeToAlpha", 0, INIFileName));
}
CListType = GetPrivateProfileInt(szName, "CListType", 0, INIFileName);
LiveUpdate = GetPrivateProfileBool(szName, "LiveUpdate", false, INIFileName);
WarnedYHO = GetPrivateProfileBool(szName, "WarnedYHO", false, INIFileName);
WarnedOHO = GetPrivateProfileBool(szName, "WarnedOHO", false, INIFileName);
Debug = GetPrivateProfileBool(szName, "Debug", false, INIFileName);
SetVisible(GetPrivateProfileBool(szName, "Show", true, INIFileName));
ShowMeTop = GetPrivateProfileBool(szName, "ShowMeTop", false, INIFileName);
ShowMeMin = GetPrivateProfileBool(szName, "ShowMeMin", false, INIFileName);
ShowMeMinNum = GetPrivateProfileInt(szName, "ShowMeMinNum", 0, INIFileName);
UseRaidColors = GetPrivateProfileBool(szName, "UseRaidColors", false, INIFileName);
ShowTotal = GetPrivateProfileInt(szName, "ShowTotal", 0, INIFileName);
FightIA = GetPrivateProfileInt(szName, "FightIA", 8, INIFileName);
FightTO = GetPrivateProfileInt(szName, "FightTO", 30, INIFileName);
EntTO = GetPrivateProfileInt(szName, "EntTO", 8, INIFileName);
UseTBMKOutputs = GetPrivateProfileBool(szName, "UseTBMKOutputs", false, INIFileName);
HistoryLimit = GetPrivateProfileInt(szName, "HistoryLimit", 25, INIFileName);
// Load colors
MeColor = GetPrivateProfileColor(szName, "MeColor", MQColor(0, 204, 0), INIFileName);
MeTopColor = GetPrivateProfileColor(szName, "MeTopColor", MQColor(0, 204, 0), INIFileName);
NormalColor = GetPrivateProfileColor(szName, "NormalColor", MQColor(255, 255, 255), INIFileName);
NPCColor = GetPrivateProfileColor(szName, "NPCColor", MQColor(255, 255, 255), INIFileName);
TotalColor = GetPrivateProfileColor(szName, "TotalColor", MQColor(102, 255, 255), INIFileName);
EntHover = GetPrivateProfileColor(szName, "EntHover", MQColor(204, 51, 51), INIFileName);
EntHighlight = GetPrivateProfileColor(szName, "EntHighlight", MQColor(102, 102, 102), INIFileName);
FightNormal = GetPrivateProfileColor(szName, "FightNormal", NormalColor, INIFileName);
FightHover = GetPrivateProfileColor(szName, "FightHover", EntHover, INIFileName);
FightHighlight = GetPrivateProfileColor(szName, "FightHighlight", EntHighlight, INIFileName);
FightActive = GetPrivateProfileColor(szName, "FightActive", MQColor(0, 204, 0), INIFileName);
FightInActive = GetPrivateProfileColor(szName, "FightInActive", MQColor(119, 119, 119), INIFileName);
FightDead = GetPrivateProfileColor(szName, "FightDead", MQColor(51, 0, 0), INIFileName);
//Restore the column widths
for (int i = 0; i <= 5; i++) {
char szTemp[16] = { 0 };
sprintf_s(szTemp, 16, "Column%iWidth", i);
const int temp = GetPrivateProfileInt(szName, szTemp, 0, INIFileName);
if (temp != 0) {
LTopList->SetColumnWidth(i, temp);
}
}
if (FightIA < 3) FightIA = 8;
if (FightTO < 3) FightTO = 30;
if (EntTO < 3) EntTO = 8;
if (CListType > 1) CListType = CLISTTARGET;
LTopList->SetColors(NormalColor, EntHover, EntHighlight);
CMobList->SetChoice(CListType);
LoadSettings();
}
int CDPSAdvWnd::WndNotification(CXWnd* pWnd, unsigned int Message, void* unknown) {
if (Debug && Message != 21) WriteChatf("Notify: %i", Message);
if (Message == XWM_CLOSE) CheckActive();
if (Message == XWM_RCLICK && pWnd == LTopList) LTopList->SetCurSel(-1);
else if (Message == XWM_CLOSE && pWnd == DPSWnd) CheckActive();
else if (Message == XWM_LCLICK) {
if (pWnd == Tabs) LoadSettings();
else if (pWnd == CShowMeTop) ShowMeTop = CShowMeTop->bChecked;
else if (pWnd == CShowMeMin) ShowMeMin = CShowMeMin->bChecked;
else if (pWnd == CUseRaidColors) UseRaidColors = CUseRaidColors->bChecked;
else if (pWnd == CLiveUpdate) LiveUpdate = CLiveUpdate->bChecked;
else if (pWnd == CUseTBMKOutput) UseTBMKOutputs = CUseTBMKOutput->bChecked;
//else if (pWnd == LTopList) WriteChatf("CurSel: %i", LTopList->GetCurSel());
else if (pWnd == CShowTotal) {
ShowTotal = CShowTotal->GetCurChoice();
if (ShowTotal == 4) ShowTotal = 0;
LoadSettings();
}
else if (pWnd == CMobList) {
CurListMob = nullptr;
LTopList->DeleteAll();
bool FoundMob = false;
if ((int)CMobList->GetCurChoice() > 1) {
CListType = 2;
DPSMob* ListMob = nullptr;
int i = 0, x = 0;
for (i = 0; i < (int)MobList.size() - 1; i++) {
ListMob = MobList[i];
if (ListMob->SpawnType == 1 && ListMob->Active && !ListMob->IsPet() && !ListMob->Mercenary) {
if (x + 2 == (int)CMobList->GetCurChoice()) {
FoundMob = true;
ListSwitch(ListMob);
break;
}
x++;
}
}
if (!FoundMob) {
CListType = 0;
DPSWnd->DrawCombo();
}
}
else CListType = (int)CMobList->GetCurChoice();
Intervals -= 1; // Force update next Pulse.
}
}
else if (Message == XWM_NEWVALUE) {
if (pWnd == TShowMeMin) {
if (!TShowMeMin->InputText.empty()) {
ShowMeMinNum = GetIntFromString(TShowMeMin->InputText, 0);
TShowMeMin->SetSel((int)TShowMeMin->InputText.length(), 0);
}
}
else if (pWnd == TFightIA) {
if (!TFightIA->InputText.empty()) {
FightIA = GetIntFromString(TFightIA->InputText, 0);
if (FightIA < 3) FightIA = 8;
}
}
else if (pWnd == TFightTO) {
if (!TFightTO->InputText.empty()) {
FightTO = GetIntFromString(TFightTO->InputText, 0);
if (FightTO < 3) FightTO = 30;
}
}
else if (pWnd == TEntTO) {
if (!TEntTO->InputText.empty()) {
EntTO = GetIntFromString(TEntTO->InputText, 0);
if (EntTO < 3) EntTO = 8;
}
}
else if (pWnd == THistoryLimit) {
if (!THistoryLimit->InputText.empty()) {
HistoryLimit = GetIntFromString(THistoryLimit->InputText, 1);
if (HistoryLimit < 1) HistoryLimit = 1;
}
}
}
return CSidlScreenWnd::WndNotification(pWnd, Message, unknown);
};
template <unsigned int _NameSize>
DPSMob* GetMob(CHAR(&Name)[_NameSize], bool Create, bool Alive)
{
//ParsePet(Name);
if (LastMob && (!Alive || (Alive && !LastMob->Dead)) && !_stricmp(LastMob->Name, Name))
return LastMob;
if (LastMob && LastMob->LastEntry && LastMob->LastEntry->DoSort) LastMob->LastEntry->Sort();
// TODO: Range based for loop.
for (int i = 0; i < (int)MobList.size(); i++) {
if ((!Alive || (Alive && !MobList[i]->Dead)) && !_stricmp(MobList[i]->Name, Name)) {
LastMob = MobList[i];
return LastMob;
}
}
if (Create) {
LastMob = new DPSMob(Name, _NameSize);
MobList.push_back(LastMob);
return LastMob;
}
return nullptr;
}
template <unsigned int _EntSize, unsigned int _MobSize>
bool SplitStringOtherHitOther(const char* Line, char(&EntName)[_EntSize], char(&MobName)[_MobSize], int* Damage)
{
if (strstr(Line, "injured by falling"))
return false;
int HitPos = 0, Action = 0;
if (!strpbrk(Line, "1234567890"))
return false;
*Damage = GetIntFromString(strpbrk(Line, "1234567890"), 0);
while (OtherHits[Action][0]) {
HitPos = find_substr(Line, OtherHits[Action]);
if (HitPos > 0)
break;
Action++;
}
if (!OtherHits[Action][0]) {
return false;
}
if (HitPos <= 0 || HitPos > 2048) {
if (*Damage > 0 && !WarnedOHO) {
WriteChatf("\ar[MQ2DPSAdv] Error: Can not use Other Hits Other: Numbers Only Hitmodes for DPS Parsing.");
if (Debug) WriteChatf("[Debug] OtherHitOther - Line: \ap%s", Line);
WarnedOHO = true;
}
return false;
}
strncpy_s(EntName, &Line[0], HitPos);
EntName[HitPos] = 0;
int DmgPos = find_substr(Line, " for ");
if (DmgPos == -1) {
return false;
}
int MobStart = HitPos + (int)strlen(OtherHits[Action]);
int MobLength = DmgPos - MobStart;
strncpy_s(MobName, &Line[MobStart], MobLength);
MobName[MobLength] = 0;
if (!_stricmp(MobName, "himself") || !_stricmp(MobName, "herself") || !_stricmp(MobName, "itself"))
strcpy_s(MobName, EntName);
return true;
}
template <unsigned int _MobSize>
bool SplitStringYouHitOther(const char* Line, char(&MobName)[_MobSize], int* Damage)
{
int Action = 0, HitPos = 0, DmgPos, MobStart, MobLength;
if (!strpbrk(Line, "1234567890"))
return false;
*Damage = GetIntFromString(strpbrk(Line, "1234567890"), 0);
while (YourHits[Action][0] != 0) {
HitPos = find_substr(Line, YourHits[Action]);
if (HitPos >= 0) break;
Action++;
}
if (!YourHits[Action][0]) {
return false;
}
if (HitPos < 0 || HitPos > 2048) {
if (*Damage > 0 && CurTarMob) {
strcpy_s(MobName, CurTarMob->Name);
if (!WarnedYHO) {
WriteChatf("\ay[MQ2DPSAdv] Warning: You Hit Other: Numbers Only may result in inaccuracy due to non-targetted attacks.");
if (Debug) WriteChatf("[Debug] Line: %s", Line);
WarnedYHO = true;
}
return true;
}
return false;
}
DmgPos = find_substr(Line, " for ");
if (DmgPos == -1) {
return false;
}
MobStart = HitPos + (int)strlen(YourHits[Action]);
MobLength = DmgPos - MobStart;
strncpy_s(MobName, &Line[MobStart], MobLength);
MobName[MobLength] = 0;
return true;
}
template <unsigned int _EntSize, unsigned int _MobSize>
bool SplitStringNonMelee(const char* Line, char(&EntName)[_EntSize], char(&MobName)[_MobSize], int* Damage)
{
if (strstr(Line, "You were hit"))
return false;
if (!strpbrk(Line, "1234567890"))
return false;
if (strstr(Line, " healed "))
return false;
*Damage = GetIntFromString(strpbrk(Line, "1234567890"), 0);
char temp[MAX_STRING] = "";
sprintf_s(temp, " for %i", *Damage);
int MobEnd = find_substr(Line, temp);
//If this was a direct damage ability [EntName] hit [MobName] for [Damage] points of [DamageType] damage.
if (MobEnd <= 0) {
if (Debug) WriteChatf("NonMelee Failed, No MobEnd - Line: %s", Line);
} else {
if ((strstr(Line, pLocalPlayer->DisplayedName) || strstr(Line, "YOUR") || strstr(Line, " is "))) {
sprintf_s(temp, pLocalPlayer->DisplayedName);
if (strstr(Line, " YOUR ") || strstr(Line, " is ")) {
//Process your damage shields.
MobEnd = find_substr(Line, " is ");
sprintf_s(temp, " is ");
strncpy_s(MobName, &Line[0], MobEnd);
}
else {
//Normal Non-Melee
strncpy_s(MobName, &Line[strlen(temp) + 5], MobEnd - strlen(temp) - 5);
}
if (strstr(Line, " is ") && !strstr(Line, " YOUR ")) {
//Process other's Damage Shields.
int EntEnd = 0;
int EntStart = 0;
if (strstr(Line, " pierced by ")) {
//Thorns DS
EntEnd = find_substr(Line, "'s thorns for ");
EntStart = find_substr(Line, " pierced by ") + 12;
strncpy_s(EntName, &Line[EntStart], EntEnd - EntStart);
}
else if (strstr(Line, " burned by ")) {
//Fire DS
EntEnd = find_substr(Line, "'s flames for ");
EntStart = find_substr(Line, " burned by ") + 11;
strncpy_s(EntName, &Line[EntStart], EntEnd - EntStart);
}
else if (strstr(Line, " tormented by ")) {
//Frost DS
EntEnd = find_substr(Line, "'s frost for ");
EntStart = find_substr(Line, " tormented by ") + 14;
strncpy_s(EntName, &Line[EntStart], EntEnd - EntStart);
}
if (EntEnd < 0 || EntStart < 0)
return false;
}
else {
strcpy_s(EntName, pLocalPlayer->DisplayedName);
}
if (!strlen(MobName) || !strlen(EntName)) {
if (Debug) WriteChatf("NonMelee Fail: %s", Line);
return false;
}
if (MobEnd > 0 && MobEnd < 256) {
MobName[MobEnd] = 0;
return true;
}
else {
return false;
}
}
sprintf_s(temp, " hit %s", MobName);
int EntEnd = find_substr(Line, temp);
if (EntEnd == -1) {
if (Debug) WriteChatf("NonMelee Fail: %s", Line);
return false;
}
strncpy_s(EntName, &Line[0], EntEnd);
EntName[EntEnd] = 0;
MobEnd = find_substr(Line, " for ");
if (MobEnd != -1) {
int MobLength = (int)(MobEnd - 5 - strlen(EntName));
strncpy_s(MobName, Line + EntEnd + 5, MobLength);
MobName[MobLength] = 0;
if (!strlen(MobName) || !strlen(EntName)) {
if (Debug) WriteChatf("NonMelee Fail: %s", Line);
return false;
}
return true;
}
}
return false;
}
template <unsigned int _MobSize>
bool SplitStringDeath(const char* Line, char(&MobName)[_MobSize])
{
int MobStart = 0, MobLength = 0;
MobLength = find_substr(Line, " died.");
if (MobLength <= 0)
MobLength = find_substr(Line, " has been slain by");
if (MobLength <= 0) {
MobStart = 15;
MobLength = (int)(strlen(Line) - 16);
}
if (MobLength <= 0)
return false;
strncpy_s(MobName, Line + MobStart, MobLength);
MobName[MobLength] = 0;
return true;
}
template <unsigned int _EntSize, unsigned int _MobSize>
bool SplitStringDOT(const char* Line, char(&EntName)[_EntSize], char(&MobName)[_MobSize], int* Damage)
{
if (!strpbrk(Line, "1234567890"))
return false;
if (strstr(Line, " healed "))
return false;
*Damage = GetIntFromString(strpbrk(Line, "1234567890"), 0);
if (*Damage <= 0 || strstr(Line, " damage by "))
return false;
int MobEnd = find_substr(Line, " has taken ");
if (strstr(Line, " damage from your ")) {
strcpy_s(EntName, pLocalPlayer->DisplayedName);
}
else {
int EntEnd = 0;
if (!strstr(Line, "Rk. I")) {
EntEnd = find_substr(Line, ".") - 6;
}
else {
EntEnd = (int)(strrchr(Line, '.') - Line) - 6;