forked from MMOBugs/MQ2Targets
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMQ2Targets.cpp
More file actions
2921 lines (2630 loc) · 89.4 KB
/
MQ2Targets.cpp
File metadata and controls
2921 lines (2630 loc) · 89.4 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
// MQ2Targets.cpp : Defines the entry point for the DLL application.
//
// PLUGIN_API is only to be used for callbacks. All existing callbacks at this time
// are shown below. Remove the ones your plugin does not use. Always use Initialize
// and Shutdown for setup and cleanup, do NOT do it in DllMain.
/* History:
1.40 12/31/06 - Initial by DrunkDwarf with htw mods
1.41 01/01/06 - Added watch debugging to debugspew for T/S (/watch debug to toggle)
1.42 01/01/06 - Fixed target load/search on plugin load, if you're already in game.
1.43 01/01/06 - Removed redundant check for guildid, preventing erasure of a guild entry in .ini if char is unguilded.
x.xx -------- - Various code over the last couple years added by htw, spawn/despawn customizations, sounds, etc.
*/
#include <mq/Plugin.h>
#include <list>
#include <vector>
#include <direct.h> // getcwd
#include <mmsystem.h> // PlaySound
#pragma comment(lib, "Winmm.lib") // PlaySound lib
#define MakeUpper(yourstring) transform (yourstring.begin(),yourstring.end(), yourstring.begin(), toupper);
//some defaults
#define NUMTARGETS 5 // display closest <x> targets to user
#define HUDXSTART 165
#define HUDYSTART 5
#define HUDYINCREMENT 12
#define FONTSIZE 2
#define HUDCOLOR 0xFFFFEA08 // yellow
#define GUILDHUDCOLOR 0xFFFF00FF // purple
#define DEADHUDCOLOR 0xFF888888 // gray
#define TARGETHUDCOLOR 0xFFFF0000 // red
#define COLORCA 0x00
#define POPUPCOLORADD 0x0E
#define CHATCOLORADD 0x009933
#define POPUPCOLORREM 0x0D
#define CHATCOLORREM 0xCC0033
#define TARGETHUDSTRING "&clr${Target.CleanName} ${Target.Level} ${Target.Class.ShortName} ${Target.Distance}&arr(${Target.HeadingTo})"
#define NOTIFYHUDSTRING "${Target.CleanName} (${Target.Level} ${Target.Class.ShortName})"
#define NOTIFYCHATSTRING "${Target.CleanName} (${Target.Level} ${Target.Class.ShortName}) ${If[${Target.Guild.NotEqual[\"NULL\"]},in ${Target.Guild},]}${If[${Target.Guild.NotEqual[\"NULL\"]},${If[${Target.GuildStatus.NotEqual[\"member\"]}, (${Target.GuildStatus}),]},]}"
#define POPUPINTERVAL 2 // interval to show up any popup text in seconds
#define SECONDINTERVAL 1 // 1 second interval
PreSetup("MQ2Targets");
PLUGIN_VERSION(3.25);
using namespace std;
enum SORTTYPE { SORT_PRIORITY = 0, SORT_DISTANCE = 1, SORT_LEVEL = 2, SORT_NAME = 3, SORT_NONE = 4 };
SORTTYPE SortType = SORT_DISTANCE;
SORTTYPE nsSortType = SORT_NONE;
enum SORTORDER { SORT_NORMAL = 0, SORT_REVERSE = 1 };
SORTORDER SortOrder = SORT_NORMAL;
SORTORDER nsSortOrder = SORT_REVERSE;
const char* SortTypeNames[] = { "priority", "distance", "level", "name", "none", "" };
const char* SortOrderNames[] = { "normal", "reverse", "" };
int ColorOption[] = { 1, 2, 4, 5, 7, 13, 14, 15, 16, 18, -1 };
const char* ColorName[] = { "gray", "green", "blue", "purple", "white", "red", "lightgreen", "yellow", "lightblue", "cyan", "" };
struct SearchStringRecord
{
std::string SearchString;
bool bNotify;
bool bHUD;
int nSound;
int nIndex;
int Priority;
};
struct NotifyRecord
{
uint32_t SpawnID;
std::string DisplayedName;
bool bNotified;
int nSound;
int Priority;
};
const char* szDirection[] = {
"-^-", //0
"<--", //1
"-->" //2
};
list<SearchStringRecord> g_SearchStrings; // list of spawns to watch for
list<NotifyRecord> g_NotifySpawns; // list of items to notify user of
struct TargetEntryInt
{
SPAWNINFO* pSpawn;
int Int;
};
struct TargetEntryFloat
{
SPAWNINFO* pSpawn;
float Float;
};
std::vector<TargetEntryFloat> g_Targets; // keeps track of targets matching search strings (spawninfo/dist)
std::vector<TargetEntryInt> g_nsTargets; // keeps track of targets matching search strings (spawninfo/dist)
size_t g_numWatchedTargets = NUMTARGETS; // how many targets to track and display. All targets
// are tracked, but only the <numWatchedTargets> closest are
// shown to the user
unsigned int g_HUDXStart = HUDXSTART;
unsigned int g_HUDYStart = HUDYSTART;
unsigned int g_HUDYIncrement = HUDYINCREMENT;
unsigned int g_HUDColor = HUDCOLOR;
unsigned int g_PopupColorAdd = POPUPCOLORADD;
unsigned int g_ChatColorAdd = CHATCOLORADD;
unsigned int g_PopupColorRem = POPUPCOLORREM;
unsigned int g_ChatColorRem = CHATCOLORREM;
bool g_UseConColor = true;
bool gVerbose = false;
unsigned int g_GuildHUDColor = GUILDHUDCOLOR;
unsigned int g_DeadHUDColor = DEADHUDCOLOR;
unsigned int g_TargetHUDColor = TARGETHUDCOLOR;
CHAR g_HUDString[MAX_STRING] = { 0 };
CHAR g_NotifyHUDString[MAX_STRING] = { 0 };
CHAR g_NotifyChatString[MAX_STRING] = { 0 };
struct NotificationsStruct {
string notifyText;
int spawnID;
};
vector<NotificationsStruct> Notifications;
bool DisplayEnabled = true;
bool DEBUGGING = false;
bool g_CheckForTargets = false; // during some times (zoning, etc) we don't want to be checking
// for targets (just a waste). This global lets us toggle this
bool g_bReadyToSearch = false;
bool g_UseMQ2Chat = true;
unsigned int g_mp3Length = 3000; // 3 seconds
unsigned int g_wavLength = 0; // entire file
bool g_useTimeStamp = false;
bool g_useChatReport = true;
bool g_useAllZone = true;
bool AlreadyShown = false;
bool bBGUpdate = true;
CHAR g_TimeStampFormat[MAX_STRING] = { 0 };
DWORD nFontSize = FONTSIZE;
bool bEQHasFocus = true;
time_t g_timerSeconds;
time_t g_timerOneSecond;
CRITICAL_SECTION g_csTargetSection;
// prototypes
// ini file reading/writing
void LoadPluginSettings();
void SavePluginSettings();
void LoadHUDString();
void LoadChatString();
// ini file targets
void ReadTargetsFromINI(const char* zone);
void DumpTargetsToINI(const char* zone);
// memory
void LoadZoneTargets();
void ClearTargets();
BOOL AddToTargetList(const char* targetName, bool bNotify, int nSound, int Priority, bool bHUD, bool bVerbose = false);
BOOL RemoveFromTargetList(const char* targetName, bool bNotify);
// command handlers
void WatchHandler(PSPAWNINFO pChar, const char* szLine);
void WatchList(const char* zone);
void WatchAdd(const char* zone, const char* targetName, int Priority, bool bNotify, int Sound, bool bHUD);
void WatchRemove(const char* zone, const char* targetName, bool bNotify = false);
void WatchTargets(const char* pTargets);
void WatchXStart(const char* pXStart);
void WatchYStart(const char* pYStart);
void WatchYIncrement(const char* pYIncrement);
void WatchFont(const char* nSize);
void WatchColor(const char* HUDType, char* HUDColor);
void WatchTime(const char* pLine);
void WatchHUD(const char* pLine);
void WatchNotifyHUD(const char* pLine);
void WatchChatHUD(const char* pLine);
void WatchSound(const char*, const char* pLine);
void WatchUsage(bool bHelp = false);
// spam to window
void WriteToChat(const char* szText, DWORD Color = USERCOLOR_DEFAULT);
BOOL InGame();
// target display
void StartSearchingForTargets();
void CheckForTargets(bool bState);
int CheckTargets();
int FindMatchingSpawns(MQSpawnSearch* pSearchSpawn, PSPAWNINFO pOrigin, bool bNotify = false, int nSound = 0, int Priority = 0, bool bHUD = true);
void CleanHUDTargets();
// sorting
static bool pMQRankCompare(const TargetEntryFloat& A, const TargetEntryFloat& B);
static bool pMQRankCompareNS(const TargetEntryInt& A, const TargetEntryInt& B);
// popup text on screen for any targets which need notifying
int AddToNotify(PSPAWNINFO pSpawn, int nSound = 0, int Priority = 0);
void RemoveFromNotify(uint32_t SpawnID, const char* DisplayedName, bool bPopup = false);
void RemoveNotifySpawns(PCHAR searchString);
void PopupNotifyTarget();
void DisplayHUDTarget(TargetEntryFloat& targInfo, DWORD X, DWORD Y, DWORD color);
// notify sound functions
void PlayNotifySound(PCHAR pFileName);
void PlayNotifySound(int nSoundID);
void StopNotifySound();
void AssignSound(PCHAR pLine);
void ListSounds();
DWORD GetColor(char* TColor, BYTE CA = 0xFF);
class MQ2TargetsType* pTargetsType = 0;
class MQ2TargetsType : public MQ2Type
{
public:
enum TargetsMembers
{
Spawn = 1,
Priority = 2,
Count = 3,
};
MQ2TargetsType() :MQ2Type("Targ")
{
TypeMember(Spawn);
TypeMember(Priority);
TypeMember(Count);
}
virtual bool GetMember(MQVarPtr VarPtr, const char* Member, char* Index, MQTypeVar& Dest) override
{
using namespace mq::datatypes;
MQTypeMember* pMember = MQ2TargetsType::FindMember(Member);
if (!pMember)
return false;
switch ((TargetsMembers)pMember->ID)
{
case Spawn:
if (Index[0]) {
if (IsNumber(Index)) {
DWORD xCount = atoi(Index) - 1;
if (xCount >= 0 && xCount < g_nsTargets.size()) {
if (Dest.Ptr = g_nsTargets[xCount].pSpawn) {
Dest.Type = pSpawnType;
return true;
}
}
}
else {
BOOL bExact = FALSE;
PCHAR pName = Index;
if (*pName == '=') {
bExact = TRUE;
pName++;
}
_strlwr_s(pName, MAX_STRING);
CHAR Temp[MAX_STRING] = { 0 };
for (unsigned long xCount = 0; xCount < g_nsTargets.size(); xCount++) {
if (bExact) {
if (g_nsTargets[xCount].pSpawn && !_stricmp(pName, g_nsTargets[xCount].pSpawn->DisplayedName)) {
Dest.Ptr = g_nsTargets[xCount].pSpawn;
Dest.Type = pSpawnType;
return true;
}
}
else {
strcpy_s(Temp, g_nsTargets[xCount].pSpawn->DisplayedName);
_strlwr_s(Temp);
if (g_nsTargets[xCount].pSpawn && strstr(Temp, pName)) {
Dest.Ptr = g_nsTargets[xCount].pSpawn;
Dest.Type = pSpawnType;
return true;
}
}
}
}
}
return false;
case Priority:
if (Index[0]) {
if (IsNumber(Index)) {
DWORD xCount = atoi(Index) - 1;
if (xCount >= 0 && xCount < g_nsTargets.size()) {
if (Dest.Ptr = g_nsTargets[xCount].pSpawn) {
Dest.Type = pIntType;
Dest.Int = g_nsTargets[xCount].Int;
return true;
}
}
}
else {
BOOL bExact = FALSE;
PCHAR pName = Index;
if (*pName == '=') {
bExact = TRUE;
pName++;
}
_strlwr_s(pName, MAX_STRING);
CHAR Temp[MAX_STRING] = { 0 };
for (unsigned long xCount = 0; xCount < g_nsTargets.size(); xCount++) {
if (bExact) {
if (g_nsTargets[xCount].pSpawn && !_stricmp(pName, g_nsTargets[xCount].pSpawn->DisplayedName)) {
Dest.Type = pIntType;
Dest.Int = g_nsTargets[xCount].Int;
return true;
}
}
else {
strcpy_s(Temp, g_nsTargets[xCount].pSpawn->DisplayedName);
_strlwr_s(Temp);
if (g_nsTargets[xCount].pSpawn && strstr(Temp, pName)) {
Dest.Type = pIntType;
Dest.Int = g_nsTargets[xCount].Int;
return true;
}
}
}
}
}
Dest.Type = pIntType;
Dest.Int = -1;
return true;
case Count:
Dest.Int = (int32_t)g_nsTargets.size();
Dest.Type = pIntType;
return true;
}
return false;
}
virtual bool ToString(MQVarPtr VarPtr, char* Destination) override
{
strcpy_s(Destination, MAX_STRING, "TRUE");
return true;
}
};
bool dataTargets(const char* szName, MQTypeVar& Dest)
{
Dest.DWord = 1;
Dest.Type = pTargetsType;
return true;
}
void DebugChat(const char* szFormat, ...)
{
if (!DEBUGGING)
return;
CHAR szOutput[MAX_STRING] = { 0 };
va_list vaList;
va_start(vaList, szFormat);
vsprintf_s(szOutput, szFormat, vaList);
WriteChatColor(szOutput);
}
// Called once, when the plugin is to initialize
PLUGIN_API void InitializePlugin()
{
char szTemp[MAX_STRING] = { 0 };
if (DEBUGGING)
DebugSpewAlways("Initializing MQ2Targets");
if (GetPrivateProfileString("Settings", "Verbose", NULL, szTemp, MAX_STRING, INIFileName)) {
if (!_stricmp(szTemp, "yes") || !_stricmp(szTemp, "on"))
gVerbose = true;
else
gVerbose = false;
}
else {
gVerbose = false;
WritePrivateProfileString("Settings", "Verbose", gVerbose ? "on" : "off", INIFileName);
}
SortType = SORT_DISTANCE;
if (GetPrivateProfileString("Settings", "HUDSortType", NULL, szTemp, MAX_STRING, INIFileName)) {
int Index = 0;
while (SortTypeNames[Index][0]) {
if (!_stricmp(szTemp, SortTypeNames[Index]))
SortType = (SORTTYPE)Index;
Index++;
}
}
else
WritePrivateProfileString("Settings", "HUDSortType", SortTypeNames[(int)SortType], INIFileName);
SortOrder = SORT_NORMAL;
if (GetPrivateProfileString("Settings", "HUDSortOrder", NULL, szTemp, MAX_STRING, INIFileName)) {
int Index = 0;
while (SortOrderNames[Index][0]) {
if (!_stricmp(szTemp, SortOrderNames[Index]))
SortOrder = (SORTORDER)Index;
Index++;
}
}
else
WritePrivateProfileString("Settings", "HUDSortOrder", SortOrderNames[(int)SortOrder], INIFileName);
nsSortType = SORT_PRIORITY;
if (GetPrivateProfileString("Settings", "SortType", NULL, szTemp, MAX_STRING, INIFileName)) {
int Index = 0;
while (SortTypeNames[Index][0]) {
if (!_stricmp(szTemp, SortTypeNames[Index]))
nsSortType = (SORTTYPE)Index;
Index++;
}
}
else
WritePrivateProfileString("Settings", "SortType", SortTypeNames[(int)nsSortType], INIFileName);
nsSortOrder = SORT_NORMAL;
if (GetPrivateProfileString("Settings", "SortOrder", NULL, szTemp, MAX_STRING, INIFileName)) {
int Index = 0;
while (SortOrderNames[Index][0]) {
if (!_stricmp(szTemp, SortOrderNames[Index]))
nsSortOrder = (SORTORDER)Index;
Index++;
}
}
else
WritePrivateProfileString("Settings", "SortOrder", SortOrderNames[(int)nsSortOrder], INIFileName);
DisplayEnabled = true;
if (gGameState == GAMESTATE_INGAME && true == g_bReadyToSearch)
{
char szINIFileName[MAX_STRING] = { 0 }, szTemp[MAX_STRING] = { 0 };
sprintf_s(szINIFileName, "%s\\%s_%s.ini", gPathConfig, GetServerShortName(), pLocalPC->Name);
if (GetPrivateProfileString(mqplugin::PluginName, "DisplayHUDElements", NULL, szTemp, MAX_STRING, szINIFileName)) {
if (!_stricmp(szTemp, "no") || !_stricmp(szTemp, "off"))
DisplayEnabled = false;
else
DisplayEnabled = true;
}
else
WritePrivateProfileString(mqplugin::PluginName, "DisplayHUDElements", DisplayEnabled ? "on" : "off", szINIFileName);
StartSearchingForTargets();
}
else
{
if (GetPrivateProfileString("Settings", "DisplayHUDElements", NULL, szTemp, MAX_STRING, INIFileName)) {
if (!_stricmp(szTemp, "no") || !_stricmp(szTemp, "off"))
DisplayEnabled = false;
else
DisplayEnabled = true;
}
else
WritePrivateProfileString("Settings", "DisplayHUDElements", DisplayEnabled ? "on" : "off", INIFileName);
}
Notifications.clear();
InitializeCriticalSection(&g_csTargetSection);
StopNotifySound();
CheckForTargets(false);
LoadPluginSettings();
if (gGameState == GAMESTATE_INGAME)
{
StartSearchingForTargets();
}
AddCommand("/watch", WatchHandler);
AddMQ2Data("Targ", dataTargets);
pTargetsType = new MQ2TargetsType;
}
// Called once, when the plugin is to shutdown
PLUGIN_API void ShutdownPlugin()
{
if (DEBUGGING)
DebugSpewAlways("Shutting down MQ2Targets");
AlreadyShown = true;
SavePluginSettings();
CleanHUDTargets();
EnterCriticalSection(&g_csTargetSection);
DeleteCriticalSection(&g_csTargetSection);
StopNotifySound();
RemoveCommand("/watch");
RemoveMQ2Data("Targ");
delete pTargetsType;
}
PLUGIN_API void OnBeginZone()
{
if (DEBUGGING)
DebugSpewAlways("MQ2Targets::OnBeginZone()");
Notifications.clear();
g_bReadyToSearch = false;
// get rid of current items on the HUD
CleanHUDTargets();
CheckForTargets(false);
}
PLUGIN_API void OnEndZone()
{
g_bReadyToSearch = true;
}
// Called every frame that the "HUD" is drawn -- e.g. net status / packet loss bar
PLUGIN_API void OnDrawHUD()
{
if (!InGame())
return;
int i = 0;
if (!pLocalPC)
return;
PSPAWNINFO me = pLocalPlayer;
if (!me)
return;
// do this at least once a second, even without spawns adding or removing
if (time(NULL) > (g_timerOneSecond + SECONDINTERVAL))
{
CleanHUDTargets();
CheckTargets();
g_timerOneSecond = time(NULL);
}
size_t nFound = g_Targets.size();
for (size_t N = 0; N < nFound; N++)
{
PSPAWNINFO theTarget = g_Targets[N].pSpawn;
if (theTarget) {
if (SortType == SORT_LEVEL)
g_Targets[N].Float = (float)theTarget->Level;
else if (SortType == SORT_DISTANCE)
g_Targets[N].Float = GetDistance(me, theTarget);
else if (SortType == SORT_PRIORITY) {
int lPriority = 0;
for (size_t X = 0; X < g_nsTargets.size(); X++)
{
if (!g_nsTargets[X].pSpawn)
continue;
if (g_nsTargets[X].pSpawn->SpawnID == theTarget->SpawnID)
lPriority = g_nsTargets[X].Int;
}
g_Targets[N].Float = (float)lPriority;
}
else
g_Targets[N].Float = 0.0;
}
}
if (SortOrder != SORT_NONE && !g_Targets.empty())
std::sort(g_Targets.begin(), g_Targets.end(), pMQRankCompare);
if (nsSortOrder != SORT_NONE && !g_nsTargets.empty())
std::sort(g_nsTargets.begin(), g_nsTargets.end(), pMQRankCompareNS);
// now draw the targets until the desired number is found
if (DisplayEnabled)
{
if (nFound > 0)
{
CHAR szHUD[MAX_STRING] = { 0 };
for (size_t N = 0; N < std::min(nFound, g_numWatchedTargets) && N < g_Targets.size(); N++)
{
PSPAWNINFO theTarget = g_Targets[N].pSpawn;
if (theTarget)
{
DWORD SX = 0;
DWORD SY = 0;
if (pScreenX && pScreenY)
{
SX = ScreenX;
SY = ScreenY;
}
// where on the screen to show the targets
DWORD X, Y;
X = SX + g_HUDXStart;
Y = SX + (g_HUDYStart + (g_HUDYIncrement * i++));
unsigned int color = g_HUDColor;
if (g_UseConColor)
{
if (theTarget && theTarget->SpawnID)
{
PSPAWNINFO pLocalSpawn = GetSpawnByID(theTarget->SpawnID);
if (pLocalSpawn)
{
color = ConColorToARGB(ConColor(pLocalSpawn));
}
}
}
DisplayHUDTarget(g_Targets[N], X, Y, color);
}
}
}
}
// if at least n seconds have elapsed since the last timer, do the next pending popup
if (time(NULL) > (g_timerSeconds + POPUPINTERVAL))
{
// reset "timer"
g_timerSeconds = time(NULL);
PopupNotifyTarget();
}
}
void DisplayHUDTarget(TargetEntryFloat& targInfo, DWORD X, DWORD Y, DWORD color)
{
static int NSkip = 0;
if (!InGame())
return;
if (++NSkip > 10) {
NSkip = 0;
if (!bBGUpdate && !gbInForeground)
bEQHasFocus = false;
else
bEQHasFocus = true;
}
if (!bEQHasFocus) return;
PSPAWNINFO theTarget = targInfo.pSpawn;
if (theTarget)
{
char outText[MAX_STRING];
string result = g_HUDString;
// figure out heading
float HeadingTo = (float)(atan2f(pLocalPlayer->Y - theTarget->Y, theTarget->X - pLocalPlayer->X) * 180.0f / PI + 90.0f);
if (HeadingTo < 0.0f)
HeadingTo += 360.0f;
else if (HeadingTo >= 360.0f)
HeadingTo -= 360.0f;
// replace &arr with direction arrow
if (find_substr(result, "&arr") != -1)
{
float MyHeading = pLocalPlayer->Heading * 0.703125f;
int arrow;
if (((((int)MyHeading - (int)HeadingTo) + 375) % 360) < 30)
{
arrow = 0; // straight ahead (+-30degrees)
}
else if (((((int)MyHeading - (int)HeadingTo) + 360) % 360) < 180)
{
arrow = 2; // to the left
}
else
arrow = 1;
result = replace(result, "&arr", szDirection[arrow]);
}
// replace &dst with distance
if (find_substr(result, "&dst") != -1)
{
CHAR szDist[MAX_STRING] = { 0 };
if (pLocalPlayer->Z - theTarget->Z > 10)
{
sprintf_s(szDist, "-%.1f", targInfo.Float);
}
else if (theTarget->Z - pLocalPlayer->Z > 10)
{
sprintf_s(szDist, "+%.1f", targInfo.Float);
}
else
sprintf_s(szDist, "%.1f", targInfo.Float);
result = replace(result, "&dst", szDist);
}
// replace &clr with target indicators if targeted, also use target colors if &high is found
bool bTarget = false;
bool bHighLight = false;
if (find_substr(result, "&clr") != -1)
{
// color of the HUD display
// Yellow
// ARGBCOLOR Color;
// Color.A = 0xFF;
// Color.R = 255;
// Color.G = 234;
// Color.B = 8;
// if we want to highlight/color stuff
bHighLight = true;
// highlight targeted spawn
CHAR szBrackets[MAX_STRING] = { 0 };
if (pTarget && pTarget->SpawnID == theTarget->SpawnID)
{
strcpy_s(szBrackets, ">>");
bTarget = true;
}
result = replace(result, "&clr", szBrackets);
}
if (true == bHighLight)
{
if (pLocalPlayer->GuildID != -1 && theTarget->GuildID == pLocalPlayer->GuildID)
color = g_GuildHUDColor;
if (true == bTarget)
{
color = g_TargetHUDColor; // red
X -= 12;
}
if (theTarget->StandState == STANDSTATE_DEAD)
color = g_DeadHUDColor;
}
// replace "${Target." with "${Spawn[<spawnid>]."
CHAR szSpawnID[20] = { 0 };
sprintf_s(szSpawnID, "${Spawn[%d].", theTarget->SpawnID);
if (find_substr(result, "${Target.") != -1)
{
result = replace(result, "${Target.", szSpawnID);
}
// now parse like MQ2HUD ini string
strcpy_s(outText, result.c_str());
ParseMacroParameter(outText);
if (outText[0] && strcmp(outText, "NULL"))
{
DrawHUDText(outText, X, Y, color, nFontSize);
}
}
}
// Called once directly after initialization, and then every time the gamestate changes
PLUGIN_API void SetGameState(DWORD GameState)
{
if (DEBUGGING)
DebugSpewAlways("MQ2Targets::SetGameState (%d)", GameState);
if (GameState == GAMESTATE_INGAME && true == g_bReadyToSearch)
{
char szINIFileName[MAX_STRING] = { 0 }, szTemp[MAX_STRING] = { 0 };
sprintf_s(szINIFileName, "%s\\%s_%s.ini", gPathConfig, GetServerShortName(), pLocalPC->Name);
DisplayEnabled = true;
if (GetPrivateProfileString(mqplugin::PluginName, "DisplayHUDElements", NULL, szTemp, MAX_STRING, szINIFileName)) {
if (!_stricmp(szTemp, "no") || !_stricmp(szTemp, "off"))
DisplayEnabled = false;
else
DisplayEnabled = true;
}
else
WritePrivateProfileString(mqplugin::PluginName, "DisplayHUDElements", DisplayEnabled ? "on" : "off", szINIFileName);
StartSearchingForTargets();
}
}
// This is called every time WriteChatColor is called by MQ2Main or any plugin,
// IGNORING FILTERS, IF YOU NEED THEM MAKE SURE TO IMPLEMENT THEM. IF YOU DONT
// CALL CEverQuest::dsp_chat MAKE SURE TO IMPLEMENT EVENTS HERE (for chat plugins)
PLUGIN_API DWORD OnWriteChatColor(PCHAR Line, DWORD Color, DWORD Filter)
{
if (_stricmp(Line, "plugin 'MQ2targets' Loaded.") == 0)
{
//if (DEBUGGING)
//DebugSpewAlways("MQ2Targets::OnWriteChatColor(%s)", Line);
g_bReadyToSearch = true;
// use that function to simulate starting the game
SetGameState(GAMESTATE_INGAME);
}
return 0;
}
// This is called each time a spawn is added to a zone (inserted into EQ's list of spawns),
// or for each existing spawn when a plugin first initializes
// NOTE: When you zone, these will come BEFORE OnZoned
PLUGIN_API void OnAddSpawn(PSPAWNINFO pNewSpawn)
{
if (gGameState == GAMESTATE_INGAME && true == g_bReadyToSearch && pNewSpawn && pNewSpawn->SpawnID > 0 && pNewSpawn->DisplayedName && strlen(pNewSpawn->DisplayedName) > 0)
{
if (DEBUGGING)
DebugSpewAlways("MQ2Targets::OnAddSpawn(%s)", pNewSpawn->DisplayedName);
CleanHUDTargets();
CheckTargets();
}
}
// This is called each time a spawn is removed from a zone (removed from EQ's list of spawns).
// It is NOT called for each existing spawn when a plugin shuts down.
PLUGIN_API void OnRemoveSpawn(PSPAWNINFO pSpawn)
{
if (gGameState == GAMESTATE_INGAME && true == g_bReadyToSearch && pSpawn && pSpawn->SpawnID > 0 && pSpawn->DisplayedName && strlen(pSpawn->DisplayedName) > 0)
{
if (DEBUGGING)
DebugSpewAlways("MQ2Targets::OnRemoveSpawn(%s)", pSpawn->DisplayedName);
CleanHUDTargets();
CheckTargets();
// if it's in the notify list, update its text
if (pSpawn) {
RemoveFromNotify(pSpawn->SpawnID, pSpawn->DisplayedName, true);
}
}
}
// overall settings for Plugin
void LoadPluginSettings()
{
char szTemp[MAX_STRING] = { 0 }, szDefault[MAX_STRING] = { 0 };
ARGBCOLOR RGB;
if (DEBUGGING)
DebugSpewAlways("MQ2Targets::LoadPluginSettings()");
g_numWatchedTargets = GetPrivateProfileInt("Settings", "NumDisplayed", NUMTARGETS, INIFileName);
nFontSize = GetPrivateProfileInt("Settings", "HUDFontSize", FONTSIZE, INIFileName);
g_HUDXStart = GetPrivateProfileInt("Settings", "HUDXStart", HUDXSTART, INIFileName);
g_HUDYStart = GetPrivateProfileInt("Settings", "HUDYStart", HUDYSTART, INIFileName);
g_HUDYIncrement = GetPrivateProfileInt("Settings", "HUDYIncrement", HUDYINCREMENT, INIFileName);
sprintf_s(szDefault, "%08X", HUDCOLOR);
GetPrivateProfileString("Settings", "HUDColor", szDefault, szTemp, MAX_STRING, INIFileName);
if (strlen(szTemp) > 6) {
g_HUDColor = GetPrivateProfileInt("Settings", "HUDColor", HUDCOLOR, INIFileName);
RGB.ARGB = g_HUDColor;
sprintf_s(szTemp, "%02X%02X%02X", RGB.R, RGB.G, RGB.B);
WritePrivateProfileString("Settings", "HUDColor", szTemp, INIFileName);
}
GetPrivateProfileString("Settings", "HUDColor", szDefault, szTemp, MAX_STRING, INIFileName);
g_HUDColor = GetColor(szTemp);
sprintf_s(szDefault, "%08X", GUILDHUDCOLOR);
GetPrivateProfileString("Settings", "GuildHUDColor", szDefault, szTemp, MAX_STRING, INIFileName);
if (strlen(szTemp) > 6) {
g_GuildHUDColor = GetPrivateProfileInt("Settings", "GuildHUDColor", GUILDHUDCOLOR, INIFileName);
RGB.ARGB = g_GuildHUDColor;
sprintf_s(szTemp, "%02X%02X%02X", RGB.R, RGB.G, RGB.B);
WritePrivateProfileString("Settings", "GuildHUDColor", szTemp, INIFileName);
}
GetPrivateProfileString("Settings", "GuildHUDColor", szDefault, szTemp, MAX_STRING, INIFileName);
g_GuildHUDColor = GetColor(szTemp);
sprintf_s(szDefault, "%08X", DEADHUDCOLOR);
GetPrivateProfileString("Settings", "DeadHUDColor", szDefault, szTemp, MAX_STRING, INIFileName);
if (strlen(szTemp) > 6) {
g_DeadHUDColor = GetPrivateProfileInt("Settings", "DeadHUDColor", DEADHUDCOLOR, INIFileName);
RGB.ARGB = g_DeadHUDColor;
sprintf_s(szTemp, "%02X%02X%02X", RGB.R, RGB.G, RGB.B);
WritePrivateProfileString("Settings", "DeadHUDColor", szTemp, INIFileName);
}
GetPrivateProfileString("Settings", "DeadHUDColor", szDefault, szTemp, MAX_STRING, INIFileName);
g_DeadHUDColor = GetColor(szTemp);
sprintf_s(szDefault, "%08X", TARGETHUDCOLOR);
GetPrivateProfileString("Settings", "TargetHUDColor", szDefault, szTemp, MAX_STRING, INIFileName);
if (strlen(szTemp) > 6) {
g_TargetHUDColor = GetPrivateProfileInt("Settings", "TargetHUDColor", TARGETHUDCOLOR, INIFileName);
RGB.ARGB = g_TargetHUDColor;
sprintf_s(szTemp, "%02X%02X%02X", RGB.R, RGB.G, RGB.B);
WritePrivateProfileString("Settings", "TargetHUDColor", szTemp, INIFileName);
}
GetPrivateProfileString("Settings", "TargetHUDColor", szDefault, szTemp, MAX_STRING, INIFileName);
g_TargetHUDColor = GetColor(szTemp);
int x;
char szColor[MAX_STRING] = { 0 };
strcpy_s(szColor, "lightgreen");
for (x = 0; ColorOption[x] > -1; x++)
if (ColorOption[x] == POPUPCOLORADD)
strcpy_s(szColor, ColorName[x]);
GetPrivateProfileString("Settings", "PopupColorAdd", szColor, szTemp, MAX_STRING, INIFileName);
for (x = 0; ColorOption[x] > -1; x++)
if (!_stricmp(szTemp, ColorName[x])) {
strcpy_s(szColor, ColorName[x]);
g_PopupColorAdd = ColorOption[x];
}
WritePrivateProfileString("Settings", "PopupColorAdd", szColor, INIFileName);
strcpy_s(szColor, "red");
for (x = 0; ColorOption[x] > -1; x++)
if (ColorOption[x] == POPUPCOLORREM)
strcpy_s(szColor, ColorName[x]);
GetPrivateProfileString("Settings", "PopupColorRem", szColor, szTemp, MAX_STRING, INIFileName);
for (x = 0; ColorOption[x] > -1; x++)
if (!_stricmp(szTemp, ColorName[x])) {
strcpy_s(szColor, ColorName[x]);
g_PopupColorRem = ColorOption[x];
}
WritePrivateProfileString("Settings", "PopupColorRem", szColor, INIFileName);
sprintf_s(szDefault, "%08X", CHATCOLORADD);
GetPrivateProfileString("Settings", "ChatColorAdd", szDefault, szTemp, MAX_STRING, INIFileName);
if (strlen(szTemp) > 6) {
g_ChatColorAdd = GetPrivateProfileInt("Settings", "ChatColorAdd", CHATCOLORADD, INIFileName);
RGB.ARGB = g_ChatColorAdd;
sprintf_s(szTemp, "%02X%02X%02X", RGB.R, RGB.G, RGB.B);
WritePrivateProfileString("Settings", "ChatColorAdd", szTemp, INIFileName);
}
GetPrivateProfileString("Settings", "ChatColorAdd", szDefault, szTemp, MAX_STRING, INIFileName);
g_ChatColorAdd = GetColor(szTemp, COLORCA);
sprintf_s(szDefault, "%08X", CHATCOLORREM);
GetPrivateProfileString("Settings", "ChatColorRem", szDefault, szTemp, MAX_STRING, INIFileName);
if (strlen(szTemp) > 6) {
g_ChatColorRem = GetPrivateProfileInt("Settings", "ChatColorRem", CHATCOLORREM, INIFileName);
RGB.ARGB = g_ChatColorRem;
sprintf_s(szTemp, "%02X%02X%02X", RGB.R, RGB.G, RGB.B);
WritePrivateProfileString("Settings", "ChatColorRem", szTemp, INIFileName);
}
GetPrivateProfileString("Settings", "ChatColorRem", szDefault, szTemp, MAX_STRING, INIFileName);
g_ChatColorRem = GetColor(szTemp, COLORCA);
GetPrivateProfileString("Settings", "UseConColor", "on", szTemp, MAX_STRING, INIFileName);
g_UseConColor = (!_strnicmp(szTemp, "1", 1) || !_strnicmp(szTemp, "on", 2) || !_strnicmp(szTemp, "yes", 3)) ? true : false;
GetPrivateProfileString("Settings", "UseMQ2Chat", "on", szTemp, MAX_STRING, INIFileName);
g_UseMQ2Chat = (!_strnicmp(szTemp, "1", 1) || !_strnicmp(szTemp, "on", 2) || !_strnicmp(szTemp, "yes", 3)) ? true : false;
GetPrivateProfileString("Settings", "UpdateInBackground", "on", szTemp, MAX_STRING, INIFileName);
bBGUpdate = (!_strnicmp(szTemp, "1", 1) || !_strnicmp(szTemp, "on", 2) || !_strnicmp(szTemp, "yes", 3)) ? true : false;
GetPrivateProfileString("Settings", "UseTimeStamp", "on", szTemp, MAX_STRING, INIFileName);
g_useTimeStamp = (!_strnicmp(szTemp, "1", 1) || !_strnicmp(szTemp, "on", 2) || !_strnicmp(szTemp, "yes", 3)) ? true : false;
GetPrivateProfileString("Settings", "UseChatReport", "on", szTemp, MAX_STRING, INIFileName);
g_useChatReport = (!_strnicmp(szTemp, "1", 1) || !_strnicmp(szTemp, "on", 2) || !_strnicmp(szTemp, "yes", 3)) ? true : false;
GetPrivateProfileString("Settings", "UseAllZone", "on", szTemp, MAX_STRING, INIFileName);
g_useAllZone = (!_strnicmp(szTemp, "1", 1) || !_strnicmp(szTemp, "on", 2) || !_strnicmp(szTemp, "yes", 3)) ? true : false;
g_mp3Length = GetPrivateProfileInt("Settings", "MP3Length", 3000, INIFileName);
g_wavLength = GetPrivateProfileInt("Settings", "WavLength", 0, INIFileName);
GetPrivateProfileString("Settings", "TimeStampFormat", "[%H:%M:%S]", g_TimeStampFormat, MAX_STRING, INIFileName);
LoadHUDString();
LoadChatString();
}
void SavePluginSettings()
{
ARGBCOLOR Color;
if (DEBUGGING)
DebugSpewAlways("MQ2Targets::SavePluginSettings()");
CHAR szTemp[MAX_STRING] = { 0 };
// save Number of Targets to display
WritePrivateProfileInt("Settings", "NumDisplayed", (int)g_numWatchedTargets, INIFileName);
sprintf_s(szTemp, "%u", nFontSize);
WritePrivateProfileString("Settings", "HUDFontSize", szTemp, INIFileName);
sprintf_s(szTemp, "%d", g_HUDXStart);
WritePrivateProfileString("Settings", "HUDXStart", szTemp, INIFileName);
sprintf_s(szTemp, "%d", g_HUDYStart);
WritePrivateProfileString("Settings", "HUDYStart", szTemp, INIFileName);
sprintf_s(szTemp, "%d", g_HUDYIncrement);
WritePrivateProfileString("Settings", "HUDYIncrement", szTemp, INIFileName);
Color.ARGB = g_HUDColor;
sprintf_s(szTemp, "%02X%02X%02X", Color.R, Color.G, Color.B);
WritePrivateProfileString("Settings", "HUDColor", szTemp, INIFileName);
Color.ARGB = g_GuildHUDColor;
sprintf_s(szTemp, "%02X%02X%02X", Color.R, Color.G, Color.B);
WritePrivateProfileString("Settings", "GuildHUDColor", szTemp, INIFileName);
Color.ARGB = g_DeadHUDColor;
sprintf_s(szTemp, "%02X%02X%02X", Color.R, Color.G, Color.B);
WritePrivateProfileString("Settings", "DeadHUDColor", szTemp, INIFileName);
Color.ARGB = g_TargetHUDColor;
sprintf_s(szTemp, "%02X%02X%02X", Color.R, Color.G, Color.B);
WritePrivateProfileString("Settings", "TargetHUDColor", szTemp, INIFileName);
WritePrivateProfileString("Settings", "UseConColor", g_UseConColor ? "on" : "off", INIFileName);
WritePrivateProfileString("Settings", "HUDString", g_HUDString, INIFileName);
WritePrivateProfileString("Settings", "NotifyHUDString", g_NotifyHUDString, INIFileName);
WritePrivateProfileString("Settings", "NotifyChatString", g_NotifyChatString, INIFileName);
WritePrivateProfileString("Settings", "UseMQ2Chat", g_UseMQ2Chat ? "on" : "off", INIFileName);
WritePrivateProfileString("Settings", "UpdateInBackground", bBGUpdate ? "on" : "off", INIFileName);
WritePrivateProfileInt("Settings", "MP3Length", g_mp3Length, INIFileName);
WritePrivateProfileInt("Settings", "WavLength", g_wavLength, INIFileName);
WritePrivateProfileString("Settings", "UseTimeStamp", g_useTimeStamp ? "on" : "off", INIFileName);
WritePrivateProfileString("Settings", "TimeStampFormat", g_TimeStampFormat, INIFileName);
WritePrivateProfileString("Settings", "UseChatReport", g_useChatReport ? "on" : "off", INIFileName);
WritePrivateProfileString("Settings", "UseAllZone", g_useAllZone ? "on" : "off", INIFileName);
char szColor[MAX_STRING] = { 0 };
int x;
strcpy_s(szColor, "lightgreen");
for (x = 0; ColorOption[x] > -1; x++)
if (ColorOption[x] == g_PopupColorAdd)