This repository has been archived by the owner on Feb 27, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
415 lines (318 loc) · 12.8 KB
/
MainWindow.xaml.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
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
using System.Windows;
using System.Windows.Input;
using MahApps.Metro.Controls;
using System.Text.RegularExpressions;
using System.Linq;
using System.Xml.Linq;
using System.IO;
using System.Diagnostics;
using System.Windows.Controls;
using EliteMMO.API;
using System.Windows.Media;
using System;
using System.ComponentModel;
using System.Threading;
using System.Runtime.InteropServices;
using WinningMarbles;
using System.Collections.Generic;
namespace FFXI_MarbleChecker
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow
{
private static BackgroundWorker backgroundWorker;
public int characterSelected = 0;
public int firstSelect = 0;
public bool automaticCheck = false;
public ListBox processids = new ListBox();
public static EliteAPI api;
public MainWindow()
{
InitializeComponent();
backgroundWorker = new BackgroundWorker
{
WorkerReportsProgress = true,
WorkerSupportsCancellation = true
};
backgroundWorker.DoWork += BackgroundWorker_DoWork;
backgroundWorker.RunWorkerCompleted += BackgroundWorker_RunWorkerCompleted;
if (File.Exists("eliteapi.dll") && File.Exists("elitemmo.api.dll"))
{
automaticCheck = true;
var pol = Process.GetProcessesByName("pol");
if (pol.Length < 1)
{
MessageBox.Show("FFXI not found");
}
else
{
for (var i = 0; i < pol.Length; i++)
{
this.POLID.Items.Add(pol[i].MainWindowTitle);
this.processids.Items.Add(pol[i].Id);
}
this.POLID.SelectedIndex = 0;
this.processids.SelectedIndex = 0;
}
}
if (automaticCheck == false)
{
automaticCheck_enabled.IsEnabled = false;
}
XDocument xdoc = XDocument.Load("data/WinningNumbers.xml");
var lv1s = from lv1 in xdoc.Descendants("WinningNumbers")
select new
{
Children = lv1.Descendants("rank")
};
//Loop through results
foreach (var lv1 in lv1s)
{
foreach (var lv2 in lv1.Children)
{
if (lv2.Attribute("name").Value == "1")
{
this.rank1.Text = lv2.Value;
} else if (lv2.Attribute("name").Value == "2")
{
this.rank2.Text = lv2.Value;
}
else if (lv2.Attribute("name").Value == "3")
{
this.rank3.Text = lv2.Value;
}
else if (lv2.Attribute("name").Value == "4")
{
this.rank4.Text = lv2.Value;
}
else if (lv2.Attribute("name").Value == "5")
{
this.rank5.Text = lv2.Value;
}
}
}
}
private void NumberValidationTextBox(object sender, TextCompositionEventArgs e)
{
Regex regex = new Regex("[^0-9]+");
e.Handled = regex.IsMatch(e.Text);
}
private void BeginCheck_Click(object sender, RoutedEventArgs e)
{
bool isWindowOpen = false;
foreach (Window w in Application.Current.Windows)
{
if (w is winningMarbles)
{
isWindowOpen = true;
w.Activate();
}
}
if (!isWindowOpen)
{
winningMarbles subWindow = new winningMarbles();
subWindow.Show();
}
}
private void AddMarble_Click(object sender, RoutedEventArgs e)
{
// characterName
// MarbleNumber
XDocument xdoc = XDocument.Load("data/CharacterData.xml");
int foundCharacter = 0;
// First check you don't have more than 10 marbles on this character
var lv1s = from lv1 in xdoc.Descendants("character")
select new
{
Header = lv1.Attribute("name").Value,
Children = lv1.Descendants("marble")
};
foreach (var lv1 in lv1s)
{
if (lv1.Header == characterName.Text)
{
foundCharacter = 1;
if (lv1.Children.Count() >= 10)
{
MessageBox.Show("This characters count is at "+lv1.Children.Count()+"/10 and can not hold anymore. Cancelling!");
}
else
{
// Reached a line that doesn't seem to exist so create it.
xdoc.Element("Characters").Elements("character")
.First(c => (string)c.Attribute("name") == characterName.Text).Add
(
new XElement
(
"marble", MarbleNumber.Text
)
);
xdoc.Save("data/CharacterData.xml");
MessageBox.Show("Added marble: " + MarbleNumber.Text + " to character: " + characterName.Text);
}
}
}
if (foundCharacter != 1)
{
xdoc.Element("Characters").Add(new XElement("character", new XAttribute("name", characterName.Text)));
xdoc.Save("data/CharacterData.xml");
// Reached a line that doesn't seem to exist so create it.
xdoc.Element("Characters").Elements("character")
.First(c => (string)c.Attribute("name") == characterName.Text).Add
(
new XElement
(
"marble", MarbleNumber.Text
)
);
xdoc.Save("data/CharacterData.xml");
MessageBox.Show("Added marble: " + MarbleNumber.Text + " to character: " + characterName.Text);
}
}
private void EditMarbles_Click(object sender, RoutedEventArgs e)
{
bool isWindowOpen = false;
foreach (Window w in Application.Current.Windows)
{
if (w is marbleViewer)
{
isWindowOpen = true;
w.Activate();
}
}
if (!isWindowOpen)
{
marbleViewer subWindow = new marbleViewer();
subWindow.Show();
}
}
private void RefreshButton_Click(object sender, RoutedEventArgs e)
{
// LOAD XML FILE AND PROCESS WINNING NUMBERS
//Load xml
XDocument xdoc = XDocument.Load("data/WinningNumbers.xml");
var lv1s = from lv1 in xdoc.Descendants("WinningNumbers")
select new
{
Children = lv1.Descendants("rank")
};
foreach (var lv1 in lv1s)
{
foreach (var lv2 in lv1.Children)
{
if (lv2.Attribute("name").Value == "1")
{
this.rank1.Text = lv2.Value;
}
else if (lv2.Attribute("name").Value == "2")
{
this.rank2.Text = lv2.Value;
}
else if (lv2.Attribute("name").Value == "3")
{
this.rank3.Text = lv2.Value;
}
else if (lv2.Attribute("name").Value == "4")
{
this.rank4.Text = lv2.Value;
}
else if (lv2.Attribute("name").Value == "5")
{
this.rank5.Text = lv2.Value;
}
}
}
}
private void MetroWindow_Closing(object sender, System.ComponentModel.CancelEventArgs e)
{
App.Current.Shutdown();
}
private void SelectPOLIDButton_Click(object sender, RoutedEventArgs e)
{
this.processids.SelectedIndex = this.POLID.SelectedIndex;
api = new EliteAPI((int)this.processids.SelectedItem);
this.SelectPOLID.Content = "SELECTED";
this.SelectPOLID.Background = Brushes.LightGreen;
EliteAPI.ChatEntry cl = api.Chat.GetNextChatLine();
while (cl != null) cl = api.Chat.GetNextChatLine();
if (firstSelect == 0)
{
backgroundWorker.RunWorkerAsync();
}
}
public string numberFound = "0";
public void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e)
{
EliteAPI.ChatEntry cl = api.Chat.GetNextChatLine();
while (cl != null)
{
//Trace.WriteLine(string.Format("type:{0} idx1:{1} idx2:{2} {3}", cl.ChatType, cl.Index1, cl.Index2, cl.Text));
// First appearance will be the selected number.
Match m = Regex.Match(cl.Text, @"Bonanza Moogle : (?<name>\d+).");
if (m.Success)
{
// Number found store this until confirmed.
numberFound = m.Groups["name"].Value;
}
// Confirmation verified, add to the XML
if (cl.Text == "Bonanza Moogle : Thank you, and good luck, kupo!")
{
Add_Marble(api.Player.Name, numberFound);
}
cl = api.Chat.GetNextChatLine();
}
Thread.Sleep(TimeSpan.FromSeconds(0.1));
}
private void BackgroundWorker_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
{
// Thread.Sleep(500);
backgroundWorker.RunWorkerAsync();
}
private void Add_Marble(string character_name, string marble_number)
{
XDocument xdoc = XDocument.Load("data/CharacterData.xml");
int foundCharacter = 0;
// First check you don't have more than 10 marbles on this character
var lv1s = from lv1 in xdoc.Descendants("character")
select new
{
Header = lv1.Attribute("name").Value,
Children = lv1.Descendants("marble")
};
foreach (var lv1 in lv1s)
{
if (lv1.Header == character_name)
{
foundCharacter = 1;
// Reached a line that doesn't seem to exist so create it.
xdoc.Element("Characters").Elements("character")
.First(c => (string)c.Attribute("name") == character_name).Add
(
new XElement
(
"marble", marble_number
)
);
xdoc.Save("data/CharacterData.xml");
}
}
if (foundCharacter != 1)
{
xdoc.Element("Characters").Add(new XElement("character", new XAttribute("name", character_name)));
xdoc.Save("data/CharacterData.xml");
// Reached a line that doesn't seem to exist so create it.
xdoc.Element("Characters").Elements("character")
.First(c => (string)c.Attribute("name") == character_name).Add
(
new XElement
(
"marble", marble_number
)
);
xdoc.Save("data/CharacterData.xml");
}
}
}
}