forked from lllsondowlll/botw-trainer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
1657 lines (1353 loc) · 58.2 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
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
namespace BotwTrainer
{
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Navigation;
using BotwTrainer.Properties;
using Newtonsoft.Json.Linq;
/// <summary>
/// Interaction logic for MainWindow
/// </summary>
public partial class MainWindow
{
// The original list of values that take effect when you save / load
private const uint SaveItemStart = 0x3FCE7FF0;
// Technically your first item as they are stored in reverse so we work backwards
private const uint ItemEnd = 0x43CA2AEC;
private const uint ItemStart = 0x43C6B2AC;
private const uint CodeHandlerStart = 0x01133000;
private const uint CodeHandlerEnd = 0x01134300;
private const uint CodeHandlerEnabled = 0x10014CFC;
private readonly List<TextBox> tbChanged = new List<TextBox>();
private readonly List<ComboBox> ddChanged = new List<ComboBox>();
private readonly List<CheckBox> cbChanged = new List<CheckBox>();
private List<Item> items;
private List<uint> codes;
private JToken json;
private TcpConn tcpConn;
private Gecko gecko;
private int itemsFound;
private bool connected;
public MainWindow()
{
this.InitializeComponent();
this.Loaded += this.MainWindowLoaded;
}
private enum Cheat
{
Stamina = 0,
Health = 1,
//Run = 2,
Rupees = 3,
MoonJump = 4,
WeaponInv = 5,
BowInv = 6,
ShieldInv = 7,
Speed = 8,
Mon = 9,
Urbosa = 10,
Revali = 11,
Daruk = 12,
//Keys = 13,
Bombs = 14,
Whips = 15
}
private bool HasChanged
{
get
{
return this.tbChanged.Any() || this.cbChanged.Any() || this.ddChanged.Any();
}
}
private void MainWindowLoaded(object sender, RoutedEventArgs e)
{
this.Title = string.Format("{0} v{1}", this.Title, Settings.Default.CurrentVersion);
this.items = new List<Item>();
this.codes = new List<uint>();
var client = new WebClient
{
BaseAddress = Settings.Default.VersionUrl,
Encoding = Encoding.UTF8,
CachePolicy =
new System.Net.Cache.RequestCachePolicy(
System.Net.Cache.RequestCacheLevel.BypassCache)
};
client.Headers.Add("Cache-Control", "no-cache");
client.DownloadStringCompleted += this.ClientDownloadStringCompleted;
// try to get current version
try
{
client.DownloadStringAsync(new Uri(string.Format("{0}{1}", client.BaseAddress, "version.txt")));
}
catch (Exception ex)
{
this.LogError(ex, "Error loading current version.");
}
// try to load json data
try
{
var file = Assembly.GetExecutingAssembly().GetManifestResourceStream("BotwTrainer.items.json");
using (var reader = new StreamReader(file))
{
var data = reader.ReadToEnd();
this.json = JObject.Parse(data);
JsonViewer.Load(data);
// Shrine data
var shrines = this.json.SelectToken("Shrines").Value<JObject>().Properties().ToList().OrderBy(x => x.Name);
foreach (var shrine in shrines)
{
ShrineList.Items.Add(new ComboBoxItem { Content = shrine.Value["Name"], Tag = shrine.Name });
}
// Tower data
var towers = this.json.SelectToken("Towers").Value<JObject>().Properties().ToList().OrderBy(x => x.Name);
foreach (var tower in towers)
{
TowerList.Items.Add(new ComboBoxItem { Content = tower.Value["Name"], Tag = tower.Name });
}
}
}
catch (Exception ex)
{
this.LogError(ex, "Error loading json.");
}
IpAddress.Text = Settings.Default.IpAddress;
this.Save.IsEnabled = this.HasChanged;
}
private bool LoadData()
{
try
{
var x = 0;
var currentItemAddress = ItemEnd;
while (currentItemAddress >= ItemStart)
{
var itemData = this.gecko.ReadBytes(currentItemAddress, 0x70);
var page = BitConverter.ToInt32(itemData.Take(4).Skip(0).Reverse().ToArray(), 0);
if (page > 9 || page < 0)
{
var percent = (100m / 418m) * x;
Dispatcher.Invoke(
() =>
{
ProgressText.Text = string.Format("{0}/{1}", x, 418);
this.UpdateProgress(Convert.ToInt32(percent));
});
currentItemAddress -= 0x220;
x++;
continue;
}
int unknown = BitConverter.ToInt32(itemData.Skip(4).Take(4).Reverse().ToArray(), 0);
var value = BitConverter.ToUInt32(itemData.Skip(8).Take(4).Reverse().ToArray(), 0);
var equipped = BitConverter.ToUInt32(itemData.Skip(12).Take(4).ToArray(), 0);
uint nameStart = currentItemAddress + 0x1C;
var builder = new StringBuilder();
for (var i = 0; i < 36; i++)
{
var data = itemData.Skip(i + 28).Take(1).ToArray()[0];
if (data == 0)
{
break;
}
builder.Append((char)data);
}
var id = builder.ToString();
if (string.IsNullOrEmpty(id))
{
throw new Exception("Can't read item at address: 0x" + nameStart.ToString("x8").ToUpper());
}
var item = new Item
{
BaseAddress = currentItemAddress,
Page = page,
Unknown = unknown,
Value = value,
Equipped = equipped,
NameStart = nameStart,
Id = id,
Modifier1Value = this.gecko.ByteToHexBitFiddle(itemData.Skip(92).Take(4).ToArray()),
Modifier2Value = this.gecko.ByteToHexBitFiddle(itemData.Skip(96).Take(4).ToArray()),
Modifier3Value = this.gecko.ByteToHexBitFiddle(itemData.Skip(100).Take(4).ToArray()),
Modifier4Value = this.gecko.ByteToHexBitFiddle(itemData.Skip(104).Take(4).ToArray()),
Modifier5Value = this.gecko.ByteToHexBitFiddle(itemData.Skip(108).Take(4).ToArray())
};
// look for name in json
var name = this.GetNameFromId(item.Id, item.PageName);
item.Name = name;
this.items.Add(item);
var currentPercent = (100m / 418m) * x;
Dispatcher.Invoke(
() =>
{
ProgressText.Text = string.Format("{0}/{1}", x, 418);
this.UpdateProgress(Convert.ToInt32(currentPercent));
});
currentItemAddress -= 0x220;
x++;
}
this.itemsFound = this.items.Count;
return true;
}
catch (Exception ex)
{
Dispatcher.Invoke(() => this.LogError(ex));
return false;
}
}
private bool SaveData(TabItem tab)
{
// Clear old errors
ErrorLog.Document.Blocks.Clear();
if (!this.HasChanged)
{
// Nothing to update
return false;
}
#region SaveLoad
try
{
// For these we amend the 0x3FCE7FF0 area which requires save/load
if (Equals(tab, this.Weapons) || Equals(tab, this.Bows) || Equals(tab, this.Shields)
|| Equals(tab, this.Armor))
{
var weaponList = this.items.Where(x => x.Page == 0).ToList();
var bowList = this.items.Where(x => x.Page == 1).ToList();
var arrowList = this.items.Where(x => x.Page == 2).ToList();
var shieldList = this.items.Where(x => x.Page == 3).ToList();
var armorList = this.items.Where(x => x.Page == 4 || x.Page == 5 || x.Page == 6).ToList();
var y = 0;
if (Equals(tab, this.Weapons))
{
foreach (var item in weaponList)
{
var foundTextBox = (TextBox)this.FindName("Value_" + item.ValueAddressHex);
if (foundTextBox != null)
{
var offset = (uint)(SaveItemStart + (y * 0x8));
this.gecko.WriteUInt(offset, Convert.ToUInt32(foundTextBox.Text));
}
y++;
}
}
if (Equals(tab, this.Bows))
{
// jump past weapons before we start
y += weaponList.Count;
foreach (var item in bowList)
{
var foundTextBox = (TextBox)this.FindName("Value_" + item.ValueAddressHex);
if (foundTextBox != null)
{
var offset = (uint)(SaveItemStart + (y * 0x8));
this.gecko.WriteUInt(offset, Convert.ToUInt32(foundTextBox.Text));
}
y++;
}
}
if (Equals(tab, this.Shields))
{
// jump past weapons/bows/arrows before we start
y += weaponList.Count + bowList.Count + arrowList.Count;
foreach (var item in shieldList)
{
var foundTextBox = (TextBox)this.FindName("Value_" + item.ValueAddressHex);
if (foundTextBox != null)
{
var offset = (uint)(SaveItemStart + (y * 0x8));
this.gecko.WriteUInt(offset, Convert.ToUInt32(foundTextBox.Text));
}
y++;
}
}
if (Equals(tab, this.Armor))
{
// jump past weapons/bows/arrows/shields before we start
y += weaponList.Count + bowList.Count + arrowList.Count + shieldList.Count;
foreach (var item in armorList)
{
var offset = (uint)(SaveItemStart + (y * 0x8));
var foundTextBox = (TextBox)this.FindName("Value_" + item.ValueAddressHex);
if (foundTextBox != null)
{
this.gecko.WriteUInt(offset, Convert.ToUInt32(foundTextBox.Text));
}
y++;
}
}
}
}
catch (Exception ex)
{
this.LogError(ex, "Attempting to save data in 0x3FCE7FF0 region.");
}
#endregion
#region Modified
try
{
// Only update what has changed to avoid corruption.
foreach (var tb in this.tbChanged)
{
if (string.IsNullOrEmpty(tb.Text))
{
continue;
}
// These text boxes have been edited
var type = tb.Name.Split('_')[0];
var tag = tb.Tag;
if (type == "Id")
{
var newName = Encoding.Default.GetBytes(tb.Text);
var add = uint.Parse(tag.ToString(), NumberStyles.HexNumber);
var thisItem = this.items.Single(i => i.NameStart == add);
// clear current name
var zeros = new byte[36];
for (var i = 0; i < zeros.Length; i++)
{
zeros[i] = 0x0;
}
this.gecko.WriteBytes(add, zeros);
uint x = 0x0;
foreach (var b in newName)
{
this.gecko.WriteBytes(add + x, new[] { b });
x = x + 0x1;
}
thisItem.Id = tb.Text;
// Name
var foundTextBox = (TextBox)this.FindName("JsonName_" + tag);
if (foundTextBox != null)
{
foundTextBox.Text = this.GetNameFromId(thisItem.Id, thisItem.PageName);
}
}
if (type == "Value")
{
var address = uint.Parse(tag.ToString(), NumberStyles.HexNumber);
int val;
bool parsed = int.TryParse(tb.Text, out val);
if (parsed)
{
this.gecko.WriteUInt(address, Convert.ToUInt32(val));
}
}
if (type == "Page")
{
var address = uint.Parse(tag.ToString(), NumberStyles.HexNumber);
int val;
bool parsed = int.TryParse(tb.Text, out val);
if (parsed && val < 10 && val >= 0)
{
this.gecko.WriteUInt(address, Convert.ToUInt32(val));
}
}
if (type == "Mod")
{
var address = uint.Parse(tag.ToString(), NumberStyles.HexNumber);
uint val;
bool parsed = uint.TryParse(tb.Text, NumberStyles.HexNumber, CultureInfo.CurrentCulture, out val);
if (parsed)
{
this.gecko.WriteUInt(address, val);
}
}
}
}
catch (Exception ex)
{
this.LogError(ex, "Attempting to update changed fields");
}
#endregion
#region Codes
try
{
// For the 'Codes' tab we mimic JGecko and send cheats to codehandler
if (Equals(tab, this.Codes))
{
var selected = new List<Cheat>();
if (Stamina.IsChecked == true)
{
selected.Add(Cheat.Stamina);
}
if (Health.IsChecked == true)
{
selected.Add(Cheat.Health);
}
if (Rupees.IsChecked == true)
{
selected.Add(Cheat.Rupees);
}
if (Mon.IsChecked == true)
{
selected.Add(Cheat.Mon);
}
if (Speed.IsChecked == true)
{
selected.Add(Cheat.Speed);
}
if (MoonJump.IsChecked == true)
{
selected.Add(Cheat.MoonJump);
}
if (WeaponSlots.IsChecked == true)
{
selected.Add(Cheat.WeaponInv);
}
if (BowSlots.IsChecked == true)
{
selected.Add(Cheat.BowInv);
}
if (ShieldSlots.IsChecked == true)
{
selected.Add(Cheat.ShieldInv);
}
if (Urbosa.IsChecked == true)
{
selected.Add(Cheat.Urbosa);
}
if (Revali.IsChecked == true)
{
selected.Add(Cheat.Revali);
}
if (Daruk.IsChecked == true)
{
selected.Add(Cheat.Daruk);
}
if (BombTime.IsChecked == true)
{
selected.Add(Cheat.Bombs);
}
if (HorseWhips.IsChecked == true)
{
selected.Add(Cheat.Whips);
}
this.SetCheats(selected);
Settings.Default.Controller = Controller.SelectedValue.ToString();
Settings.Default.Save();
}
this.DebugData();
Debug.UpdateLayout();
// clear changed after save
this.tbChanged.Clear();
this.cbChanged.Clear();
this.ddChanged.Clear();
}
catch (Exception ex)
{
this.LogError(ex);
}
#endregion
return true;
}
private async void LoadClick(object sender, RoutedEventArgs e)
{
this.ToggleControls("Load");
this.items.Clear();
try
{
// talk to wii u and get mem dump of data
var result = await Task.Run(() => this.LoadData());
if (result)
{
this.DebugData();
this.LoadTab(this.Weapons, 0);
this.LoadTab(this.Bows, 1);
this.LoadTab(this.Arrows, 2);
this.LoadTab(this.Shields, 3);
this.LoadTab(this.Armor, 4);
this.LoadTab(this.Materials, 7);
this.LoadTab(this.Food, 8);
this.LoadTab(this.KeyItems, 9);
// Code Tab Values
CurrentStamina.Text = this.gecko.GetString(0x42439598);
var healthPointer = this.gecko.GetUInt(0x4225B4B0);
CurrentHealth.Text = this.gecko.GetInt(healthPointer + 0x430).ToString(CultureInfo.InvariantCulture);
CurrentRupees.Text = this.gecko.GetInt(0x4010AA0C).ToString(CultureInfo.InvariantCulture);
CurrentMon.Text = this.gecko.GetInt(0x4010B14C).ToString(CultureInfo.InvariantCulture);
CbSpeed.SelectedValue = this.gecko.GetString(0x439BF514);
CurrentWeaponSlots.Text = this.gecko.GetInt(0x3FCFB498).ToString(CultureInfo.InvariantCulture);
CurrentBowSlots.Text = this.gecko.GetInt(0x3FD4BB50).ToString(CultureInfo.InvariantCulture);
CurrentShieldSlots.Text = this.gecko.GetInt(0x3FCC0B40).ToString(CultureInfo.InvariantCulture);
CurrentUrbosa.Text = this.gecko.GetInt(0x3FCFFA80).ToString(CultureInfo.InvariantCulture);
CurrentRevali.Text = this.gecko.GetInt(0x3FD5ED90).ToString(CultureInfo.InvariantCulture);
CurrentDaruk.Text = this.gecko.GetInt(0x3FD50088).ToString(CultureInfo.InvariantCulture);
this.Notification.Content = string.Format("Items found: {0}", this.itemsFound);
this.ToggleControls("DataLoaded");
this.cbChanged.Clear();
this.tbChanged.Clear();
this.ddChanged.Clear();
this.Save.IsEnabled = this.HasChanged;
}
}
catch (Exception ex)
{
this.LogError(ex, "Load Data");
}
}
private void SaveClick(object sender, RoutedEventArgs e)
{
//var result = await Task.Run(() => this.SaveData((TabItem)TabControl.SelectedItem));
this.Save.IsEnabled = false;
var result = this.SaveData((TabItem)TabControl.SelectedItem);
if (!result)
{
MessageBox.Show("No changes have been made");
}
}
private void CoordsGoClick(object sender, RoutedEventArgs e)
{
var x = Convert.ToSingle(CoordsXValue.Text);
var y = Convert.ToSingle(CoordsYValue.Text);
var z = Convert.ToSingle(CoordsZValue.Text);
var xByte = BitConverter.GetBytes(x).Reverse().ToArray();
var yByte = BitConverter.GetBytes(y).Reverse().ToArray();
var zByte = BitConverter.GetBytes(z).Reverse().ToArray();
var ms = new MemoryStream();
ms.Write(xByte, 0, xByte.Length);
ms.Write(yByte, 0, yByte.Length);
ms.Write(zByte, 0, zByte.Length);
var bytes = ms.ToArray();
uint pointer = this.gecko.GetUInt(0x439BF794);
uint address = pointer + 0x140;
this.gecko.WriteBytes(address, bytes);
}
private void LoadCoords()
{
var run = false;
try
{
uint pointer = this.gecko.GetUInt(0x439BF794);
uint address = pointer + 0x140;
Dispatcher.Invoke(
() =>
{
run = this.connected && EnableCoords.IsChecked == true;
CoordsAddress.Content = "0x" + address.ToString("x8").ToUpper() + " <- Memory Address";
});
while (run)
{
var coords = this.gecko.ReadBytes(address, 0xC);
if (!coords.Any())
{
MessageBox.Show("No data found");
break;
}
var x = coords.Take(4).Reverse().ToArray();
var y = coords.Skip(4).Take(4).Reverse().ToArray();
var z = coords.Skip(8).Take(4).Reverse().ToArray();
var xFloat = BitConverter.ToSingle(x, 0);
var yFloat = BitConverter.ToSingle(y, 0);
var zFloat = BitConverter.ToSingle(z, 0);
Dispatcher.Invoke(
() =>
{
// previous float
var prevX = Convert.ToSingle(CoordsX.Content.ToString());
var prevZ = Convert.ToSingle(CoordsZ.Content.ToString());
CoordsX.Content = string.Format("{0}", Math.Round(xFloat, 2));
CoordsY.Content = string.Format("{0}", Math.Round(yFloat, 2));
CoordsZ.Content = string.Format("{0}", Math.Round(zFloat, 2));
run = this.connected && EnableCoords.IsChecked == true;
});
Thread.Sleep(1000);
}
}
catch (Exception ex)
{
Dispatcher.Invoke(() => this.LogError(ex, "Coords Tab"));
}
}
private void ConnectClick(object sender, RoutedEventArgs e)
{
try
{
this.tcpConn = new TcpConn(this.IpAddress.Text, 7331);
this.connected = this.tcpConn.Connect();
if (!this.connected)
{
this.LogError(new Exception("Failed to connect"));
return;
}
// init gecko
this.gecko = new Gecko(this.tcpConn, this);
if (this.connected)
{
var status = this.gecko.GetServerStatus();
if (status == 0)
{
return;
}
// Saved settings stuff
var shown = Settings.Default.Warning;
if (shown < 3)
{
Settings.Default.Warning++;
//MessageBox.Show("WARNING: Item names are now editable. Using bad data may mess up your game so use with care.");
}
Settings.Default.IpAddress = IpAddress.Text;
Settings.Default.Save();
Controller.SelectedValue = Settings.Default.Controller;
this.ToggleControls("Connected");
}
}
catch (System.Net.Sockets.SocketException)
{
this.connected = false;
MessageBox.Show("Wrong IP");
}
catch (Exception ex)
{
this.LogError(ex);
}
}
private void DisconnectClick(object sender, RoutedEventArgs e)
{
try
{
this.tcpConn.Close();
this.ToggleControls("Disconnected");
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
private void ExportClick(object sender, RoutedEventArgs e)
{
try
{
DebugGrid.SelectAllCells();
DebugGrid.ClipboardCopyMode = DataGridClipboardCopyMode.IncludeHeader;
ApplicationCommands.Copy.Execute(null, DebugGrid);
var result = (string)Clipboard.GetData(DataFormats.CommaSeparatedValue);
DebugGrid.UnselectAllCells();
var path = Environment.GetFolderPath(Environment.SpecialFolder.Desktop);
var excelFile = new StreamWriter(path + @"\debug.csv");
excelFile.WriteLine(result);
excelFile.Close();
MessageBox.Show("File exported to " + path);
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString(), "Excel Export");
}
}
private void TestClick(object sender, RoutedEventArgs e)
{
var server = this.gecko.GetServerVersion();
var os = this.gecko.GetOsVersion();
MessageBox.Show(string.Format("Server: {0}\nOs: {1}", server, os));
}
private void LoadTab(ContentControl tab, int page)
{
var scroll = new ScrollViewer { Name = "ScrollContent", Margin = new Thickness(10), VerticalAlignment = VerticalAlignment.Top };
var holder = new WrapPanel { Margin = new Thickness(0), VerticalAlignment = VerticalAlignment.Top };
// setup grid
var grid = this.GenerateTabGrid(tab.Name);
var x = 1;
var list = this.items.Where(i => i.Page == page).OrderByDescending(i => i.BaseAddress);
if (page == 4)
{
list = this.items.Where(i => i.Page == 4 || i.Page == 5 || i.Page == 6).OrderByDescending(i => i.BaseAddress);
}
foreach (var item in list)
{
grid.RowDefinitions.Add(new RowDefinition());
// Name - Readonly data
var name = new TextBox
{
Text = item.Name,
Margin = new Thickness(0),
BorderThickness = new Thickness(0),
Height = 22,
Width = 190,
IsReadOnly = true,
Name = "JsonName_" + item.NameStartHex
};
// we register the name so we can update it later without having to refresh
var check = (TextBox)this.FindName("JsonName_" + item.NameStartHex);
if (check != null)
{
this.UnregisterName("JsonName_" + item.NameStartHex);
}
this.RegisterName("JsonName_" + item.NameStartHex, name);
// Id
var id = new TextBox
{
Text = item.Id,
Tag = item.NameStartHex,
ToolTip = item.NameStartHex,
Margin = new Thickness(0),
Height = 22,
Width = 130,
IsReadOnly = false,
Name = "Id_" + item.NameStartHex
};
id.TextChanged += this.TextChanged;
check = (TextBox)this.FindName("Id_" + item.NameStartHex);
if (check != null)
{
this.UnregisterName("Id_" + item.NameStartHex);
}
this.RegisterName("Id_" + item.NameStartHex, id);
// Current item is red
if (item.EquippedBool)
{
id.Foreground = Brushes.Red;
name.Foreground = Brushes.Red;
}
// add first 2 fields
Grid.SetRow(name, x);
Grid.SetColumn(name, 0);
grid.Children.Add(name);
Grid.SetRow(id, x);
Grid.SetColumn(id, 1);
grid.Children.Add(id);
// Value to 0 if its FFFFF etc
var value = item.Value;
if (value > int.MaxValue)
{
value = 0;
}
var val = this.GenerateGridTextBox(value.ToString(), item.ValueAddressHex, "Value_", x, 2, 70);
val.PreviewTextInput += this.NumberValidationTextBox;
grid.Children.Add(val);
// Page
var pgtb = this.GenerateGridTextBox(item.Page.ToString(), item.BaseAddressHex, "Page_", x, 3, 20);
pgtb.PreviewTextInput += this.NumberValidationTextBox;
grid.Children.Add(pgtb);
// Mod1
var mtb1 = this.GenerateGridTextBox(item.Modifier1Value, item.Modifier1Address, "Mod_", x, 4, 70);
grid.Children.Add(mtb1);
// Mod2
var mtb2 = this.GenerateGridTextBox(item.Modifier2Value, item.Modifier2Address, "Mod_", x, 5, 70);
grid.Children.Add(mtb2);
// Mod3s
var mtb3 = this.GenerateGridTextBox(item.Modifier3Value, item.Modifier3Address, "Mod_", x, 6, 70);
grid.Children.Add(mtb3);
// Mod4
var mtb4 = this.GenerateGridTextBox(item.Modifier4Value, item.Modifier4Address, "Mod_", x, 7, 70);
grid.Children.Add(mtb4);
// Mod5
var mtb5 = this.GenerateGridTextBox(item.Modifier5Value, item.Modifier5Address, "Mod_", x, 8, 70);
grid.Children.Add(mtb5);
x++;
}
grid.Height = x * 35;
holder.Children.Add(new TextBox
{
Background = Brushes.Transparent,
BorderThickness = new Thickness(0),
Margin = new Thickness(20, 10, 0, 0),
IsReadOnly = true,
TextWrapping = TextWrapping.Wrap,
Text = "Items move around. What you see below may not be what is in memory. Refresh to get the latest data before you try to save anything.",
Foreground = Brushes.Red
});
holder.Children.Add(grid);
scroll.Content = holder;
tab.Content = scroll;
}
private void DebugData()
{
// Debug Grid data
DebugGrid.ItemsSource = this.items;
/*
try
{
// Show extra info in 'Codes' tab to see if our cheats are looking in the correct place
var stamina1 = this.gecko.GetString(0x42439594);
//var stamina2 = this.gecko.GetString(0x42439598);
this.StaminaData.Content = stamina1; //string.Format("[0x42439594 = {0}, 0x42439598 = {1}]", stamina1, stamina2);
var health1 = this.gecko.GetUInt(0x4225B4B0);
var health2 = this.gecko.GetString(health1 + 0x430);
this.HealthData.Content = health2; //string.Format("0x{0} = {1}", (health1 + 0430).ToString("x8").ToUpper(), health2);
var rupee1 = this.gecko.GetString(0x3FC92D10);
//var rupee2 = this.gecko.GetString(0x4010AA0C);
this.RupeeData.Content = rupee1; //string.Format("[0x3FC92D10 = {0}, 0x4010AA0C = {1}]", rupee1, rupee2);
var mon1 = this.gecko.GetString(0x3FD41158);
//var mon2 = this.gecko.GetString(0x4010B14C);
this.MonData.Content = mon1; //string.Format("[0x3FD41158 = {0}, 0x4010B14C = {1}]", mon1, mon2);
var run = this.gecko.GetString(0x43A88CC4);
this.RunData.Content = run; //string.Format("0x43A88CC4 = {0} (Redundant really due to speed code)", run);
var speed = this.gecko.GetString(0x439BF514);
this.SpeedData.Content = speed; //string.Format("0x439BF514 = {0}", speed);
var weapon1 = this.gecko.GetString(0x3FCFB498);
//var weapon2 = this.gecko.GetString(0x4010B34C);
this.WeaponSlotsData.Content = weapon1; //string.Format("[0x3FCFB498 = {0}, 0x4010B34C = {1}]", weapon1, weapon2);
var bow1 = this.gecko.GetString(0x3FD4BB50);
//var bow2 = this.gecko.GetString(0x4011126C);
this.BowSlotsData.Content = bow1; //string.Format("[0x3FD4BB50 = {0}, 0x4011126C = {1}]", bow1, bow2);
var shield1 = this.gecko.GetString(0x3FCC0B40);
//var shield2 = this.gecko.GetString(0x4011128C);
this.ShieldSlotsData.Content = shield1; //string.Format("[0x3FCC0B40 = {0}, 0x4011128C = {1}]", shield1, shield2);
var key1 = this.gecko.GetString(0x3FD5CB48);
//var key2 = this.gecko.GetString(0x3FF6EA00);
this.SmallKeysData.Content = key1; //string.Format("[0x3FD5CB48 = {0}, 0x3FF6EA00 = {1}]", key1, key2);
var urbosa1 = this.gecko.GetString(0x3FCFFA80);
//var urbosa2 = this.gecko.GetString(0x4011BA2C);
this.UrbosaData.Content = urbosa1; //string.Format("[0x3FCFFA80 = {0}, 0x4011BA2C = {1}]", urbosa1, urbosa2);
var revali1 = this.gecko.GetString(0x3FD5ED90);
//var revali2 = this.gecko.GetString(0x4011BA0C);
this.RevaliData.Content = revali1; //string.Format("[0x3FD5ED90 = {0}, 0x4011BA0C = {1}]", revali1, revali2);
var daruk1 = this.gecko.GetString(0x3FD50088);
//var daruk2 = this.gecko.GetString(0x4011B9EC);