-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathSyndicateHelper.cs
More file actions
1401 lines (1191 loc) · 62.3 KB
/
SyndicateHelper.cs
File metadata and controls
1401 lines (1191 loc) · 62.3 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
// SyndicateHelper.cs
// Main plugin class for the SyndicateHelper ExileAPI plugin.
// Provides UI overlays, decision scoring, and strategy guidance for the Betrayal/Syndicate mechanic in Path of Exile.
using ExileCore;
using ExileCore.PoEMemory;
using ExileCore.PoEMemory.Elements;
using ExileCore.PoEMemory.MemoryObjects;
using ExileCore.Shared.Cache;
using ExileCore.Shared.Enums;
using ExileCore.Shared.Helpers;
using ExileCore.Shared.Nodes;
using ImGuiNET;
using SharpDX;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using System.Numerics;
using System.Windows.Forms;
using Vector2 = System.Numerics.Vector2;
namespace SyndicateHelper
{
public class SyndicateDecision { public string MemberName { get; set; } public Element InterrogateButton { get; set; } public Element ReleaseButton { get; set; } public Element SpecialButton { get; set; } public string InterrogateText { get; set; } public string SpecialText { get; set; } }
public struct EvaluatedChoice
{
public string Name { get; set; }
public int Score { get; set; }
public Element Button { get; set; }
}
public enum GoalPriority { Critical, Major, Minor, Optimal }
public class StrategicGoal
{
public string Text { get; set; }
public GoalPriority Priority { get; set; }
public Color DisplayColor { get; set; }
}
public class SyndicateHelper : BaseSettingsPlugin<SyndicateHelperSettings>
{
private class CachedText
{
public string Text { get; set; }
public System.Numerics.Vector2 Size { get; set; }
public System.Numerics.Vector2 Position { get; set; }
public Color Color { get; set; }
}
private readonly List<Tuple<RectangleF, Color>> _rectanglesToDraw = new();
private readonly List<Tuple<RectangleF, RectangleF, Color>> _linksToDraw = new();
private readonly List<StrategicGoal> _strategicGoals = new List<StrategicGoal>();
private readonly List<string> _debugMessages = new List<string>();
private readonly HashSet<SyndicateDivision> _targetDivisions = new HashSet<SyndicateDivision>();
private readonly Dictionary<GoalPriority, bool> _collapsedSections = new()
{
[GoalPriority.Critical] = false,
[GoalPriority.Major] = false,
[GoalPriority.Minor] = true,
[GoalPriority.Optimal] = true
};
private bool _advisorMinimized = false;
private Dictionary<string, SyndicateMemberState> _boardState = new Dictionary<string, SyndicateMemberState>();
private int _imprisonedMemberCount = 0;
private SyndicateStrategy _strategyEvaluator;
private List<EvaluatedChoice> _lastChoices = new List<EvaluatedChoice>();
private SyndicateDecision _lastDecision = null;
private HashSet<long> _highlightedButtonAddresses = new();
private readonly List<CachedText> _cachedChoiceScores = new List<CachedText>();
private readonly List<CachedText> _cachedRewardText = new List<CachedText>();
private readonly List<RectangleF> _goalRects = new List<RectangleF>();
private RectangleF _leftButtonRect;
private RectangleF _rightButtonRect;
private RectangleF _minimizeButtonRect;
private DateTime _lastClickTime = DateTime.MinValue;
private bool _isBoardStateDirty = true;
private static readonly HashSet<string> SyndicateMemberNames = new HashSet<string>
{
"Aisling", "Cameria", "Elreon", "Gravicius", "Guff", "Haku", "Hillock",
"It That Fled", "Janus", "Jorgin", "Korell", "Leo", "Rin", "Riker",
"Tora", "Vagan", "Vorici"
};
private Dictionary<string, Element> _cachedPortraitElements = new Dictionary<string, Element>();
private List<Element> _cachedRelationshipElements = new List<Element>();
private bool _uiElementsDirty = true;
private int _selectedSettingsTab = 0;
private SyndicateDivision _availableSafehouseDivision = SyndicateDivision.None;
private Element _safehouseButtonElement;
private RectangleF _safehouseButtonRect = RectangleF.Empty;
private void CycleStrategy(int direction)
{
var strategyNames = SyndicateStrategies.Strategies.Select(s => s.Name).ToList();
if (strategyNames.Count == 0) return;
var currentStrategyName = Settings.StrategyProfile.Value;
var currentIndex = strategyNames.IndexOf(currentStrategyName);
if (currentIndex == -1)
{
Settings.StrategyProfile.Value = strategyNames[0];
Settings.ApplyStrategyGoals(Settings.StrategyProfile.Value);
_isBoardStateDirty = true;
return;
}
var newIndex = (currentIndex + direction + strategyNames.Count) % strategyNames.Count;
Settings.StrategyProfile.Value = strategyNames[newIndex];
Settings.ApplyStrategyGoals(Settings.StrategyProfile.Value);
_isBoardStateDirty = true;
}
private bool IsValidRect(RectangleF rect)
{
if (rect.IsEmpty) return false;
if (rect.Width <= 0 || rect.Height <= 0) return false;
if (float.IsNaN(rect.X) || float.IsNaN(rect.Y)) return false;
if (float.IsInfinity(rect.X) || float.IsInfinity(rect.Y)) return false;
const float minBound = -2000f;
const float maxBound = 8000f;
if (rect.X < minBound || rect.X > maxBound) return false;
if (rect.Y < minBound || rect.Y > maxBound) return false;
return true;
}
private SyndicateDivision DetectAvailableSafehouse(SyndicatePanel betrayalWindow)
{
if (betrayalWindow?.SyndicateStates == null)
return SyndicateDivision.None;
foreach (var memberState in betrayalWindow.SyndicateStates)
{
if (memberState == null) continue;
try
{
if (memberState.Intel >= 100)
{
var job = memberState.Job;
if (job != null && Enum.TryParse<SyndicateDivision>(job.Name, out var division))
{
return division;
}
}
}
catch
{
}
}
return SyndicateDivision.None;
}
private Element FindSafehouseButton(SyndicatePanel betrayalWindow)
{
if (betrayalWindow == null) return null;
return FindSafehouseButtonRecursive(betrayalWindow);
}
private Element FindSafehouseButtonRecursive(Element element)
{
if (element == null) return null;
var text = SyndicateHelperUtility.GetElementTextSafely(element);
if (!string.IsNullOrEmpty(text))
{
var lowerText = text.ToLowerInvariant();
bool isRaidButton = lowerText.Contains("raid") ||
lowerText.Contains("safehouse") ||
lowerText.Contains("enter") ||
lowerText.Contains("attack") ||
lowerText.Contains("assault");
if (isRaidButton && element.IsVisible)
{
return element;
}
}
// Search children
foreach (var child in element.Children)
{
var result = FindSafehouseButtonRecursive(child);
if (result != null) return result;
}
return null;
}
private bool IsValidButton(Element button)
{
if (button == null) return false;
if (!button.IsVisible) return false;
try
{
var rect = button.GetClientRectCache;
return IsValidRect(rect);
}
catch
{
return false;
}
}
public override bool Initialise()
{
Name = "SyndicateHelper";
return true;
}
public override void OnUnload()
{
if (Settings?.StrategyProfile != null)
{
Settings.StrategyProfile.OnValueSelected -= Settings_ApplyStrategyGoals;
}
base.OnUnload();
}
public override void DrawSettings()
{
string[] settingTabs =
{
"Visual Style",
"Syndicate Strategies",
"UI Settings"
};
if (ImGui.BeginChild("LeftSidebar", new Vector2(150, ImGui.GetContentRegionAvail().Y), ImGuiChildFlags.Border, ImGuiWindowFlags.None))
{
for (var i = 0; i < settingTabs.Length; i++)
{
if (ImGui.Selectable(settingTabs[i], _selectedSettingsTab == i))
{
_selectedSettingsTab = i;
}
}
}
ImGui.EndChild();
ImGui.SameLine();
ImGui.PushStyleVar(ImGuiStyleVar.ChildRounding, 5.0f);
var contentRegionArea = ImGui.GetContentRegionAvail();
if (ImGui.BeginChild("RightPanel", contentRegionArea, ImGuiChildFlags.Border, ImGuiWindowFlags.None))
{
switch (settingTabs[_selectedSettingsTab])
{
case "Visual Style":
DrawVisualStyleTab();
break;
case "Syndicate Strategies":
DrawSyndicateStrategiesTab();
break;
case "UI Settings":
DrawUISettingsTab();
break;
}
}
ImGui.PopStyleVar();
ImGui.EndChild();
}
private void DrawVisualStyleTab()
{
ImGui.Text("Background Alpha");
var bgAlpha = Settings.BackgroundAlpha.Value;
if (ImGui.SliderInt("##BackgroundAlpha", ref bgAlpha, Settings.BackgroundAlpha.Min, Settings.BackgroundAlpha.Max))
{
Settings.BackgroundAlpha.Value = bgAlpha;
}
ImGui.Text("Frame Thickness");
var frameThickness = Settings.FrameThickness.Value;
if (ImGui.SliderInt("##FrameThickness", ref frameThickness, Settings.FrameThickness.Min, Settings.FrameThickness.Max))
{
Settings.FrameThickness.Value = frameThickness;
}
ImGui.Separator();
ImGui.Text("Good Choice");
var goodColor = Settings.GoodChoiceColor.Value.ToImguiVec4();
if (ImGui.ColorEdit4("##GoodChoice", ref goodColor))
{
Settings.GoodChoiceColor.Value = new SharpDX.Color((byte)(goodColor.X * 255), (byte)(goodColor.Y * 255), (byte)(goodColor.Z * 255), (byte)(goodColor.W * 255));
}
ImGui.Text("Goal Completion");
var goalColor = Settings.GoalCompletionColor.Value.ToImguiVec4();
if (ImGui.ColorEdit4("##GoalCompletion", ref goalColor))
{
Settings.GoalCompletionColor.Value = new SharpDX.Color((byte)(goalColor.X * 255), (byte)(goalColor.Y * 255), (byte)(goalColor.Z * 255), (byte)(goalColor.W * 255));
}
ImGui.Text("Neutral Choice");
var neutralColor = Settings.NeutralChoiceColor.Value.ToImguiVec4();
if (ImGui.ColorEdit4("##NeutralChoice", ref neutralColor))
{
Settings.NeutralChoiceColor.Value = new SharpDX.Color((byte)(neutralColor.X * 255), (byte)(neutralColor.Y * 255), (byte)(neutralColor.Z * 255), (byte)(neutralColor.W * 255));
}
ImGui.Text("Bad Choice");
var badColor = Settings.BadChoiceColor.Value.ToImguiVec4();
if (ImGui.ColorEdit4("##BadChoice", ref badColor))
{
Settings.BadChoiceColor.Value = new SharpDX.Color((byte)(badColor.X * 255), (byte)(badColor.Y * 255), (byte)(badColor.Z * 255), (byte)(badColor.W * 255));
}
ImGui.Separator();
ImGui.Text("Animation Settings");
ImGui.Text("Enable Animations");
var enableAnimations = Settings.EnableAnimations.Value;
if (ImGui.Checkbox("##EnableAnimations", ref enableAnimations))
{
Settings.EnableAnimations.Value = enableAnimations;
}
ImGui.Text("Animation Speed");
var animSpeed = Settings.AnimationSpeed.Value;
if (ImGui.SliderFloat("##AnimationSpeed", ref animSpeed, Settings.AnimationSpeed.Min, Settings.AnimationSpeed.Max))
{
Settings.AnimationSpeed.Value = animSpeed;
}
ImGui.Text("Animation Intensity");
var animIntensity = Settings.AnimationIntensity.Value;
if (ImGui.SliderFloat("##AnimationIntensity", ref animIntensity, Settings.AnimationIntensity.Min, Settings.AnimationIntensity.Max))
{
Settings.AnimationIntensity.Value = animIntensity;
}
}
private void DrawSyndicateStrategiesTab()
{
ImGui.Text("Strategy Profile");
var newProfile = ImGuiExtension.ComboBox("##Profile", Settings.StrategyProfile.Value,
Settings.StrategyProfile.Values, out var profileSelected, ImGuiComboFlags.HeightLarge);
if (profileSelected)
{
Settings.StrategyProfile.Value = newProfile;
Settings.ApplyStrategyGoals(Settings.StrategyProfile.Value);
_isBoardStateDirty = true;
}
ImGui.Separator();
if (Settings.StrategyProfile.Value == "Relationship-Based")
{
DrawRelationshipSettings();
ImGui.Separator();
}
DrawMemberGoalsTab();
}
private void DrawRelationshipSettings()
{
ImGui.Text("Relationship Configuration");
ImGui.Separator();
ImGui.Text("Opposed Divisions");
var opposedDivisions = Settings.OpposedDivisions.Value;
if (ImGui.InputText("##OpposedDivisions", ref opposedDivisions, 256))
{
Settings.OpposedDivisions.Value = opposedDivisions;
}
if (ImGui.IsItemHovered())
{
ImGui.SetTooltip("Comma-separated pairs of divisions that should NOT have relationships\n(e.g., 'Transportation-Research,Fortification-Intervention')");
}
ImGui.Text("Allied Divisions");
var alliedDivisions = Settings.AlliedDivisions.Value;
if (ImGui.InputText("##AlliedDivisions", ref alliedDivisions, 256))
{
Settings.AlliedDivisions.Value = alliedDivisions;
}
if (ImGui.IsItemHovered())
{
ImGui.SetTooltip("Comma-separated pairs of divisions that SHOULD have relationships\n(e.g., 'Fortification-Transportation,Intervention-Research')");
}
ImGui.Text("Relationship Score Modifier");
var relationshipModifier = Settings.RelationshipScoreModifier.Value;
if (ImGui.SliderInt("##RelationshipModifier", ref relationshipModifier,
Settings.RelationshipScoreModifier.Min, Settings.RelationshipScoreModifier.Max))
{
Settings.RelationshipScoreModifier.Value = relationshipModifier;
}
if (ImGui.IsItemHovered())
{
ImGui.SetTooltip("Score multiplier for choices that affect relationships (0-100%)");
}
}
private void DrawUISettingsTab()
{
ImGui.Text("Show Goal Info");
var showGoalInfo = Settings.ShowGoalInfo.Value;
if (ImGui.Checkbox("##ShowGoalInfo", ref showGoalInfo))
{
Settings.ShowGoalInfo.Value = showGoalInfo;
}
ImGui.Text("Show Action Buttons");
var showButtons = Settings.ShowButtons.Value;
if (ImGui.Checkbox("##ShowButtons", ref showButtons))
{
Settings.ShowButtons.Value = showButtons;
}
ImGui.Text("Show Curve Connections");
var showCurves = Settings.ShowCurves.Value;
if (ImGui.Checkbox("##ShowCurves", ref showCurves))
{
Settings.ShowCurves.Value = showCurves;
}
ImGui.Separator();
ImGui.Text("Enable Debug Drawing");
var enableDebug = Settings.EnableDebugDrawing.Value;
if (ImGui.Checkbox("##EnableDebug", ref enableDebug))
{
Settings.EnableDebugDrawing.Value = enableDebug;
}
ImGui.Text("Draw Portraits");
var drawPortraits = Settings.DrawPortraits.Value;
if (ImGui.Checkbox("##DrawPortraits", ref drawPortraits))
{
Settings.DrawPortraits.Value = drawPortraits;
}
ImGui.Text("Draw Relationships");
var drawRelations = Settings.DrawRelations.Value;
if (ImGui.Checkbox("##DrawRelations", ref drawRelations))
{
Settings.DrawRelations.Value = drawRelations;
}
}
private void DrawMemberGoalsTab()
{
ImGui.Text("Fortification Members");
ImGui.Separator();
Settings.Aisling.Value = ImGuiExtension.ComboBox("Aisling##Fort", Settings.Aisling.Value, Settings.Aisling.Values, out var _);
Settings.Cameria.Value = ImGuiExtension.ComboBox("Cameria##Fort", Settings.Cameria.Value, Settings.Cameria.Values, out var _);
Settings.Elreon.Value = ImGuiExtension.ComboBox("Elreon##Fort", Settings.Elreon.Value, Settings.Elreon.Values, out var _);
Settings.Gravicius.Value = ImGuiExtension.ComboBox("Gravicius##Fort", Settings.Gravicius.Value, Settings.Gravicius.Values, out var _);
ImGui.Spacing();
ImGui.Text("Research Members");
ImGui.Separator();
Settings.Guff.Value = ImGuiExtension.ComboBox("Guff##Res", Settings.Guff.Value, Settings.Guff.Values, out var _);
Settings.Haku.Value = ImGuiExtension.ComboBox("Haku##Res", Settings.Haku.Value, Settings.Haku.Values, out var _);
Settings.Hillock.Value = ImGuiExtension.ComboBox("Hillock##Res", Settings.Hillock.Value, Settings.Hillock.Values, out var _);
Settings.ItThatFled.Value = ImGuiExtension.ComboBox("It That Fled##Res", Settings.ItThatFled.Value, Settings.ItThatFled.Values, out var _);
ImGui.Spacing();
ImGui.Text("Intervention Members");
ImGui.Separator();
Settings.Janus.Value = ImGuiExtension.ComboBox("Janus##Int", Settings.Janus.Value, Settings.Janus.Values, out var _);
Settings.Jorgin.Value = ImGuiExtension.ComboBox("Jorgin##Int", Settings.Jorgin.Value, Settings.Jorgin.Values, out var _);
Settings.Korell.Value = ImGuiExtension.ComboBox("Korell##Int", Settings.Korell.Value, Settings.Korell.Values, out var _);
Settings.Leo.Value = ImGuiExtension.ComboBox("Leo##Int", Settings.Leo.Value, Settings.Leo.Values, out var _);
ImGui.Spacing();
ImGui.Text("Transportation Members");
ImGui.Separator();
Settings.Rin.Value = ImGuiExtension.ComboBox("Rin##Trans", Settings.Rin.Value, Settings.Rin.Values, out var _);
Settings.Riker.Value = ImGuiExtension.ComboBox("Riker##Trans", Settings.Riker.Value, Settings.Riker.Values, out var _);
Settings.Tora.Value = ImGuiExtension.ComboBox("Tora##Trans", Settings.Tora.Value, Settings.Tora.Values, out var _);
Settings.Vagan.Value = ImGuiExtension.ComboBox("Vagan##Trans", Settings.Vagan.Value, Settings.Vagan.Values, out var _);
Settings.Vorici.Value = ImGuiExtension.ComboBox("Vorici##Trans", Settings.Vorici.Value, Settings.Vorici.Values, out var _);
}
private void Settings_ApplyStrategyGoals(string value)
{
Settings.ApplyStrategyGoals(value);
_isBoardStateDirty = true;
}
public override Job Tick()
{
if (!CanRun()) {
_lastDecision = null;
return null;
}
try
{
#pragma warning disable CS0618
var betrayalWindow = GameController.IngameState?.IngameUi?.BetrayalWindow as SyndicatePanel;
#pragma warning restore CS0618
if (betrayalWindow == null || !betrayalWindow.IsVisible)
{
_lastDecision = null;
_isBoardStateDirty = true;
return null;
}
_linksToDraw.Clear();
_debugMessages.Clear();
_rectanglesToDraw.Clear();
_cachedChoiceScores.Clear();
_cachedRewardText.Clear();
_goalRects.Clear();
if (_isBoardStateDirty)
{
UpdateBoardAndPrisonState(betrayalWindow);
var currentStrategy = SyndicateStrategies.Strategies.FirstOrDefault(s => s.Name == Settings.StrategyProfile.Value);
_strategyEvaluator = new SyndicateStrategy(Settings, _boardState, _imprisonedMemberCount, currentStrategy);
_strategicGoals.Clear();
GenerateStrategicGoals(betrayalWindow);
_isBoardStateDirty = false;
}
if (_uiElementsDirty)
{
UpdateUIElementCache(betrayalWindow);
_uiElementsDirty = false;
}
var eventDataElement = betrayalWindow.BetrayalEventData as BetrayalEventData;
_lastDecision = eventDataElement != null && eventDataElement.IsVisible ? ParseDecision(eventDataElement) : null;
if (_lastDecision != null)
{
ProcessEncounterChoices(eventDataElement);
}
ProcessBoardOverlays(betrayalWindow);
_availableSafehouseDivision = DetectAvailableSafehouse(betrayalWindow);
if (_availableSafehouseDivision != SyndicateDivision.None)
{
_safehouseButtonElement = FindSafehouseButton(betrayalWindow);
_safehouseButtonRect = _safehouseButtonElement != null && _safehouseButtonElement.IsVisible
? _safehouseButtonElement.GetClientRectCache
: RectangleF.Empty;
}
else
{
_safehouseButtonElement = null;
_safehouseButtonRect = RectangleF.Empty;
}
if (Input.IsKeyDown(Keys.LButton) && (DateTime.Now - _lastClickTime).TotalMilliseconds > SyndicateHelperConstants.MouseClickDebounceMs)
{
var mousePos = new SharpDX.Vector2(GameController.IngameState.MousePosX, GameController.IngameState.MousePosY);
if (_leftButtonRect.Contains(mousePos))
{
CycleStrategy(-1);
_lastClickTime = DateTime.Now;
}
else if (_rightButtonRect.Contains(mousePos))
{
CycleStrategy(1);
_lastClickTime = DateTime.Now;
}
else if (_minimizeButtonRect.Contains(mousePos))
{
_advisorMinimized = !_advisorMinimized;
_lastClickTime = DateTime.Now;
}
}
return null;
}
catch (Exception ex)
{
LogError($"SyndicateHelper Tick error: {ex.Message}");
return null;
}
}
public override void Render()
{
if (!CanRun()) return;
try
{
#pragma warning disable CS0618
var betrayalWindow = GameController.IngameState?.IngameUi?.BetrayalWindow as SyndicatePanel;
#pragma warning restore CS0618
if (betrayalWindow == null || !betrayalWindow.IsVisible) return;
var advisorBottomY = RenderStrategyAdvisorImGui(betrayalWindow);
var backgroundColor = new Color((byte)0, (byte)0, (byte)0, (byte)Settings.BackgroundAlpha.Value);
if (_lastDecision != null)
{
ProcessChoiceHighlights();
}
if (Settings.ShowButtons.Value)
{
foreach (var rect in _rectanglesToDraw)
{
// Validate rectangle before drawing to prevent artifacts at (0,0)
if (IsValidRect(rect.Item1))
{
Graphics.DrawFrame(rect.Item1, rect.Item2, Settings.FrameThickness.Value);
}
}
// Draw safehouse button highlight if available
if (_availableSafehouseDivision != SyndicateDivision.None && IsValidRect(_safehouseButtonRect))
{
Graphics.DrawFrame(_safehouseButtonRect, Settings.GoodChoiceColor.Value, Settings.FrameThickness.Value + 1);
if (Settings.EnableAnimations.Value)
{
SyndicateHelperUtility.DrawSnakeEffect(
_safehouseButtonRect,
Settings.GoodChoiceColor.Value,
Settings.AnimationSpeed.Value,
Settings.AnimationIntensity.Value,
Graphics.DrawBox
);
}
}
if (Settings.EnableAnimations.Value)
{
var bestChoice = _lastChoices.OrderByDescending(c => c.Score).FirstOrDefault();
if (bestChoice.Button != null && bestChoice.Button.IsVisible)
{
var bestButtonRect = bestChoice.Button.GetClientRectCache;
if (IsValidRect(bestButtonRect))
{
var scoreColor = _highlightedButtonAddresses.Contains(bestChoice.Button.Address)
? Settings.GoalCompletionColor.Value
: bestChoice.Score > 0 ? Settings.GoodChoiceColor.Value :
bestChoice.Score == 0 ? Settings.NeutralChoiceColor.Value : Settings.BadChoiceColor.Value;
SyndicateHelperUtility.DrawSnakeEffect(
bestButtonRect,
scoreColor,
Settings.AnimationSpeed.Value,
Settings.AnimationIntensity.Value,
Graphics.DrawBox
);
}
}
}
if (Settings.ShowCurves.Value)
{
foreach (var link in _linksToDraw)
{
// Validate both rectangles before drawing curve
if (!IsValidRect(link.Item1) || !IsValidRect(link.Item2))
continue;
var goalAnchor = new System.Numerics.Vector2(link.Item1.Right, link.Item1.Top);
var buttonAnchor = new System.Numerics.Vector2(link.Item2.Left, link.Item2.Center.Y);
SyndicateHelperUtility.DrawBezierCurve(
goalAnchor,
buttonAnchor,
Settings.FrameThickness.Value,
link.Item3,
Graphics.DrawLine);
}
}
}
if (Settings.ShowGoalInfo.Value)
{
foreach (var cachedText in _cachedRewardText)
{
Graphics.DrawTextWithBackground(cachedText.Text, cachedText.Position, cachedText.Color, FontAlign.Left, backgroundColor);
}
}
if (Settings.ShowButtons.Value)
{
foreach (var cachedText in _cachedChoiceScores)
{
Graphics.DrawTextWithBackground(cachedText.Text, cachedText.Position, cachedText.Color, FontAlign.Left, backgroundColor);
}
}
if (Settings.EnableDebugDrawing.Value)
{
var y = advisorBottomY + SyndicateHelperConstants.DebugDrawPositionY;
var a = new System.Numerics.Vector2(SyndicateHelperConstants.DebugDrawPositionX, y);
Graphics.DrawTextWithBackground(
$"Prison: {_imprisonedMemberCount}/{SyndicateHelperConstants.MaxPrisonSlots} slots filled.",
a, Color.White, FontAlign.Left, backgroundColor);
a.Y += SyndicateHelperConstants.DebugLineSpacing;
foreach (var msg in _debugMessages)
{
Graphics.DrawTextWithBackground(msg, a, Color.White, FontAlign.Left, backgroundColor);
a.Y += SyndicateHelperConstants.DebugLineSpacing;
}
if (Settings.DrawPortraits.Value)
{
foreach (var portrait in _cachedPortraitElements.Values)
{
if (portrait?.GetClientRectCache != null)
{
var portraitRect = portrait.GetClientRectCache;
if (IsValidRect(portraitRect))
{
Graphics.DrawFrame(portraitRect, Color.Cyan, 1);
}
}
}
}
if (Settings.DrawRelations.Value)
{
foreach (var relation in _cachedRelationshipElements)
{
if (relation?.GetClientRectCache != null)
{
var relationRect = relation.GetClientRectCache;
if (IsValidRect(relationRect))
{
Graphics.DrawFrame(relationRect, Color.Magenta, 1);
}
}
}
}
if (_availableSafehouseDivision != SyndicateDivision.None)
{
a.Y += SyndicateHelperConstants.DebugLineSpacing;
Graphics.DrawTextWithBackground(
$"Safehouse ready: {_availableSafehouseDivision}",
a, Color.LimeGreen, FontAlign.Left, backgroundColor);
}
}
}
catch (Exception ex)
{
LogError($"SyndicateHelper Render error: {ex.Message}");
}
}
private void ProcessEncounterChoices(BetrayalEventData eventDataElement)
{
_lastChoices.Clear();
if (_lastDecision == null) return;
_lastChoices.Add(new EvaluatedChoice { Name = "Interrogate", Score = _strategyEvaluator.ScoreChoiceByCode("Interrogate", _lastDecision), Button = _lastDecision.InterrogateButton });
var specialActionId = eventDataElement.Action?.Id;
if (!string.IsNullOrWhiteSpace(specialActionId))
{
_lastChoices.Add(new EvaluatedChoice { Name = specialActionId, Score = _strategyEvaluator.ScoreChoiceByCode(specialActionId, _lastDecision), Button = _lastDecision.SpecialButton });
}
_lastChoices.Add(new EvaluatedChoice { Name = "Release", Score = 0, Button = _lastDecision.ReleaseButton });
foreach(var choice in _lastChoices) { AddDebug($"Choice: {choice.Name}, Score: {choice.Score}"); }
}
private void ProcessChoiceHighlights()
{
if (_lastDecision == null || _lastChoices.Count == 0) return;
_highlightedButtonAddresses.Clear();
var sortedGoals = _strategicGoals.OrderBy(g => g.Priority).ToList();
for (int i = 0; i < sortedGoals.Count && i < _goalRects.Count; i++)
{
var goal = sortedGoals[i];
var goalRect = _goalRects[i];
bool specialCompletes = ChoiceAccomplishesGoal(_lastDecision.SpecialText, goal.Text, _lastDecision.MemberName, _boardState);
bool interrogateCompletes = ChoiceAccomplishesGoal("Interrogate", goal.Text, _lastDecision.MemberName, _boardState);
var buttonToHighlight = specialCompletes ? _lastDecision.SpecialButton : (interrogateCompletes ? _lastDecision.InterrogateButton : null);
if (IsValidButton(buttonToHighlight))
{
var buttonRect = buttonToHighlight.GetClientRectCache;
if (IsValidRect(goalRect) && IsValidRect(buttonRect))
{
_rectanglesToDraw.Add(new Tuple<RectangleF, Color>(goalRect, Settings.GoalCompletionColor.Value));
_rectanglesToDraw.Add(new Tuple<RectangleF, Color>(buttonRect, Settings.GoalCompletionColor.Value));
_highlightedButtonAddresses.Add(buttonToHighlight.Address);
}
}
}
var bestChoice = _lastChoices.OrderByDescending(c => c.Score).FirstOrDefault();
if (bestChoice.Button == null) return;
foreach (var choice in _lastChoices)
{
var buttonRect = choice.Button?.GetClientRectCache ?? RectangleF.Empty;
if (!IsValidRect(buttonRect)) continue;
if (!choice.Button.IsVisible) continue;
var scoreText = $"[{choice.Score}]";
var textSize = Graphics.MeasureText(scoreText, SyndicateHelperConstants.DefaultFontSize);
var textPos = new System.Numerics.Vector2(
buttonRect.Right + SyndicateHelperConstants.ScoreTextOffsetX,
buttonRect.Center.Y - textSize.Y / 2 - SyndicateHelperConstants.ScoreTextOffsetY);
if (_highlightedButtonAddresses.Contains(choice.Button.Address))
{
_cachedChoiceScores.Add(new CachedText { Text = scoreText, Size = textSize, Position = textPos, Color = Settings.GoalCompletionColor.Value });
continue;
}
var scoreColor = choice.Score > 0 ? Settings.GoodChoiceColor.Value :
choice.Score == 0 ? Settings.NeutralChoiceColor.Value : Settings.BadChoiceColor.Value;
_cachedChoiceScores.Add(new CachedText { Text = scoreText, Size = textSize, Position = textPos, Color = scoreColor });
if (choice.Score == bestChoice.Score)
{
_rectanglesToDraw.Add(new Tuple<RectangleF, Color>(buttonRect, scoreColor));
}
else if (choice.Score < 0)
{
_rectanglesToDraw.Add(new Tuple<RectangleF, Color>(buttonRect, Settings.BadChoiceColor.Value));
}
}
if (Settings.EnableAnimations.Value && IsValidButton(bestChoice.Button))
{
var bestButtonRect = bestChoice.Button.GetClientRectCache;
if (IsValidRect(bestButtonRect))
{
var scoreColor = _highlightedButtonAddresses.Contains(bestChoice.Button.Address)
? Settings.GoalCompletionColor.Value
: bestChoice.Score > 0 ? Settings.GoodChoiceColor.Value :
bestChoice.Score == 0 ? Settings.NeutralChoiceColor.Value : Settings.BadChoiceColor.Value;
SyndicateHelperUtility.DrawSnakeEffect(
bestButtonRect,
scoreColor,
Settings.AnimationSpeed.Value,
Settings.AnimationIntensity.Value,
Graphics.DrawBox
);
}
}
}
private void UpdateBoardAndPrisonState(SyndicatePanel betrayalWindow)
{
var newBoardState = new Dictionary<string, SyndicateMemberState>();
var prisonCount = 0;
if (betrayalWindow?.SyndicateStates == null)
{
return;
}
var leaders = betrayalWindow.SyndicateLeadersData?.Leaders?
.Where(l => l?.Target != null)
.Select(l => l.Target.Name)
.Where(name => !string.IsNullOrWhiteSpace(name))
.ToHashSet();
if (leaders == null)
{
leaders = new HashSet<string>();
}
foreach (var memberState in betrayalWindow.SyndicateStates)
{
var memberName = memberState?.Target?.Name;
if (string.IsNullOrWhiteSpace(memberName)) continue;
var rankName = memberState?.Rank?.Name;
var jobName = memberState?.Job?.Name;
if (Enum.TryParse(jobName, out SyndicateDivision division) ||
jobName == "None" ||
!string.IsNullOrWhiteSpace(rankName))
{
var state = new SyndicateMemberState
{
Name = memberName,
Rank = rankName ?? string.Empty,
Division = division,
IsLeader = leaders.Contains(memberName)
};
newBoardState[memberName] = state;
if (IsMemberImprisoned(memberState?.UIElement)) prisonCount++;
}
}
_boardState = newBoardState;
_imprisonedMemberCount = prisonCount;
foreach (var relElement in _cachedRelationshipElements)
{
var text = relElement?.Text;
if (string.IsNullOrWhiteSpace(text)) continue;
var match = Regex.Match(text, @"(.+?)\s+(is friends with|is rivals with)\s+(.+)", RegexOptions.IgnoreCase);
if (match.Success)
{
var member1Name = match.Groups[1].Value.Trim();
var relationshipType = match.Groups[2].Value.Trim();
var member2Name = match.Groups[3].Value.Trim();
if (newBoardState.TryGetValue(member1Name, out var member1State) &&
newBoardState.TryGetValue(member2Name, out var member2State))
{
if (relationshipType.Equals("is friends with", StringComparison.OrdinalIgnoreCase))
{
member1State.Friends.Add(member2Name);
member2State.Friends.Add(member1Name);
}
else if (relationshipType.Equals("is rivals with", StringComparison.OrdinalIgnoreCase))
{
member1State.Rivals.Add(member2Name);
member2State.Rivals.Add(member1Name);
}
}
}
}
}
private bool IsMemberImprisoned(Element element)
{
if (element == null || !element.IsVisible) return false;
var text = SyndicateHelperUtility.GetElementTextSafely(element);
if (text.Contains("Turn Left", StringComparison.OrdinalIgnoreCase) ||
text.Contains("Turns Left", StringComparison.OrdinalIgnoreCase))
{
return true;
}
foreach (var child in element?.Children)
{
if (IsMemberImprisoned(child)) return true;
}
return false;
}
private float RenderStrategyAdvisorImGui(SyndicatePanel betrayalWindow)
{
var panelWidth = 280;
var windowPos = new System.Numerics.Vector2(SyndicateHelperConstants.DefaultDrawPositionX, SyndicateHelperConstants.DefaultDrawPositionY);
ImGui.SetNextWindowPos(windowPos, ImGuiCond.FirstUseEver);
ImGui.SetNextWindowSize(new System.Numerics.Vector2(panelWidth, 400), ImGuiCond.FirstUseEver);
ImGui.PushStyleColor(ImGuiCol.WindowBg, new System.Numerics.Vector4(0.08f, 0.08f, 0.1f, 0.85f));
ImGui.PushStyleColor(ImGuiCol.TitleBg, new System.Numerics.Vector4(0.15f, 0.15f, 0.2f, 0.9f));
ImGui.PushStyleColor(ImGuiCol.TitleBgActive, new System.Numerics.Vector4(0.2f, 0.2f, 0.25f, 0.95f));
ImGui.PushStyleColor(ImGuiCol.Border, new System.Numerics.Vector4(0.3f, 0.3f, 0.35f, 0.5f));
ImGui.PushStyleColor(ImGuiCol.Header, new System.Numerics.Vector4(0.2f, 0.2f, 0.25f, 0.6f));
ImGui.PushStyleColor(ImGuiCol.HeaderHovered, new System.Numerics.Vector4(0.25f, 0.25f, 0.3f, 0.7f));
ImGui.PushStyleColor(ImGuiCol.HeaderActive, new System.Numerics.Vector4(0.3f, 0.3f, 0.35f, 0.8f));
ImGui.PushStyleColor(ImGuiCol.Text, new System.Numerics.Vector4(1f, 1f, 1f, 1f));
ImGui.PushStyleColor(ImGuiCol.TextDisabled, new System.Numerics.Vector4(0.5f, 0.5f, 0.5f, 1f));
var windowFlags = ImGuiWindowFlags.NoScrollbar | ImGuiWindowFlags.AlwaysAutoResize;
if (!ImGui.Begin("Strategy Advisor", windowFlags))
{
ImGui.PopStyleColor(9);
ImGui.End();
return windowPos.Y;
}
var strategyNames = SyndicateStrategies.Strategies.Select(s => s.Name).ToList();
strategyNames.Insert(0, "Custom");
var currentStrategy = Settings.StrategyProfile.Value ?? "Custom";