-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainDialog.cs
177 lines (143 loc) · 7.15 KB
/
MainDialog.cs
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
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by:
// TerminalGuiDesigner v1.1.0.0
// You can make changes to this file and they will not be overwritten when saving.
// </auto-generated>
// -----------------------------------------------------------------------------
namespace GreatRune
{
using System.Diagnostics;
using GreatRune.GameManagers;
using Terminal.Gui;
using static GreatRune.GameManagers.RunesHelper;
using System.Diagnostics.CodeAnalysis;
public partial class MainDialog
{
private string lblStatusOriginalText;
private readonly object timerToken;
private readonly MemoryManager memoryManager = new();
private readonly ProcessSelectorFSM processSelectorFSM;
const string EldenRingProcessName = "eldenring";
Dictionary<Terminal.Gui.Label, int> LabelGreatRuneID_Dict = new();
public MainDialog()
{
InitializeComponent();
processSelectorFSM = new ProcessSelectorFSM(EldenRingProcessName, memoryManager);
timerToken = Application.MainLoop.AddTimeout(TimeSpan.FromMilliseconds(1000), TimerTick);
btnQuit.Clicked += () =>
{
Application.MainLoop.RemoveTimeout(timerToken);
Application.RequestStop();
};
this.lblStatusOriginalText = lblStatus.Text.ToString();
lblStatus.ColorScheme = null;
lblStatus.Enabled = false;
LabelGreatRuneID_Dict[lblGodrick] = 0x4000_0000 | (int)GreatRunesID.GODRICK_S_GREAT_RUNE;
LabelGreatRuneID_Dict[lblMalenia] = 0x4000_0000 | (int)GreatRunesID.MALENIA_S_GREAT_RUNE;
LabelGreatRuneID_Dict[lblMohg] = 0x4000_0000 | (int)GreatRunesID.MOHG_S_GREAT_RUNE;
LabelGreatRuneID_Dict[lblMorgott] = 0x4000_0000 | (int)GreatRunesID.MORGOTT_S_GREAT_RUNE;
LabelGreatRuneID_Dict[lblRadahn] = 0x4000_0000 | (int)GreatRunesID.RADAHN_S_GREAT_RUNE;
LabelGreatRuneID_Dict[lblRykard] = 0x4000_0000 | (int)GreatRunesID.RYKARD_S_GREAT_RUNE;
foreach (var label in LabelGreatRuneID_Dict.Keys)
label.Clicked += () => { LabelClicked(label); };
}
private void LabelClicked(Terminal.Gui.Label label)
{
if (!memoryManager.IsOpen || // process not open
label.ColorScheme == gold || // rune already activated
label.Text.ToString()[0] =='-' || // rune not in invetory
// message box answered "No"
(0 != MessageBox.Query("GreatRune", $"Activate {label.Text.ToString().Substring(2)} great rune?", new NStack.ustring[] { "Yes", "No" })))
return;
SpawnItem(LabelGreatRuneID_Dict[label]);
}
#nullable enable
Process? _gameProcess;
public Process? GameProcess
{
get { return _gameProcess; }
private set
{
chkAuto.Enabled = (value != null);
if (_gameProcess != value)
{
chkAuto.Checked = false;
lblStatus.Text = (value != null) ? $" Process found, ID : {value.Id}" : lblStatusOriginalText;
lblStatus.ColorScheme = (value != null) ? gold : null;
}
_gameProcess = value;
}
}
private bool TimerTick(MainLoop mainLoop)
{
processSelectorFSM.Update(out Process? process);
Application.MainLoop.Invoke(() => { GameProcess = process; });
if (!memoryManager.IsOpen)
return true;
ReadGreatRunes(out GreatRunesRecord greatRunes, out GreatRunesRecord activatedRunes);
UpdateInterface(greatRunes, activatedRunes);
if (chkAuto.Checked)
ActivateRunes(greatRunes, activatedRunes);
return true;
}
private void ActivateRunes(GreatRunesRecord greatRunes, GreatRunesRecord activatedRunes)
{
if (greatRunes.Godrick && !activatedRunes.Godrick)
SpawnItem((int)GreatRunesID.GODRICK_S_GREAT_RUNE | 0x4000_0000);
if (greatRunes.Malenia && !activatedRunes.Malenia)
SpawnItem((int)GreatRunesID.MALENIA_S_GREAT_RUNE | 0x4000_0000);
if (greatRunes.Mohg && !activatedRunes.Mohg)
SpawnItem((int)GreatRunesID.MOHG_S_GREAT_RUNE | 0x4000_0000);
if (greatRunes.Morgott && !activatedRunes.Morgott)
SpawnItem((int)GreatRunesID.MORGOTT_S_GREAT_RUNE | 0x4000_0000);
if (greatRunes.Radahn && !activatedRunes.Radahn)
SpawnItem((int)GreatRunesID.RADAHN_S_GREAT_RUNE | 0x4000_0000);
if (greatRunes.Rykard && !activatedRunes.Rykard)
SpawnItem((int)GreatRunesID.RYKARD_S_GREAT_RUNE | 0x4000_0000);
}
private void SpawnItem(int id)
{
memoryManager.ItemGib(id, 1);
}
private void UpdateLabelText(Terminal.Gui.Label label, bool enabled)
{
if (label == null)
return;
var text = label?.Text?.ToString()?.Substring(1);
text = (enabled ? "√" : "-") + text;
label.Text = text;
}
private void UpdateInterface(GreatRunesRecord greatRunes, GreatRunesRecord activatedRunes)
{
Application.MainLoop.Invoke(() =>
{
UpdateLabelText(lblGodrick, greatRunes.Godrick | activatedRunes.Godrick);
UpdateLabelText(lblMalenia, greatRunes.Malenia | activatedRunes.Malenia);
UpdateLabelText(lblMohg, greatRunes.Mohg | activatedRunes.Mohg);
UpdateLabelText(lblMorgott, greatRunes.Morgott | activatedRunes.Morgott);
UpdateLabelText(lblRadahn, greatRunes.Radahn | activatedRunes.Radahn);
UpdateLabelText(lblRennala, greatRunes.Rennala | activatedRunes.Rennala);
UpdateLabelText(lblRykard, greatRunes.Rykard | activatedRunes.Rykard);
lblGodrick.ColorScheme = activatedRunes.Godrick ? gold : null;
lblMalenia.ColorScheme = activatedRunes.Malenia ? gold : null;
lblMohg.ColorScheme = activatedRunes.Mohg ? gold : null;
lblMorgott.ColorScheme = activatedRunes.Morgott ? gold : null;
lblRadahn.ColorScheme = activatedRunes.Radahn ? gold : null;
lblRennala.ColorScheme = activatedRunes.Rennala ? gold : null;
lblRykard.ColorScheme = activatedRunes.Rykard ? gold : null;
});
}
private void ReadGreatRunes(out GreatRunesRecord greatRunes, out GreatRunesRecord activatedRunes)
{
if (!memoryManager.UpdateInventory())
{
greatRunes = new(false, false, false, false, false, false, false);
activatedRunes = new(false, false, false, false, false, false, false);
return;
}
greatRunes = RunesHelper.GreatRunes(memoryManager.InventoryItems);
activatedRunes = RunesHelper.ActivatedRunes(memoryManager.InventoryItems);
}
}
}