forked from RedGuides/MQ2AutoSize
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMQ2AutoSize.cpp
1591 lines (1484 loc) · 47.7 KB
/
MQ2AutoSize.cpp
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
// MQ2AutoSize.cpp : Resize spawns by distance (client only)
#include <mq/Plugin.h>
#include <chrono>
// Plugin Setup
PreSetup("MQ2AutoSize");
PLUGIN_VERSION(1.2);
// Constants
constexpr std::chrono::milliseconds UPDATE_INTERVAL{ 200 }; // Controls the update frequency to perform a radius-based resize
constexpr int MIN_SIZE = 1; // Minimum size value
constexpr int MAX_SIZE = 250; // Maximum size value
constexpr int FAR_CLIP_PLANE = 1000; // Placeholder for EQ Far Clip Plane value
constexpr float OTHER_SIZE = 1.0f; // Default size for other entities
constexpr float ZERO_SIZE = 0.0f; // Size representing zero
// Variables
std::chrono::steady_clock::time_point lastUpdate; // Skip pulse counter
int previousRangeDistance = 0; // Previous range distance
bool loadedDannet = false; // State of DanNet plugin
bool loadedEQBC = false; // State of EQBC plugin
// Function Declarations
static void SpawnListResize(bool bReset); // Function to resize the spawn list
static void ChooseInstructionPlugin(); // Function to choose the instruction plugin
static void Emulate(std::string_view type); // Function to emulate certain behavior (zonewide vs range)
static void DrawAutoSize_MQSettingsPanel(); // Function to draw the MQ settings panel
static void SendGroupCommand(std::string_view who); // Function to send a command to a group
static int RoundToNearestTen(int value); // Function to round a value to the nearest ten
static bool IsInGroup(); // Function to check if in a group
static bool IsInRaid(); // Function to check if in a raid
void SaveINI(const std::string& param, const bool squelch); // Function to save INI values to disk
enum class eCommunicationMode
{
None = 0,
DanNet = 1,
EQBC = 2,
Default = None,
};
eCommunicationMode selectedComms = eCommunicationMode::Default;
enum class eResizeMode
{
None = 0,
Zonewide = 1,
Range = 2,
Default = Range,
};
eResizeMode ResizeMode = eResizeMode::Default;
// our configuration
struct COurSizes
{
bool Enabled = true;
bool OptAutoSave = false;
bool OptPC = true;
bool OptNPC = false;
bool OptPet = false;
bool OptMerc = false;
bool OptMount = false;
bool OptCorpse = false;
bool OptSelf = false;
int ResizeRange = 50;
int SizePC = 1;
int SizeNPC = 1;
int SizePet = 1;
int SizeMerc = 1;
int SizeMount = 1;
int SizeCorpse = 1;
int SizeSelf = 1;
};
COurSizes AS_Config;
// exposed TLO variables
class MQ2AutoSizeType : public MQ2Type
{
public:
enum class AutoSizeMembers
{
Enabled,
Active,
AutoSave,
ResizePC,
ResizeNPC,
ResizePets,
ResizeMercs,
ResizeMounts,
ResizeCorpse,
ResizeSelf,
Range,
SizePC,
SizeNPC,
SizePets,
SizeMercs,
SizeMounts,
SizeCorpse,
SizeSelf
};
MQ2AutoSizeType() : MQ2Type("AutoSize")
{
ScopedTypeMember(AutoSizeMembers, Enabled);
ScopedTypeMember(AutoSizeMembers, Active);
ScopedTypeMember(AutoSizeMembers, AutoSave);
ScopedTypeMember(AutoSizeMembers, ResizePC);
ScopedTypeMember(AutoSizeMembers, ResizeNPC);
ScopedTypeMember(AutoSizeMembers, ResizePets);
ScopedTypeMember(AutoSizeMembers, ResizeMercs);
ScopedTypeMember(AutoSizeMembers, ResizeMounts);
ScopedTypeMember(AutoSizeMembers, ResizeCorpse);
ScopedTypeMember(AutoSizeMembers, ResizeSelf);
ScopedTypeMember(AutoSizeMembers, Range);
ScopedTypeMember(AutoSizeMembers, SizePC);
ScopedTypeMember(AutoSizeMembers, SizeNPC);
ScopedTypeMember(AutoSizeMembers, SizePets);
ScopedTypeMember(AutoSizeMembers, SizeMercs);
ScopedTypeMember(AutoSizeMembers, SizeMounts);
ScopedTypeMember(AutoSizeMembers, SizeCorpse);
ScopedTypeMember(AutoSizeMembers, SizeSelf);
}
bool GetMember(MQVarPtr VarPtr, const char* Member, char* Index, MQTypeVar& Dest) override
{
MQTypeMember* pMember = MQ2AutoSizeType::FindMember(Member);
if (!pMember)
return false;
switch (static_cast<AutoSizeMembers>(pMember->ID))
{
case AutoSizeMembers::Enabled:
Dest.Int = AS_Config.Enabled;
Dest.Type = datatypes::pBoolType;
return true;
case AutoSizeMembers::Active:
Dest.Int = AS_Config.OptPC || AS_Config.OptNPC || AS_Config.OptPet || AS_Config.OptMerc || AS_Config.OptMount || AS_Config.OptCorpse || AS_Config.OptSelf;
Dest.Type = datatypes::pBoolType;
return true;
case AutoSizeMembers::AutoSave:
Dest.Int = AS_Config.OptAutoSave;
Dest.Type = datatypes::pBoolType;
return true;
case AutoSizeMembers::ResizePC:
Dest.Int = AS_Config.OptPC;
Dest.Type = datatypes::pBoolType;
return true;
case AutoSizeMembers::ResizeNPC:
Dest.Int = AS_Config.OptNPC;
Dest.Type = datatypes::pBoolType;
return true;
case AutoSizeMembers::ResizePets:
Dest.Int = AS_Config.OptPet;
Dest.Type = datatypes::pBoolType;
return true;
case AutoSizeMembers::ResizeMercs:
Dest.Int = AS_Config.OptMerc;
Dest.Type = datatypes::pBoolType;
return true;
case AutoSizeMembers::ResizeMounts:
Dest.Int = AS_Config.OptMount;
Dest.Type = datatypes::pBoolType;
return true;
case AutoSizeMembers::ResizeCorpse:
Dest.Int = AS_Config.OptCorpse;
Dest.Type = datatypes::pBoolType;
return true;
case AutoSizeMembers::ResizeSelf:
Dest.Int = AS_Config.OptSelf;
Dest.Type = datatypes::pBoolType;
return true;
case AutoSizeMembers::Range:
Dest.Int = AS_Config.ResizeRange;
Dest.Type = datatypes::pIntType;
return true;
case AutoSizeMembers::SizePC:
Dest.Int = AS_Config.SizePC;
Dest.Type = datatypes::pIntType;
return true;
case AutoSizeMembers::SizeNPC:
Dest.Int = AS_Config.SizeNPC;
Dest.Type = datatypes::pIntType;
return true;
case AutoSizeMembers::SizePets:
Dest.Int = AS_Config.SizePet;
Dest.Type = datatypes::pIntType;
return true;
case AutoSizeMembers::SizeMercs:
Dest.Int = AS_Config.SizeMerc;
Dest.Type = datatypes::pIntType;
return true;
case AutoSizeMembers::SizeMounts:
Dest.Int = AS_Config.SizeMount;
Dest.Type = datatypes::pIntType;
return true;
case AutoSizeMembers::SizeCorpse:
Dest.Int = AS_Config.SizeCorpse;
Dest.Type = datatypes::pIntType;
return true;
case AutoSizeMembers::SizeSelf:
Dest.Int = AS_Config.SizeSelf;
Dest.Type = datatypes::pIntType;
return true;
}
return false;
}
};
MQ2AutoSizeType* pAutoSizeType = nullptr;
bool dataAutoSize(const char*, MQTypeVar& ret)
{
ret.DWord = 1;
ret.Type = pAutoSizeType;
return true;
}
// class to access the ChangeHeight function
class PlayerZoneClient_Hook
{
public:
DETOUR_TRAMPOLINE_DEF(void, ChangeHeight_Trampoline, (float, float, float, bool))
void ChangeHeight_Detour(float newHeight, float cameraPos, float speedScale, bool unused)
{
ChangeHeight_Trampoline(newHeight, cameraPos, speedScale, unused);
}
// this assures valid function call
void ChangeHeight_Wrapper(float fNewSize)
{
float fView = OTHER_SIZE;
PlayerClient* pSpawn = reinterpret_cast<PlayerClient*>(this);
if (pSpawn->SpawnID == pLocalPlayer->SpawnID)
{
fView = ZERO_SIZE;
}
ChangeHeight_Trampoline(fNewSize, fView, 1.0f, false);
}
};
/**
* This function reads an integer value from a specified section and key in an INI file.
* It then clamps the value to ensure it falls within the specified minimum and maximum size range.
* If the pulled value is lower than MIN_SIZE then it will be set to MIN_SIZE value
* If the pulled value is larger than MAX_SIZE then it will be set to MAX_SIZE value
*
* @param section The section in the INI file to read from.
* @param key The key in the section to read the value of.
* @param defaultValue The default value to use if the key is not found or the value is invalid.
* @return An integer representing the size value, clamped to be within the range of MIN_SIZE and MAX_SIZE.
*/
static int getSaneSize(const char* section, const char* key, int defaultValue)
{
int size = GetPrivateProfileInt(section, key, defaultValue, INIFileName);
return std::clamp(size, MIN_SIZE, MAX_SIZE);
}
void LoadINI()
{
AS_Config.OptAutoSave = GetPrivateProfileBool("Config", "AutoSave", true, INIFileName);
AS_Config.OptPC = GetPrivateProfileBool("Config", "ResizePC", false, INIFileName);
AS_Config.OptNPC = GetPrivateProfileBool("Config", "ResizeNPC", false, INIFileName);
AS_Config.OptPet = GetPrivateProfileBool("Config", "ResizePets", false, INIFileName);
AS_Config.OptMerc = GetPrivateProfileBool("Config", "ResizeMercs", false, INIFileName);
AS_Config.OptMount = GetPrivateProfileBool("Config", "ResizeMounts", false, INIFileName);
AS_Config.OptCorpse = GetPrivateProfileBool("Config", "ResizeCorpse", false, INIFileName);
AS_Config.OptSelf = GetPrivateProfileBool("Config", "ResizeSelf", false, INIFileName);
AS_Config.ResizeRange = getSaneSize("Config", "Range", AS_Config.ResizeRange);
AS_Config.SizePC = getSaneSize("Config", "SizePC", MIN_SIZE);
AS_Config.SizeNPC = getSaneSize("Config", "SizeNPC", MIN_SIZE);
AS_Config.SizePet = getSaneSize("Config", "SizePets", MIN_SIZE);
AS_Config.SizeMerc = getSaneSize("Config", "SizeMercs", MIN_SIZE);
AS_Config.SizeMount = getSaneSize("Config", "SizeMounts", MIN_SIZE);
AS_Config.SizeCorpse = getSaneSize("Config", "SizeCorpse", MIN_SIZE);
AS_Config.SizeSelf = getSaneSize("Config", "SizeSelf", MIN_SIZE);
WriteChatf("\ay%s\aw:: Configuration file loaded.", mqplugin::PluginName);
// apply new settings from INI read
if (GetGameState() == GAMESTATE_INGAME && pLocalPlayer)
{
SpawnListResize(false);
}
}
// provide an INI key parameter to save only that key, or leave it null to save all keys
// enable squelch to suppress output to the client
void SaveINI(const std::string& param = "", const bool squelch = false)
{
// Map to store configuration key-value pairs
std::vector<std::pair<std::string, std::string>> configMap =
{
{"AutoSave", AS_Config.OptAutoSave ? "on" : "off"},
{"ResizePC", AS_Config.OptPC ? "on" : "off"},
{"ResizeNPC", AS_Config.OptNPC ? "on" : "off"},
{"ResizePets", AS_Config.OptPet ? "on" : "off"},
{"ResizeMercs", AS_Config.OptMerc ? "on" : "off"},
{"ResizeMounts", AS_Config.OptMount ? "on" : "off"},
{"ResizeCorpse", AS_Config.OptCorpse ? "on" : "off"},
{"ResizeSelf", AS_Config.OptSelf ? "on" : "off"},
{"SizePC", std::to_string(AS_Config.SizePC)},
{"SizeNPC", std::to_string(AS_Config.SizeNPC)},
{"SizePets", std::to_string(AS_Config.SizePet)},
{"SizeMercs", std::to_string(AS_Config.SizeMerc)},
{"SizeMounts", std::to_string(AS_Config.SizeMount)},
{"SizeCorpse", std::to_string(AS_Config.SizeCorpse)},
{"SizeSelf", std::to_string(AS_Config.SizeSelf)}
};
// this writes a specific key to disk with its value
if (!param.empty())
{
auto it = std::find_if(configMap.begin(), configMap.end(), [&](const auto& p) { return p.first == param; });
if (it != configMap.end())
{
WritePrivateProfileString("Config", it->first, it->second, INIFileName);
}
// special handling for Range key, we don't want to write the value to disk unless
// it's between MIN_SIZE and MAX_SIZE
else if (param == "Range" && AS_Config.ResizeRange >= MIN_SIZE && AS_Config.ResizeRange <= MAX_SIZE)
{
WritePrivateProfileInt("Config", "Range", AS_Config.ResizeRange, INIFileName);
}
}
else
{
// this writes all keys and their values to disk as normal
for (const auto& [key, value] : configMap)
{
WritePrivateProfileString("Config", key, value, INIFileName);
}
// special handling for Range since it's not part of the map (intentionally)
if (AS_Config.ResizeRange >= MIN_SIZE && AS_Config.ResizeRange <= MAX_SIZE)
{
WritePrivateProfileInt("Config", "Range", AS_Config.ResizeRange, INIFileName);
}
}
// only display info if squelch is false
if (!squelch)
{
WriteChatf("\ay%s\aw:: Configuration file saved.", mqplugin::PluginName);
}
}
void ChangeSize(PlayerClient* pChangeSpawn, float fNewSize)
{
if (pChangeSpawn)
{
reinterpret_cast<PlayerZoneClient_Hook*>(pChangeSpawn)->ChangeHeight_Wrapper(fNewSize);
}
}
void HandleResize(PlayerClient* pSpawn, bool bReset, int size) {
// only resize if functionality is enabled
if (AS_Config.Enabled) {
ChangeSize(pSpawn, bReset ? ZERO_SIZE : size);
}
else {
ChangeSize(pSpawn, ZERO_SIZE);
}
}
void SizePasser(PlayerClient* pSpawn, bool bReset)
{
if (GetGameState() != GAMESTATE_INGAME)
{
return;
}
if (!pLocalPlayer || !pSpawn) return;
if (pSpawn->SpawnID == pLocalPlayer->SpawnID)
{
if (AS_Config.OptSelf)
{
HandleResize(pSpawn, bReset, AS_Config.SizeSelf);
}
return;
}
switch (GetSpawnType(pSpawn))
{
case PC:
if (AS_Config.OptPC)
{
HandleResize(pSpawn, bReset, AS_Config.SizePC);
}
break;
case NPC:
if (AS_Config.OptNPC)
{
HandleResize(pSpawn, bReset, AS_Config.SizeNPC);
}
break;
case PET:
if (AS_Config.OptPet)
{
HandleResize(pSpawn, bReset, AS_Config.SizePet);
}
break;
case MERCENARY:
if (AS_Config.OptMerc)
{
HandleResize(pSpawn, bReset, AS_Config.SizeMerc);
}
break;
case MOUNT:
if (AS_Config.OptMount && pSpawn->SpawnID != pLocalPlayer->SpawnID)
{
HandleResize(pSpawn, bReset, AS_Config.SizeMount);
}
break;
case CORPSE:
if (AS_Config.OptCorpse)
{
HandleResize(pSpawn, bReset, AS_Config.SizeCorpse);
}
break;
default:
break;
}
}
void ResetAllByType(eSpawnType OurType)
{
PlayerClient* pSpawn = pSpawnList;
if (GetGameState() != GAMESTATE_INGAME || !pLocalPlayer || !pSpawn)
{
return;
}
while (pSpawn)
{
if (pSpawn->SpawnID != pLocalPlayer->SpawnID)
{
eSpawnType ListType = GetSpawnType(pSpawn);
if (ListType == OurType)
ChangeSize(pSpawn, ZERO_SIZE);
}
pSpawn = pSpawn->GetNext();
}
}
void SpawnListResize(bool bReset)
{
if (GetGameState() != GAMESTATE_INGAME)
return;
PlayerClient* pAllSpawns = pSpawnList;
while (pAllSpawns)
{
SizePasser(pAllSpawns, bReset);
pAllSpawns = pAllSpawns->GetNext();
}
}
PLUGIN_API void OnEndZone()
{
SpawnListResize(false);
}
PLUGIN_API void OnPulse()
{
if (GetGameState() != GAMESTATE_INGAME)
{
return;
}
if (std::chrono::steady_clock::now() < lastUpdate + UPDATE_INTERVAL)
{
return;
}
lastUpdate = std::chrono::steady_clock::now();
PlayerClient* pAllSpawns = pSpawnList;
while (pAllSpawns)
{
float fDist = GetDistance(pLocalPlayer, pAllSpawns);
if (fDist < AS_Config.ResizeRange)
{
SizePasser(pAllSpawns, false);
}
else if (fDist < AS_Config.ResizeRange + 50)
{
SizePasser(pAllSpawns, true);
}
pAllSpawns = pAllSpawns->GetNext();
}
}
void OutputHelp()
{
WriteChatf("\ay%s\aw:: Command Usage Help", mqplugin::PluginName);
WriteChatf(" \ag/autosize\ax - Toggles AutoSize functionality on/off");
WriteChatf(" \ag/autosize\ax \aydist\ax - Toggles distance-based vs Zonewide");
WriteChatf(" \ag/autosize\ax \ayrange #\ax - Sets range for distance checking");
WriteChatf("--- Valid Resize Toggles ---");
WriteChatf(" \ag/autosize\ax [ \aypc\ax | \aynpc\ax | \aypets\ax | \aymercs\ax | \aymounts\ax | \aycorpse\ax | \ayeverything\ax | \ayself\ax ]");
WriteChatf("--- Valid Size Syntax (%d to %d) ---", MIN_SIZE, MAX_SIZE);
WriteChatf(" \ag/autosize\ax [ \aysizepc\ax | \aysizenpc\ax | \aysizepets\ax | \aysizemercs\ax | \aysizemounts\ax | \aysizecorpse\ax | \aysizeself\ax ] [ \ay#\ax ]");
WriteChatf("--- Other Valid Commands ---");
WriteChatf(" \ag/autosize\ax [ \ayhelp\ax | \aystatus\ax | \ayautosave\ax | \aysave\ax | \ayload\ax ]");
WriteChatf("--- Ability to set options ---");
WriteChatf(" \ag/autosize\ax [ \ayautosize\ax | \aypc\ax | \aynpc\ax | \aypets\ax | \aymercs\ax | \aymounts\ax | \aycorpse\ax | \ayeverything\ax | \ayself\ax ] [\agon\ax | \aroff\ax]");
}
void OutputStatus()
{
char szMethod[100] = { 0 };
char szOn[10] = "\agon\ax";
char szOff[10] = "\aroff\ax";
if (!AS_Config.Enabled || !AS_Config.OptPC && !AS_Config.OptNPC && !AS_Config.OptPet && !AS_Config.OptMerc && !AS_Config.OptCorpse && !AS_Config.OptSelf)
{
strcpy_s(szMethod, "\arInactive\ax");
}
else if (AS_Config.ResizeRange < FAR_CLIP_PLANE)
{
sprintf_s(szMethod, "\ayRange\ax) RangeSize(\ag%d\ax", AS_Config.ResizeRange);
}
else if (AS_Config.ResizeRange == FAR_CLIP_PLANE)
{
// covers the idea of Zonewide by using FAR_CLIP_PLANE value (which is about 100% Far Cliping Plane)
strcpy_s(szMethod, "\ayZonewide\ax");
}
WriteChatf("\ay%s\aw:: Current Status -- Method: (%s)%s", mqplugin::PluginName, szMethod, AS_Config.OptAutoSave ? " \agAUTOSAVING" : "");
// leaving Everything in the output to avoid any script which might have read this line
// forced the value to off though.
WriteChatf("Toggles: PC(%s) NPC(%s) Pets(%s) Mercs(%s) Mounts(%s) Corpses(%s) Self(%s) Everything(%s) ",
AS_Config.OptPC ? szOn : szOff,
AS_Config.OptNPC ? szOn : szOff,
AS_Config.OptPet ? szOn : szOff,
AS_Config.OptMerc ? szOn : szOff,
AS_Config.OptMount ? szOn : szOff,
AS_Config.OptCorpse ? szOn : szOff,
AS_Config.OptSelf ? szOn : szOff,
szOff // no longer available but left to ensure that no random script that reads this, breaks.
);
WriteChatf("Sizes: PC(\ag%d\ax) NPC(\ag%d\ax) Pets(\ag%d\ax) Mercs(\ag%d\ax) Mounts(\ag%d\ax) Corpses(\ag%d\ax) Target(\ag%d\ax) Self(\ag%d\ax) Everything(\ag%d\ax)",
AS_Config.SizePC,
AS_Config.SizeNPC,
AS_Config.SizePet,
AS_Config.SizeMerc,
AS_Config.SizeMount,
AS_Config.SizeCorpse,
0, // no longer available but left to ensure that no random script that reads this, breaks.
AS_Config.SizeSelf,
0 // no longer available but left to ensure that no random script that reads this, breaks.
);
}
bool ToggleOption(const char* pszToggleOutput, bool* pbOption)
{
*pbOption = !*pbOption;
WriteChatf("\ay%s\aw:: Option (\ay%s\ax) now %s\ax", mqplugin::PluginName, pszToggleOutput, *pbOption ? "\agenabled" : "\ardisabled");
if (AS_Config.OptAutoSave)
SaveINI();
return *pbOption;
}
void SetOption(const char* optString, bool* pbOption, bool bValue)
{
*pbOption = bValue;
WriteChatf("\ay%s\aw:: Option (\ay%s\ax) now %s\ax", mqplugin::PluginName, optString, *pbOption ? "\agenabled" : "\ardisabled");
if (AS_Config.OptAutoSave)
SaveINI();
}
void SetSizeConfig(const char* pszOption, int iNewSize, int* iOldSize)
{
// special handling for Range being set to Zonewide
if (ci_equals(pszOption, "range") && iNewSize == FAR_CLIP_PLANE)
{
// set the pointer to the new value
*iOldSize = iNewSize;
WriteChatf("\ay%s\aw:: Range size is \agZonewide\ax - %d units", mqplugin::PluginName, FAR_CLIP_PLANE);
// return early to avoid saving to INI
return;
}
// make sure that we are setting values for a valid reason
if ((iNewSize != *iOldSize) && (iNewSize >= MIN_SIZE && iNewSize <= MAX_SIZE))
{
int iPrevSize = *iOldSize;
// set the pointer to the new value
*iOldSize = iNewSize;
WriteChatf("\ay%s\aw:: %s size changed from \ay%d\ax to \ag%d", mqplugin::PluginName, pszOption, iPrevSize, *iOldSize);
}
else
{
WriteChatf("\ay%s\aw:: %s size is \ag%d\ax (was not modified)", mqplugin::PluginName, pszOption, *iOldSize);
}
if (AS_Config.OptAutoSave)
SaveINI();
}
void AutoSizeCmd(PlayerClient*, const char* szLine)
{
char szCurArg[MAX_STRING] = { 0 };
char szNumber[MAX_STRING] = { 0 };
GetArg(szCurArg, szLine, 1);
GetArg(szNumber, szLine, 2);
int iNewSize = GetIntFromString(szNumber, MIN_SIZE);
if (!szCurArg[0])
{
// toggle AutoSize functionality via configuration
ToggleOption("AutoSize functionality", &AS_Config.Enabled);
}
else if (ci_equals(szCurArg, "on"))
{
SetOption("AutoSize functionality", &AS_Config.Enabled, true);
}
else if (ci_equals(szCurArg, "off"))
{
SetOption("AutoSize functionality", &AS_Config.Enabled, false);
}
else if (ci_equals(szCurArg, "dist"))
{
if (ci_equals(szNumber, "on"))
{
if (AS_Config.ResizeRange == FAR_CLIP_PLANE)
{
// this means we are currently set to Zonewide and need to set to Range instead
// we want look like we are toggling to Range from Zonewide setting
// we will do this by reseting the ResizeRange to what it was prior
Emulate("range");
}
}
else if (ci_equals(szNumber, "off"))
{
if (AS_Config.ResizeRange != FAR_CLIP_PLANE)
{
// this means we are currently set to Range distance and want to be Zonewide
// we want look like we are toggling to Zonewide from Range setting
// we will do this by increasing the ResizeRange to FAR_CLIP_PLANE
Emulate("zonewide");
}
}
else
{
if (AS_Config.ResizeRange == FAR_CLIP_PLANE)
{
Emulate("range");
}
else if (AS_Config.ResizeRange != FAR_CLIP_PLANE)
{
Emulate("zonewide");
}
}
}
else if (ci_equals(szCurArg, "save"))
{
SaveINI();
}
else if (ci_equals(szCurArg, "load"))
{
LoadINI();
}
else if (ci_equals(szCurArg, "autosave"))
{
if (ci_equals(szNumber, "on"))
{
SetOption("Autosave", &AS_Config.OptAutoSave, true);
}
else if (ci_equals(szNumber, "off"))
{
SetOption("Autosave", &AS_Config.OptAutoSave, false);
}
else
{
ToggleOption("Autosave", &AS_Config.OptAutoSave);
}
}
else if (ci_equals(szCurArg, "range"))
{
SetSizeConfig("range", iNewSize, &AS_Config.ResizeRange);
}
else if (ci_equals(szCurArg, "size"))
{
WriteChatf("\ay%s\aw:: This feature (\ay%s\ax) has been deprecated. Check /mqsetting -> plugins -> AutoSize.", mqplugin::PluginName, szCurArg);
}
else if (ci_equals(szCurArg, "sizepc"))
{
SetSizeConfig("PC", iNewSize, &AS_Config.SizePC);
}
else if (ci_equals(szCurArg, "sizenpc"))
{
SetSizeConfig("NPC", iNewSize, &AS_Config.SizeNPC);
}
else if (ci_equals(szCurArg, "sizepets"))
{
SetSizeConfig("Pet", iNewSize, &AS_Config.SizePet);
}
else if (ci_equals(szCurArg, "sizemercs"))
{
SetSizeConfig("Mercs", iNewSize, &AS_Config.SizeMerc);
}
else if (ci_equals(szCurArg, "sizemounts"))
{
SetSizeConfig("Mounts", iNewSize, &AS_Config.SizeMount);
}
else if (ci_equals(szCurArg, "sizecorpse"))
{
SetSizeConfig("Corpses", iNewSize, &AS_Config.SizeCorpse);
}
else if (ci_equals(szCurArg, "sizeself"))
{
SetSizeConfig("Self", iNewSize, &AS_Config.SizeSelf);
}
else if (ci_equals(szCurArg, "pc"))
{
if (ci_equals(szNumber, "on"))
{
SetOption("PC", &AS_Config.OptPC, true);
}
else if (ci_equals(szNumber, "off"))
{
SetOption("PC", &AS_Config.OptPC, false);
ResetAllByType(PC);
}
else
{
if (!ToggleOption("PC", &AS_Config.OptPC))
{
ResetAllByType(PC);
}
}
}
else if (ci_equals(szCurArg, "npc"))
{
if (ci_equals(szNumber, "on"))
{
SetOption("NPC", &AS_Config.OptNPC, true);
}
else if (ci_equals(szNumber, "off"))
{
SetOption("NPC", &AS_Config.OptNPC, false);
ResetAllByType(NPC);
}
else
{
if (!ToggleOption("NPC", &AS_Config.OptNPC))
{
ResetAllByType(NPC);
}
}
}
else if (ci_equals(szCurArg, "everything"))
{
if (!AS_Config.OptSelf)
{
DoCommand("/squelch /autosize self on");
}
if (!AS_Config.OptCorpse)
{
DoCommand("/squelch /autosize corpse on");
}
if (!AS_Config.OptMerc)
{
DoCommand("/squelch /autosize mercs on");
}
if (!AS_Config.OptMount)
{
DoCommand("/squelch /autosize mounts on");
}
if (!AS_Config.OptNPC)
{
DoCommand("/squelch /autosize npc on");
}
if (!AS_Config.OptPC)
{
DoCommand("/squelch /autosize pc on");
}
if (!AS_Config.OptPet)
{
DoCommand("/squelch /autosize pets on");
}
}
else if (ci_equals(szCurArg, "pets"))
{
if (ci_equals(szNumber, "on"))
{
SetOption("Pets", &AS_Config.OptPet, true);
}
else if (ci_equals(szNumber, "off"))
{
SetOption("Pets", &AS_Config.OptPet, false);
ResetAllByType(PET);
}
else
{
if (!ToggleOption("Pets", &AS_Config.OptPet))
{
ResetAllByType(PET);
}
}
}
else if (ci_equals(szCurArg, "mercs"))
{
if (ci_equals(szNumber, "on"))
{
SetOption("Mercs", &AS_Config.OptMerc, true);
}
else if (ci_equals(szNumber, "off"))
{
SetOption("Mercs", &AS_Config.OptMerc, false);
ResetAllByType(MERCENARY);
}
else
{
if (!ToggleOption("Mercs", &AS_Config.OptMerc))
{
ResetAllByType(MERCENARY);
}
}
}
else if (ci_equals(szCurArg, "mounts"))
{
if (ci_equals(szNumber, "on"))
{
SetOption("Mounts", &AS_Config.OptMount, true);
}
else if (ci_equals(szNumber, "off"))
{
SetOption("Mounts", &AS_Config.OptMount, false);
ResetAllByType(MOUNT);
}
else
{
if (!ToggleOption("Mounts", &AS_Config.OptMount))
{
ResetAllByType(MOUNT);
}
}
}
else if (ci_equals(szCurArg, "corpse"))
{
if (ci_equals(szNumber, "on"))
{
SetOption("Corpses", &AS_Config.OptCorpse, true);
}
else if (ci_equals(szNumber, "off"))
{
SetOption("Corpses", &AS_Config.OptCorpse, false);
ResetAllByType(CORPSE);
}
else
{
if (!ToggleOption("Corpses", &AS_Config.OptCorpse))
{
ResetAllByType(CORPSE);
}
}
}
else if (ci_equals(szCurArg, "target"))
{
// deprecated because when you use this while having features enabled this feature didn't actually work.
// if you don't have anything resizing, why would you want to resize just the target?
WriteChatf("\ay%s\aw:: This feature (\ay%s\ax) has been deprecated. Check /mqsetting -> plugins -> AutoSize.", mqplugin::PluginName, szCurArg);
}
else if (ci_equals(szCurArg, "self"))
{
if (ci_equals(szNumber, "on"))
{
SetOption("Self", &AS_Config.OptSelf, true);
}
else if (ci_equals(szNumber, "off"))
{
SetOption("Self", &AS_Config.OptSelf, false);
ChangeSize(pLocalPlayer, ZERO_SIZE);
}
else
{
if (!ToggleOption("Self", &AS_Config.OptSelf))
{
ChangeSize(pLocalPlayer, ZERO_SIZE);
}
}
}
else if (ci_equals(szCurArg, "help"))
{
OutputHelp();
}
else if (ci_equals(szCurArg, "status"))
{
OutputStatus();
}
else
{
WriteChatf("\ay%s\aw:: \arInvalid command parameter.", mqplugin::PluginName);
}
}
PLUGIN_API void InitializePlugin()
{
EzDetour(PlayerZoneClient__ChangeHeight, &PlayerZoneClient_Hook::ChangeHeight_Detour, &PlayerZoneClient_Hook::ChangeHeight_Trampoline);
pAutoSizeType = new MQ2AutoSizeType;
AddMQ2Data("AutoSize", dataAutoSize);
AddCommand("/autosize", AutoSizeCmd);
AddSettingsPanel("plugins/AutoSize", DrawAutoSize_MQSettingsPanel);
LoadINI();
loadedEQBC = IsPluginLoaded("MQ2EQBC");
loadedDannet = IsPluginLoaded("MQ2DanNet");
ChooseInstructionPlugin();
}
PLUGIN_API void ShutdownPlugin()
{
RemoveDetour(PlayerZoneClient__ChangeHeight);
RemoveSettingsPanel("plugins/AutoSize");
RemoveCommand("/autosize");
SpawnListResize(true);
if (AS_Config.OptAutoSave)
{
SaveINI();
}
RemoveMQ2Data("AutoSize");
delete pAutoSizeType;
}
PLUGIN_API void OnLoadPlugin(const char* pluginName)
{
DebugSpewAlways("OnLoadPluign: MQ2AutoSize -> %s", pluginName);
// dannet plugin is loading
if (ci_equals(pluginName, "MQ2DanNet"))
{
loadedDannet = true;
ChooseInstructionPlugin();
}
// eqbc plugin is loading
if (ci_equals(pluginName, "MQ2EQBC"))
{
loadedEQBC = true;
ChooseInstructionPlugin();
}
}
PLUGIN_API void OnUnloadPlugin(const char* pluginName)
{
DebugSpewAlways("OnUnloadPlugin: MQ2AutoSize -> %s", pluginName);
// dannet plugin is about to unload
if (ci_equals(pluginName, "MQ2DanNet"))
{
loadedDannet = false;
ChooseInstructionPlugin();
}
// eqbc plugin is about to unload
if (ci_equals(pluginName, "MQ2EQBC"))
{
loadedEQBC = false;
ChooseInstructionPlugin();
}
}
template <typename T>
bool RadioButton(const char* label, T* value, T defaultValue)
{
using UnderlyingType = std::underlying_type_t<T>;
return ImGui::RadioButton(label, reinterpret_cast<UnderlyingType*>(value), static_cast<UnderlyingType>(defaultValue));
}
void DrawAutoSize_MQSettingsPanel()
{
ImGui::TextColored(ImVec4(1.0f, 1.0f, 0.0f, 1.0f), "MQ2AutoSize");
if (ImGui::BeginTabBar("AutoSizeTabBar"))
{
if (ImGui::BeginTabItem("Options"))
{
ImGui::SeparatorText("General");
// General: Enable / Disable AutoSize functionality
ImGui::Checkbox("Enable AutoSize functionality", &AS_Config.Enabled);
// General: auto save
if (ImGui::Checkbox("Enable auto saving of configuration", &AS_Config.OptAutoSave))
{
DoCommandf("/autosize autosave %s", AS_Config.OptAutoSave ? "on" : "off");
}
// General: Zonewide
if (RadioButton("Zonewide (max clipping plane)", &ResizeMode, eResizeMode::Zonewide))