-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathMainWindow.xaml.cs
2153 lines (1947 loc) · 58.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
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
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using InfiniteRuntimeTagViewer.Interface.Controls;
using InfiniteRuntimeTagViewer.Interface.Windows;
using AvalonDock.Layout;
using Memory;
using InfiniteRuntimeTagViewer.Halo;
using System.Windows.Media;
using System.Timers;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Threading;
using System.Collections.ObjectModel;
using InfiniteRuntimeTagViewer.Properties;
using System.ComponentModel;
using System.Diagnostics;
using System.Net;
using Newtonsoft.Json.Linq;
using System.Xml;
using InfiniteRuntimeTagViewer.Halo.TagStructDump;
namespace InfiniteRuntimeTagViewer
{
public partial class MainWindow
{
/* ###### THINGS TO BE FIXED/ADDED (which i will get around to eventually) ######
### BUG FIXES ###
autoload + dont show unloaded tags + load: cant create new tag ui instances or something
-- oh i know what happened there, when halo gets unhooked, it wipes the UI without scrubbing the UI references from UItaglist or something
theres still a ton of opportunites to crash in unlikely scenarios, need to investigate all crashes and create handlers
### QOL ###
reload tag button
optimize tagdata loading by making combobox index a source
mod poke abort
-- required tags
-- can abort
### FEATURES ###
randomize tagref option
single poke doesn't have revert button :(
### ERROR CATCHING ###
### TAG STRUCTS ###
char ' gets turned into the funny unknown char. ex. don't -> dont^t (ok using that character there prompts vs to use unicode mode, no)
### HASH STUFF (i'll do this next week or sometime) ###
add tool: hash logger - will read through every loaded tag in the game and log referenced hashes
add hash database support - so people can convert hashes to known unhashed strings
add tool: hash guesser - lets users guess ushash strings from unknown hashes
prolly some more stuff i cant remember how i was gonna do all this
### STUFF THATS NOT REALLY ON THE LIST ###
show red border on failed pokes INSIDE tag data tab, and not just in the poke queue
*/
public MainWindow()
{
InitializeComponent();
//GetAllMethods();
StateChanged += MainWindowStateChangeRaised;
_t = new System.Timers.Timer();
_t.Elapsed += OnTimedEvent;
_t.Interval = 2000;
_t.AutoReset = true;
inhale_tagnames();
//SettingsControl settings = new();
SetGeneralSettingsFromConfig();
done_loading_settings = true;
//settings.Close();
add_new_section_to_pokelist("Poke Queue");
//If the user has opted to check for updates automatically
if (Settings.Default.Updater)
{
//Check for updates
Task.Run(() => CheckForUpdates(this, null));
}
}
#region Window Styling
// Can execute
private void CommandBinding_CanExecute(object sender, CanExecuteRoutedEventArgs e)
{
e.CanExecute = true;
}
// Minimize
private void CommandBinding_Executed_Minimize(object sender, ExecutedRoutedEventArgs e)
{
SystemCommands.MinimizeWindow(this);
}
// Maximize
private void CommandBinding_Executed_Maximize(object sender, ExecutedRoutedEventArgs e)
{
SystemCommands.MaximizeWindow(this);
}
// Restore
private void CommandBinding_Executed_Restore(object sender, ExecutedRoutedEventArgs e)
{
SystemCommands.RestoreWindow(this);
}
// Close
private void CommandBinding_Executed_Close(object sender, ExecutedRoutedEventArgs e)
{
SystemCommands.CloseWindow(this);
}
// State change
private void MainWindowStateChangeRaised(object? sender, EventArgs e)
{
if (WindowState == WindowState.Maximized)
{
MainWindowBorder.BorderThickness = new Thickness(8);
RestoreButton.Visibility = Visibility.Visible;
MaximizeButton.Visibility = Visibility.Collapsed;
}
else
{
MainWindowBorder.BorderThickness = new Thickness(0);
RestoreButton.Visibility = Visibility.Collapsed;
MaximizeButton.Visibility = Visibility.Visible;
}
}
#endregion
#region UI Event Handlers
//Adjust UI element size depending on window size.
private void window_SizeChanged(object sender, SizeChangedEventArgs e)
{
double newWindowWidth = e.NewSize.Width;
//Debug.WriteLine(newWindowWidth);
if (newWindowWidth < 1200)
{
CloseProcBtn.IsHitTestVisible = false;
CloseProcBtn.Visibility = Visibility.Collapsed;
}
else
{
CloseProcBtn.IsHitTestVisible = true;
CloseProcBtn.Visibility = Visibility.Visible;
}
if (newWindowWidth < 1000)
{
ReloadProcBtn.IsHitTestVisible = false;
ReloadProcBtn.Visibility = Visibility.Collapsed;
}
else
{
ReloadProcBtn.IsHitTestVisible = true;
ReloadProcBtn.Visibility = Visibility.Visible;
}
}
private void BtnReloadProcessClick(object sender, RoutedEventArgs e)
{
foreach (Process? process in Process.GetProcessesByName("HaloInfinite"))
{
string? filePath = process.MainModule.FileName;
process.Kill();
Process.Start(filePath);
}
}
private void BtnCloseClick(object sender, RoutedEventArgs e)
{
foreach (Process? process in Process.GetProcessesByName("HaloInfinite"))
{
process.Kill();
}
}
private void Button_Click_1(object sender, RoutedEventArgs e)
{
num_of_user_added_lists++;
add_new_section_to_pokelist("Poke Queue(" + num_of_user_added_lists + ")");
}
private void SetStatus(string message)
{
Dispatcher.Invoke(new Action(() =>
{
statusText.Text = message;
}));
}
#endregion
#region Variables
public bool AutoHookKey;
public bool AutoLoadKey;
public bool AutoPokeKey;
public bool FilterOnlyMappedKey;
public bool OpacityKey;
public bool CheckForUpdatesKey;
public bool AlwaysOnTopKey;
public bool done_loading_settings;
public string ProcAsyncBaseAddr = Settings.Default.ProcAsyncBaseAddr;
public string HookProcessAsyncBaseAddr; // Tag_List_Function
public string ScanMemAOBBaseAddr = "HaloInfinite.exe+0x4357FD8"; // Tag_List_Str
public delegate void HookAndLoadDelagate();
public delegate void LoadTagsDelagate();
private readonly System.Timers.Timer _t;
public Mem M = new();
#endregion
#region Settings
public void ShowPointerDialog(object source, RoutedEventArgs e)
{
PointerDialog pointerDialog = new();
pointerDialog.Show();
pointerDialog.Focus();
}
public void GetGeneralSettingsFromConfig()
{
AutoHookKey = Settings.Default.AutoHook;
AutoLoadKey = Settings.Default.AutoLoad;
AutoPokeKey = Settings.Default.AutoPoke;
FilterOnlyMappedKey = Settings.Default.FilterOnlyMapped;
OpacityKey = Settings.Default.Opacity;
AlwaysOnTopKey = Settings.Default.AlwaysOnTop;
CheckForUpdatesKey = Settings.Default.Updater;
}
public void SetGeneralSettingsFromConfig()
{
GetGeneralSettingsFromConfig();
CbxSearchProcess.IsChecked = AutoHookKey;
CbxAutoPokeChanges.IsChecked = AutoPokeKey;
CbxFilterUnloaded.IsChecked = FilterOnlyMappedKey;
//whatdoescbxstandfor.IsChecked = AutoLoadKey; // Probably check box... -Z
CbxOnTop.IsChecked = AlwaysOnTopKey;
CbxOpacity.IsChecked = OpacityKey;
CbxCheckForUpdates.IsChecked = CheckForUpdatesKey;
}
public void OnApplyChanges_Click()
{
SaveUserChangedSettings();
Settings.Default.Save();
SetGeneralSettingsFromConfig();
}
public void SaveUserChangedSettings()
{
Settings.Default.AutoHook = CbxSearchProcess.IsChecked;
//Settings.Default.AutoLoad = whatdoescbxstandfor.IsChecked;
Settings.Default.AutoPoke = CbxAutoPokeChanges.IsChecked;
Settings.Default.FilterOnlyMapped = CbxFilterUnloaded.IsChecked;
Settings.Default.AlwaysOnTop = CbxOnTop.IsChecked;
Settings.Default.Opacity = CbxOpacity.IsChecked;
Settings.Default.Updater = CbxCheckForUpdates.IsChecked;
}
#endregion
#region SearchBar
private void SearchBoxClick(object? sender, RoutedEventArgs e)
{
Search();
}
private void SearchBoxEnter(object sender, System.Windows.Input.KeyEventArgs e)
{
if (e.Key == Key.Return)
{
Search();
}
}
private void Search()
{
//string[] supportedTags = Halo.TagObjects.TagLayouts.Tags.Keys.ToArray();
string search = Searchbox.Text;
foreach (TreeViewItem tv in TagsTree.Items)
{
if (!tv.Header.ToString().Contains(search))
{
tv.Visibility = Visibility.Collapsed;
foreach (TreeViewItem tc in tv.Items)
{
if (tc.Header.ToString().Contains(search))
{
tc.Visibility = Visibility.Visible;
tv.Visibility = Visibility.Visible;
}
else
{
tc.Visibility = Visibility.Collapsed;
}
}
}
else
{
tv.Visibility = Visibility.Visible;
foreach (TreeViewItem tc in tv.Items)
{
tc.Visibility = Visibility.Visible;
}
}
}
}
#endregion
#region MenuCommands
public void ClickExit(object sender, RoutedEventArgs e)
{
SystemCommands.CloseWindow(this);
}
public void OpenTeleportMenu(object sender, RoutedEventArgs e)
{
TeleportWindow tp_win = new(M);
tp_win.Show();
}
public ProcessSelector GetProcessSelector()
{
return processSelector;
}
public bool specific;
public void UnloadTags(object sender, RoutedEventArgs e)
{
TagsTree.Items.Clear();
loadedTags = false;
}
public void ShowGameExeDialog(object sender, RoutedEventArgs e)
{
OpenFileDialog ofd = new OpenFileDialog
{
Filter = "Halo Infinite Executable|HaloInfinite.exe",
Title = "Select the Halo Infinite executable"
};
ofd.ShowDialog();
if (ofd.FileName != "")
{
//Save the setting for the exe file
Settings.Default.GameLocation = ofd.FileName;
SetStatus("Updated Game Location");
}
}
public void CheckForUpdates(object sender, RoutedEventArgs e)
{
//Check for recent commits on GitHub
//If there are recent commits, display a message box asking if the user would like to download the latest version
//If the user clicks yes, open the link to the GitHub repo and download the latest version
//Get recent commits from GitHub
string commits = "";
string node_id;
try
{
using (WebClient client = new WebClient())
{
client.Headers.Add("user-agent", "request");
commits = client.DownloadString("https://api.github.com/repos/Gamergotten/Infinite-runtime-tagviewer/commits/master");
Debug.WriteLine("Commits: " + commits);
//parse the json and set node_id to the value of the node_id field
JObject json = JObject.Parse(commits);
node_id = (string) json["node_id"];
Debug.WriteLine("Node ID: " + node_id);
}
if (Settings.Default.Version == "")
{
Settings.Default.Version = node_id;
Settings.Default.Save();
return;
}
}
catch (Exception)
{
Debug.WriteLine("API Fail");
System.Windows.Forms.MessageBox.Show("Unable to check for updates. Please check your internet connection.");
return;
}
string storedVersion;
try
{
//Get the stored version number from the settings file
storedVersion = Settings.Default.Version;
Debug.WriteLine("Stored version: " + storedVersion);
}
catch (Exception)
{
System.Windows.Forms.MessageBox.Show("Unable to check for updates. Please check your internet connection.");
return;
}
//Compare the two and if the stored version is less than the current version, display a message box asking if the user would like to download the latest version
if (storedVersion != node_id)
{
DialogResult result = System.Windows.Forms.MessageBox.Show("A new version of the tag viewer is available. Would you like to download the latest version?", "Update Available", MessageBoxButtons.YesNoCancel);
if (result == System.Windows.Forms.DialogResult.Yes)
{
SetStatus("Downloading latest version...");
//Download the file
try
{
using (WebClient client = new WebClient())
{
client.DownloadProgressChanged += (s, e) =>
{
SetStatus("Downloading..." + e.ProgressPercentage.ToString() + "%");
};
client.DownloadFileCompleted += (s, e) =>
{
SetStatus("Download Complete");
// any other code to process the file
//Write the node id to the settings file
Settings.Default.Version = node_id;
Settings.Default.Save();
//Start the unzip.bat file
ProcessStartInfo startInfo = new()
{
FileName = "unzip.bat",
Arguments = "Infinite-runtime-tagviewer.zip"
};
Process.Start(startInfo);
//Close the current process
Environment.Exit(0);
};
//Download the file on a background thread
client.DownloadFileAsync(new Uri("https://nightly.link/Gamergotten/Infinite-runtime-tagviewer/workflows/dotnet/master/IRTV.zip"), "IRTV.zip");
while (client.IsBusy)
{
System.Windows.Forms.Application.DoEvents();
}
}
}
catch (Exception)
{
System.Windows.Forms.MessageBox.Show("Unable to download the latest version. Please check your internet connection.");
}
}
}
else
{
SetStatus("Client up to date!");
}
return;
}
// open mods window
public ModWindow? mwidow;
private void MenuItem_Click(object sender, RoutedEventArgs e)
{
try
{
if (mwidow == null)
{
mwidow = new ModWindow();
mwidow.Show();
mwidow.Focus();
mwidow.main = this;
mwidow.load_mods_from_directories();
}
else
{
mwidow.Show();
mwidow.Focus();
}
if (CbxOpacity.IsChecked)
{
mwidow.Opacity = 0.90;
}
else
{
mwidow.Opacity = 1;
}
}
catch (System.InvalidOperationException)
{
mwidow = null;
MenuItem_Click(sender, e);
}
}
// REVERT POKE STUFF
private void REVERT_ALL_BUTTON(object sender, RoutedEventArgs e)
{
int fails = 0;
int pokes = 0;
for (int q = 0; q < Pokelistlist.Count; q++)
{
KeyValuePair<int, int> kv = revertlist(Pokelistlist.ElementAt(q).Key);
fails += kv.Value;
pokes += kv.Key;
}
if (fails < 1)
{
poke_text.Text = pokes + " changes reverted!";
if (mwidow != null)
{
mwidow.debug_text.Text = pokes + " changes reverted!";
}
}
else
{
poke_text.Text = pokes + " reverted, " + fails + " failed";
if (mwidow != null)
{
mwidow.debug_text.Text = pokes + " reverted, " + fails + " failed";
}
}
change_text.Text = return_real_number_of_pokes_queued_okk() + " changes queued";
}
private void REVERT_SINGLE_BUTTON(object sender, RoutedEventArgs e)
{
KeyValuePair<int, int> kv = revertlist(current_pokelist);
int fails = kv.Value;
int pokes = kv.Key;
if (fails < 1)
{
poke_text.Text = pokes + " changes reverted!";
if (mwidow != null)
{
mwidow.debug_text.Text = pokes + " changes reverted!";
}
}
else
{
poke_text.Text = pokes + " reverted, " + fails + " failed";
if (mwidow != null)
{
mwidow.debug_text.Text = pokes + " reverted, " + fails + " failed";
}
}
change_text.Text = return_real_number_of_pokes_queued_okk() + " changes queued";
}
private void BtnREMOVEQueueSingle_Click(object sender, RoutedEventArgs e)
{
clear_pokes_list(current_pokelist);
change_text.Text = return_real_number_of_pokes_queued_okk() + " changes queued";
if (mwidow != null)
{
mwidow.test_changes.Text = return_real_number_of_pokes_queued_okk() + " changes queued";
}
Pokelistlist.Remove(current_pokelist);
PokeList_Combobox.Items.Remove(PokeList_Combobox.SelectedItem);
if (PokeList_Combobox.Items.Count > 0)
PokeList_Combobox.SelectedIndex = 0;
poke_text.Text = "Poke List Removed";
}
private void DockManager_DocumentClosing(object sender, AvalonDock.DocumentClosingEventArgs e)
{
// On tag window closing.
UpdateLayout();
GC.Collect(3, GCCollectionMode.Forced);
}
private void BtnShowHideQueue_Click(object sender, RoutedEventArgs e)
{
System.Windows.Controls.Button? btn = (System.Windows.Controls.Button) sender;
queuelist.Visibility = queuelist.Visibility == Visibility.Visible ? Visibility.Collapsed : Visibility.Visible;
btn.Content =
queuelist.Visibility == Visibility.Visible
? "Hide Queue"
: "Show Queue";
}
private void BtnClearQueueSingle_Click(object sender, RoutedEventArgs e)
{
clear_pokes_list(current_pokelist);
change_text.Text = return_real_number_of_pokes_queued_okk() + " changes queued";
if (mwidow != null)
{
mwidow.test_changes.Text = return_real_number_of_pokes_queued_okk() + " changes queued";
}
poke_text.Text = "Poke List Cleared";
}
private void BtnClearQueue_Click(object sender, RoutedEventArgs e)
{
clear_all_pokelists();
}
// POKE OUR CHANGES LETSGOOOO
private void BtnPokeChanges_Click(object sender, RoutedEventArgs e)
{
PokeChanges();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
KeyValuePair<int, int> kv = pokelist(current_pokelist);
poke_text.Text = kv.Key + " poked, " + kv.Value + " failed";
if (mwidow != null)
{
mwidow.debug_text.Text = kv.Key + " poked, " + kv.Value + " failed";
}
}
private void Open_pokes(object sender, RoutedEventArgs e)
{
if (!loadedTags)
{
HookAndLoad();
}
// Create OpenFileDialog
Microsoft.Win32.OpenFileDialog dlg = new()
{
// Set filter for file extension and default file extension
DefaultExt = ".irtv",
Filter = "IRTV Files (*.irtv)|*.irtv"
};
// Display OpenFileDialog by calling ShowDialog method
bool? result = dlg.ShowDialog();
// Get the selected file name and display in a TextBox
if (result == true)
{
string fullFileName = dlg.FileName;
string fileNameWithExt = Path.GetFileName(fullFileName);
add_new_section_to_pokelist(fileNameWithExt);
recieve_file_to_inhalo_pokes(dlg.FileName);
string target_folder = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + "\\IRTV";
if (!Directory.Exists(target_folder))
Directory.CreateDirectory(target_folder);
string destPath = Path.Combine(target_folder, fileNameWithExt);
if (File.Exists(destPath))
File.Delete(destPath);
File.Copy(dlg.FileName, destPath);
}
}
private void Save_pokes(object sender, RoutedEventArgs e)
{
Microsoft.Win32.SaveFileDialog? sfd = new()
{
Filter = "IRTV Files (*.irtv)|*.irtv|All files (*.*)|*.*",
// Set other options depending on your needs ...
};
if (sfd.ShowDialog() == true)
{
string filename = sfd.FileName;
// save the file
//File.WriteAllText(filename, contents);
//KeyValuePair<string, KeyValuePair<string, string>>
string big_ol_poke_dump = "";
foreach (KeyValuePair<string, KeyValuePair<string, string>> k in Pokelistlist[current_pokelist].Pokelist)
{
big_ol_poke_dump += k.Key + ";" + k.Value.Key + ";" + k.Value.Value + "\r\n";
}
Savewindow sw = new();
sw.Show();
sw.main = this;
sw.ill_take_it_from_here_mainwindow(filename, big_ol_poke_dump);
poke_text.Text = Pokelistlist[current_pokelist].Pokelist.Count + " Pokes Saved!";
}
}
private void PokeList_Combobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
ComboBoxItem? comboBoxItem = PokeList_Combobox.SelectedItem as ComboBoxItem;
if (comboBoxItem != null)
{
load_a_pokelist(comboBoxItem.Content.ToString());
}
}
private void Select_Tag_click(object sender, RoutedEventArgs e)
{
TreeViewItem? item = sender as TreeViewItem;
CreateTagEditorTabByTagIndex(item.Tag.ToString());
}
private void CheckBoxProcessCheck(object sender, RoutedEventArgs e)
{
_t.Enabled = CbxSearchProcess.IsChecked;
if (done_loading_settings)
{
OnApplyChanges_Click();
}
}
private void UpdateOptionsFromSettings(object sender, RoutedEventArgs e)
{
if (done_loading_settings)
OnApplyChanges_Click();
}
private void UpdateOption_for_hiding_unloaded(object sender, RoutedEventArgs e)
{
if (done_loading_settings)
{
OnApplyChanges_Click();
if (loadedTags == true)
{
HookAndLoad();
}
}
}
// load tags from Mem
public void BtnReLoadTags_Click(object sender, RoutedEventArgs e)
{
TagsTree.Items.Clear();
groups_headers.Clear();
tags_headers.Clear();
HookAndLoad();
}
private void BtnLoadTags_Click(object sender, RoutedEventArgs e)
{
HookAndLoad();
Reload_Button.IsEnabled = true;
}
private void Window_Deactivated(object sender, EventArgs e)
{
Window window = (Window) sender;
if (CbxOnTop.IsChecked == true)
{
window.Topmost = true;
}
else
{
window.Topmost = false;
}
}
private void Ppacity(object sender, RoutedEventArgs e)
{
UpdateOptionsFromSettings(sender, e);
if (CbxOpacity.IsChecked)
{
window.Opacity = 0.90;
if (mwidow != null)
{
mwidow.Opacity = 0.90;
}
}
else
{
window.Opacity = 1;
if (mwidow != null)
{
mwidow.Opacity = 1;
}
}
}
#endregion
#region Tag Loading
// group 4chars, group instance
// eg. weap, { system.whatever.balls }
public Dictionary<string, TreeViewItem> groups_headers = new();
public Dictionary<string, TreeViewItem> tags_headers = new();
public ObservableCollection<string> second_level = new();
public Dictionary<string, string> InhaledTagnames = new();
public Dictionary<string, TagStruct> TagsList { get; set; } = new(); // and now we can convert it back because we just sort it elsewhere
public SortedDictionary<string, GroupTagStruct> TagGroups { get; set; } = new();
private bool is_checked;
public bool loadedTags = false;
public bool hooked = false;
public long aobStart;
private long BaseAddress = -1;
private int TagCount = -1;
public async void HookAndLoad()
{
try
{
await HookProcessAsync();
}
catch (System.ArgumentNullException)
{
}
if (BaseAddress != -1 && BaseAddress != 0)
{
await LoadTagsMem(false);
if (hooked == true)
{
SearchBoxClick(null, null);
System.Diagnostics.Debugger.Log(0, "DBGTIMING", "Done loading tags");
}
}
}
// instead of using the other method i made a new one because the last one yucky,
public bool SlientHookAndLoad(bool load_tags_too)
{
_ = HookProcessAsync();
if (BaseAddress != -1 && BaseAddress != 0)
{
if (load_tags_too)
{
TagsTree.Items.Clear();
groups_headers.Clear();
tags_headers.Clear();
LoadTagsMem(true);
if (hooked == true)
{
SearchBoxClick(null, null);
}
}
return true;
}
return false;
}
private async Task HookProcessAsync()
{
try
{
bool reset = processSelector.hookProcess(M);
if (M.mProc.Process.Handle == IntPtr.Zero || processSelector.selected == false || loadedTags == false)
{
// Could not find the process
SetStatus("Cant find HaloInfinite.exe");
BaseAddress = -1;
hooked = false;
loadedTags = false;
TagsTree.Items.Clear();
}
if (!hooked || reset)
{
// Get the base address
UpdateAddress();
BaseAddress = M.ReadLong(HookProcessAsyncBaseAddr);
string validtest = M.ReadString(BaseAddress.ToString("X"));
//System.Diagnostics.Debug.WriteLine(M.ReadLong("HaloInfinite .exe+0x3D13E38")); // this is the wrong address lol
if (validtest == "tag instances")
{
SetStatus("Process Hooked: " + M.mProc.Process.Id);
hooked = true;
}
else
{
SetStatus("Offset failed, scanning...");
await ScanMem();
}
}
}
catch (Exception ex)
{
Debug.WriteLine(ex.ToString());
//If exception is a null reference exception, set the hook text to "Game Not Open"
if (ex.GetType().IsAssignableFrom(typeof(NullReferenceException)))
{
SetStatus("Can't Find HaloInfinite.exe");
//Show a message box that prompts the user if they want to launch the game
MessageBoxResult result = (MessageBoxResult) System.Windows.Forms.MessageBox.Show("HaloInfinite.exe is not open. Do you want to open it?", "HaloInfinite.exe Not Open", System.Windows.Forms.MessageBoxButtons.YesNo);
if (result == MessageBoxResult.Yes)
{
//Check if the setting for the game location is set
if (Settings.Default.GameLocation != "")
{
//If it is set, open the game
System.Diagnostics.Process.Start(Settings.Default.GameLocation);
//wait 15 seconds before trying to load again
await Task.Delay(15000);
//Try to hook again
await HookProcessAsync();
}
else
{
//If it is not set, allow the user to browse to an exe file, then open that exe file, wait 15 seconds, and resume loading.
OpenFileDialog ofd = new()
{
Filter = "HaloInfinite.exe|HaloInfinite.exe",
Title = "Please select HaloInfinite.exe"
};
ofd.ShowDialog();
Settings.Default.GameLocation = ofd.FileName;
Settings.Default.Save();
System.Diagnostics.Process.Start(Settings.Default.GameLocation);
await Task.Delay(15000);
await HookProcessAsync();
}
}
}
}
}
public void UpdateAddress()
{
if (Settings.Default.ProcAsyncBaseAddr.StartsWith("HaloInfinite.exe+0x"))
{
HookProcessAsyncBaseAddr = Settings.Default.ProcAsyncBaseAddr;
}
else
{
HookProcessAsyncBaseAddr = ScanMemAOBBaseAddr;
}
}
public async Task LoadTagsMem(bool is_silent)
{
is_checked = CbxFilterUnloaded.IsChecked;
await Task.Run((Action) (() =>
{
if (TagCount != -1)
{
TagCount = -1;
TagGroups.Clear();
TagsList.Clear();
}
TagCount = this.M.ReadInt((BaseAddress + 0x6C).ToString("X"));
long tagsStart = this.M.ReadLong((BaseAddress + 0x78).ToString("X"));
// each tag is 52 bytes long // was it 52 or was it 0x52? whatever
// 0x0 datnum 4bytes
// 0x4 ObjectID 4bytes
// 0x8 Tag_group Pointer 8bytes
// 0x10 Tag_data Pointer 8bytes
// 0x18 Tag_type_desc Pointer 8bytes
TagsList = new Dictionary<string, TagStruct>();
for (int tagIndex = 0; tagIndex < TagCount; tagIndex++)
{
TagStruct currentTag = new();
long tagAddress = tagsStart + (tagIndex * 52);
byte[] test1 = this.M.ReadBytes(tagAddress.ToString("X"), (long) 4);
try
{
currentTag.Datnum = BitConverter.ToString(test1).Replace("-", string.Empty);
loadedTags = false;
}
catch (ArgumentNullException)
{
hooked = false;
return;
}
byte[] test = (this.M.ReadBytes((tagAddress + 4).ToString("X"), (long) 4));
// = String.Concat(bytes.Where(c => !Char.IsWhiteSpace(c)));
currentTag.ObjectId = BitConverter.ToString(test).Replace("-", string.Empty);
currentTag.TagGroup = read_tag_group((long) this.M.ReadLong((tagAddress + 0x8).ToString("X")));
currentTag.TagData = this.M.ReadLong((tagAddress + 0x10).ToString("X"));
currentTag.TagFullName = convert_ID_to_tag_name(currentTag.ObjectId).Trim();
currentTag.TagFile = currentTag.TagFullName.Split('\\').Last<string>().Trim();
if (is_checked)
{
byte[] b = this.M.ReadBytes((currentTag.TagData + 12).ToString("X"), (long) 4);
if (b != null)
{
string checked_datnum = BitConverter.ToString(b).Replace("-", string.Empty);
if (checked_datnum != currentTag.Datnum)
{
currentTag.unloaded = true;
}
}
else
{
currentTag.unloaded = true;
}
}
// do the tag definitition
if (!TagsList.ContainsKey(currentTag.ObjectId))
{
TagsList.Add(currentTag.ObjectId, currentTag);
}