forked from Gamergotten/Infinite-runtime-tagviewer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMainWindow.xaml.cs
1805 lines (1613 loc) · 49.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
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.Xml.Serialization;
using InfiniteRuntimeTagViewer.Halo.TagObjects;
using System.Windows.Media;
using System.Timers;
using System.Threading.Tasks;
using System.Threading;
using System.Windows.Forms;
using System.Reflection;
using System.Windows.Threading;
using InfiniteRuntimeTagViewer.Properties;
namespace InfiniteRuntimeTagViewer
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
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 bool AutoHookKey;
public bool AutoLoadKey;
public bool AutoPokeKey;
public bool FilterOnlyMappedKey;
public bool done_loading_settings;
#region poop region
public void GetGeneralSettingsFromConfig()
{
AutoHookKey = Settings.Default.AutoHook;
AutoLoadKey = Settings.Default.AutoLoad;
AutoPokeKey = Settings.Default.AutoPoke;
FilterOnlyMappedKey = Settings.Default.FilterOnlyMapped;
}
public void SetGeneralSettingsFromConfig()
{
GetGeneralSettingsFromConfig();
CbxSearchProcess.IsChecked = AutoHookKey;
CbxAutoPokeChanges.IsChecked = AutoPokeKey;
CbxFilterUnloaded.IsChecked = FilterOnlyMappedKey;
whatdoescbxstandfor.IsChecked = AutoLoadKey;
}
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;
}
#endregion
public delegate void HookAndLoadDelagate();
public delegate void LoadTagsDelagate();
private readonly System.Timers.Timer _t;
public Mem M = new();
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");
}
private async Task HookProcessAsync()
{
bool reset = processSelector.hookProcess(M);
if (M.pHandle == IntPtr.Zero || processSelector.selected == false || loadedTags == false)
{
// Could not find the process
hook_text.Text = "Cant find HaloInfinite.exe";
BaseAddress = -1;
hooked = false;
loadedTags = false;
TagsTree.Items.Clear();
}
if (!hooked || reset)
{
// Get the base address
BaseAddress = M.ReadLong("HaloInfinite.exe+3E96260");
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")
{
hook_text.Text = "Process Hooked: " + M.theProc.Id;
hooked = true;
}
else
{
hook_text.Text = "Offset failed, scanning...";
await ScanMem();
}
}
}
public async void HookAndLoad()
{
await HookProcessAsync(); // this didn't wait lol
if (BaseAddress != -1 && BaseAddress != 0)
{
LoadTagsMem(false);
if (hooked == true)
{
Searchbox_TextChanged(null, null);
System.Diagnostics.Debugger.Log(0, "DBGTIMING", "Done loading tags");
}
}
}
// AUTO MOD LOADER STUFF
static int min_tags_changed_for_update = 750;
static int min_tags_changed_for_interupt_update = 150;
public int tag_count_last_update = 0;
public int current_tag_count = 0;
public bool is_waiting;
private async void OnTimedEvent(object source, ElapsedEventArgs e)
{
Dispatcher.Invoke(new Action(async () =>
{
if (hooked) // wait till hooked so, the user can decide when to turn this on without it annoyingly firing off
{
if (!is_waiting)
{
await HookProcessAsync();
if (BaseAddress > 0)
{
int real_tag_count = M.ReadInt((BaseAddress + 0x70).ToString("X"));
current_tag_count = real_tag_count;
extra_tag_text.Text = "found (" + real_tag_count + " tags)";
if (current_tag_count < tag_count_last_update - min_tags_changed_for_update || current_tag_count > tag_count_last_update + min_tags_changed_for_update)
{
is_waiting = true;
extra_tag_text.Text = "one sec (" + real_tag_count + " tags)"; // actually its 12 seconds fuck you
while (is_waiting)
{
await Task.Delay(12000);
int real_tag_count_again = M.ReadInt((BaseAddress + 0x70).ToString("X"));
if (!(real_tag_count_again < current_tag_count - min_tags_changed_for_interupt_update) && !(real_tag_count_again > current_tag_count + min_tags_changed_for_interupt_update))
{
is_waiting = false;
extra_tag_text.Text = "reloading (" + real_tag_count_again + " tags)";
LoadTagsMem(false);
if (whatdoescbxstandfor.IsChecked)
{
PokeChanges();
}
tag_count_last_update = real_tag_count_again;
}
else
{
current_tag_count = real_tag_count_again;
extra_tag_text.Text = "Awaiting (" + real_tag_count_again + " tags)";
}
}
}
}
}
}
}));
}
public bool loadedTags = false;
public bool hooked = false;
public async Task ScanMem()
{
BaseAddress = M.ReadLong("HaloInfinite.exe+3E96260"); // FALLBACK ADDRESS POINTER (which is literally useless)
string validtest = M.ReadString(BaseAddress.ToString("X"));
if (validtest == "tag instances")
{
hook_text.Text = "Process Hooked: " + M.theProc.Id;
hooked = true;
}
else
{
hook_text.Text = "Offset failed, scanning...";
try
{
long? aobScan = (await M.AoBScan("74 61 67 20 69 6E 73 74 61 6E 63 65 73", true))
.First(); // "tag instances"
// Failed to find base tag address
if (aobScan == null || aobScan == 0)
{
BaseAddress = -1;
loadedTags = false;
hook_text.Text = "Failed to locate base tag address";
}
else
{
BaseAddress = aobScan.Value;
hook_text.Text = "Process Hooked: " + M.theProc.Id + " (AOB)";
hooked = true;
}
}
catch (Exception)
{
hook_text.Text = "Cant find HaloInfinite.exe";
}
}
}
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();
}
}
}
private void Ppacity(object sender, RoutedEventArgs e)
{
if (window.Opacity != 0.90)
{
window.Opacity = 0.90;
}
else
{
window.Opacity = 1;
}
}
private long BaseAddress = -1;
private int TagCount = -1;
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();
// 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;
}
// 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)
{
Searchbox_TextChanged(null, null);
}
}
return true;
}
return false;
}
public void LoadTagsMem(bool is_silent)
{
if (TagCount != -1)
{
TagCount = -1;
TagGroups.Clear();
TagsList.Clear();
}
TagCount = M.ReadInt((BaseAddress + 0x6C).ToString("X"));
long tagsStart = 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 = M.ReadBytes(tagAddress.ToString("X"), 4);
try
{
currentTag.Datnum = BitConverter.ToString(test1).Replace("-", string.Empty);
loadedTags = false;
}
catch (System.ArgumentNullException)
{
hooked = false;
return;
}
byte[] test = (M.ReadBytes((tagAddress + 4).ToString("X"), 4));
// = String.Concat(bytes.Where(c => !Char.IsWhiteSpace(c)));
currentTag.ObjectId = BitConverter.ToString(test).Replace("-", string.Empty);
currentTag.TagGroup = read_tag_group(M.ReadLong((tagAddress + 0x8).ToString("X")));
currentTag.TagData = M.ReadLong((tagAddress + 0x10).ToString("X"));
currentTag.TagFullName = convert_ID_to_tag_name(currentTag.ObjectId).Trim();
currentTag.TagFile = currentTag.TagFullName.Split('\\').Last().Trim();
if (CbxFilterUnloaded.IsChecked)
{
byte[] b = M.ReadBytes((currentTag.TagData + 12).ToString("X"), 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);
}
}
if (!is_silent)
Loadtags();
}
public string? read_tag_group(long tagGroupAddress)
{
try
{
string key = ReverseString(M.ReadString((tagGroupAddress + 0xC).ToString("X"), "", 8).Substring(0, 4));
if (!TagGroups.ContainsKey(key))
{
GroupTagStruct currentGroup = new()
{
TagGroupDesc = M.ReadString((tagGroupAddress).ToString("X") + ",0x0"),
TagGroupName = key,
TagGroupDefinitition = M.ReadString((tagGroupAddress + 0x20).ToString("X") + ",0x0,0x0"),
TagExtraType = M.ReadString((tagGroupAddress + 0x2C).ToString("X"), "", 12)
};
long testAddress = M.ReadLong((tagGroupAddress + 0x48).ToString("X"));
if (testAddress != 0)
{
currentGroup.TagExtraName = M.ReadString((testAddress).ToString("X"));
}
// Doing the UI here so we dont have to literally reconstruct the elements elsewhere // lol // xd how'd that work out for you
//TreeViewItem sortheader = new TreeViewItem();
//sortheader.Header = ReverseString(current_group.tag_group_name.Substring(0, 4)) + " (" + current_group.tag_group_desc + ")";
//sortheader.ToolTip = current_group.tag_group_definitition;
//TagsTree.Items.Add(sortheader);
//current_group.tag_category = sortheader;
TagGroups.Add(key, currentGroup);
}
return key;
}
catch (Exception)
{
return null;
}
}
// as far as im aware this is still running on the main thread :frown:
// group 4chars, group instance
// eg. weap, { system.whatever.balls }
public Dictionary<string, TreeViewItem> groups_headers = new();
public Dictionary<string, TreeViewItem> tags_headers = new();
public void Loadtags()
{
Dictionary<string, TreeViewItem> groups_headers_diff = new();
// cycle through and evaluate against diff
// act accordingly
// save
// TagsTree
loadedTags = true;
for (int i = 0; i<TagGroups.Count; i++) // per group
{
KeyValuePair<string, GroupTagStruct> goop = TagGroups.ElementAt(i);
if (groups_headers.Keys.Contains(goop.Key)) // is included in group_headers
{
TreeViewItem t = groups_headers[goop.Key];
groups_headers_diff.Add(goop.Key, t);
groups_headers.Remove(goop.Key);
GroupTagStruct displayGroup = goop.Value;
displayGroup.TagCategory = t;
TagGroups[goop.Key] = displayGroup;
}
else
{
GroupTagStruct displayGroup = goop.Value;
TreeViewItem sortheader = new()
{
Header = displayGroup.TagGroupName + " (" + displayGroup.TagGroupDesc + ")",
ToolTip = new TextBlock { Foreground = Brushes.Black, Text = displayGroup.TagGroupDefinitition }
};
displayGroup.TagCategory = sortheader;
TagGroups[goop.Key] = displayGroup;
TagsTree.Items.Add(sortheader);
groups_headers_diff.Add(goop.Key, sortheader);
}
}
foreach (KeyValuePair<string, TreeViewItem> poop in groups_headers) // per group
{
if (poop.Value != null)
{
TagsTree.Items.Remove(poop.Value);
}
}
groups_headers = groups_headers_diff;
Dictionary<string, TreeViewItem> tags_headers_diff = new();
foreach (KeyValuePair<string, TagStruct> curr_tag in TagsList.OrderBy(key => key.Value.TagFullName)) // per tag
{
if (!curr_tag.Value.unloaded)
{
if (tags_headers.Keys.Contains(curr_tag.Key)) // is included in tag_headers UI
{
TreeViewItem t = tags_headers[curr_tag.Key];
t.Tag = curr_tag.Key;
tags_headers_diff.Add(curr_tag.Key, t);
tags_headers.Remove(curr_tag.Key);
}
else // tag isnt in UI
{
TreeViewItem t = new();
TagStruct tag = curr_tag.Value;
TagGroups.TryGetValue(tag.TagGroup, out GroupTagStruct dictTagGroup);
t.Header = "(" + tag.Datnum + ") " + convert_ID_to_tag_name(tag.ObjectId);
t.Tag = curr_tag.Key; // our index to our tag
t.Selected += Select_Tag_click;
dictTagGroup.TagCategory.Items.Add(t);
tags_headers_diff.Add(curr_tag.Key, t);
}
}
}
foreach (KeyValuePair<string, TreeViewItem> poop in tags_headers) // per tag remove
{
if (poop.Value != null)
{
TreeViewItem ownber = poop.Value.Parent as TreeViewItem;
ownber.Items.Remove(poop.Value);
}
}
tags_headers = tags_headers_diff;
if (TagsTree.Items.Count < 1)
{
loadedTags = false;
}
//had to do this cause for whatever reason the multithreading prevented it from actually filtering the tags
hook_text.Text = "Loaded Tags";
// the filter thing used to be here lol
}
public Dictionary<string, string> InhaledTagnames = new();
public void inhale_tagnames()
{
string filename = Directory.GetCurrentDirectory() + @"\files\tagnames.txt";
IEnumerable<string>? lines = System.IO.File.ReadLines(filename);
foreach (string? line in lines)
{
string[] hexString = line.Split(" : ");
if (!InhaledTagnames.ContainsKey(hexString[0]))
{
InhaledTagnames.Add(hexString[0], hexString[1]);
}
}
}
public string convert_ID_to_tag_name(string value)
{
_ = InhaledTagnames.TryGetValue(value, value: out string? potentialName);
return potentialName ??= "ObjectID: " + value;
}
public static string ReverseString(string myStr)
{
char[] myArr = myStr.ToCharArray();
Array.Reverse(myArr);
return new string(myArr);
}
public void CreateTagEditorTabByTagIndex(string tagID)
{
TagStruct? tag = TagsList[tagID];
string? tagFull = "(" + tag.Datnum + ") " + convert_ID_to_tag_name(tag.ObjectId);
string tagName = tagFull.Split('\\').Last();
// Find the existing layout document ( draggable panel item )
if (dockManager.Layout.Descendents().OfType<LayoutDocument>().Any())
{
LayoutDocument? dockSearch = dockManager.Layout.Descendents()
.OfType<LayoutDocument>()
.FirstOrDefault(a => a.ContentId == tagFull);
// Check if we found the tag
if (dockSearch != null)
{
// Set the tag as active
if (dockSearch.IsActive)
{
dockSearch.IsActive = true;
}
// Set the tag as the active tab
if (dockSearch.Parent is LayoutDocumentPane ldp)
{
for (int x = 0; x < ldp.Children.Count; x++)
{
LayoutContent dlp = ldp.Children[x];
if (dlp == dockSearch)
{
bool? found = true;
ldp.SelectedContentIndex = x;
}
else
{
bool? found = false; // used for debugging
}
}
}
return;
}
}
// Create the tag editor.
TagEditorControl? tagEditor = new TagEditorControl(this);
tagEditor.Inhale_tag(tagID);
// Create the layout document for docking.
LayoutDocument doc = tagEditor.LayoutDocument = new LayoutDocument();
doc.Title = tagName;
doc.IsActive = true;
doc.Content = tagEditor;
doc.ContentId = tagFull;
dockLayoutDocPane.Children.Add(doc);
dockLayoutRoot.ActiveContent = doc;
}
private void Select_Tag_click(object sender, RoutedEventArgs e)
{
TreeViewItem? item = sender as TreeViewItem;
CreateTagEditorTabByTagIndex(item.Tag.ToString());
}
// list of changes to ammend to the memory when we phit the poke button
// i think it goes: address, type, value
// address instructions | value type | value value
public Dictionary<string, Poke_queue> Pokelistlist = new();
public class Poke_queue
{
public Dictionary<string, KeyValuePair<string, string>> Pokelist =new();
public Dictionary<string, KeyValuePair<string, string>>? revertlist = new();
}
public string current_pokelist = "";
public void add_new_section_to_pokelist(string newname)
{
if (!Pokelistlist.ContainsKey(newname))
{
ComboBoxItem? comboBoxItem = new() { Content = newname };
PokeList_Combobox.Items.Add(comboBoxItem);
Pokelistlist[newname] = new();
PokeList_Combobox.SelectedIndex = PokeList_Combobox.Items.Count - 1;
}
current_pokelist = newname;
}
private void PokeList_Combobox_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
var comboBoxItem = PokeList_Combobox.SelectedItem as ComboBoxItem;
if (comboBoxItem != null)
{
load_a_pokelist(comboBoxItem.Content.ToString());
}
}
public void load_a_pokelist(string queuename)
{
if (Pokelistlist.ContainsKey(queuename))
{
current_pokelist = queuename;
if (queuename == "Poke Queue")
{
remove_from_quee_button.IsEnabled = false;
}
else
{
remove_from_quee_button.IsEnabled = true;
}
changes_panel.Children.Clear();
UIpokelist.Clear();
for (int i = 0; i< Pokelistlist[queuename].Pokelist.Count; i++)
{
KeyValuePair<string, KeyValuePair<string, string>> peep_this_one = Pokelistlist[queuename].Pokelist.ElementAt(i);
string instuctions = peep_this_one.Key;
string value_type = peep_this_one.Value.Key;
string value_itself = peep_this_one.Value.Value;
string revert = "none";
if (Pokelistlist[queuename].revertlist.ContainsKey(instuctions))
{
revert = Pokelistlist[queuename].revertlist[instuctions].Value;
}
if (UIpokelist.ContainsKey(instuctions))
{
TagChangesBlock updateElement = UIpokelist[instuctions];
updateElement.address.Text = instuctions;
updateElement.sig_address_path = instuctions;
updateElement.type.Text = value_type;
updateElement.value.Text = value_itself;
//updateElement.tagSource.Text = def.TagStruct.TagFile + " + " + def.GetTagOffset();
string dont_Be_null = convert_ID_to_tag_name(instuctions.Split(":").FirstOrDefault());
updateElement.tagSource.Text = dont_Be_null;
updateElement.bordercolor.BorderBrush = new SolidColorBrush(Colors.Yellow);
updateElement.revert.Text = revert;
}
else
{
TagChangesBlock newBlock = new()
{
address = { Text = instuctions },
type = { Text = value_type },
value = { Text = value_itself },
};
string dont_Be_null = convert_ID_to_tag_name(instuctions.Split(":").FirstOrDefault());
newBlock.tagSource.Text = dont_Be_null;
newBlock.sig_address_path = instuctions;
newBlock.revert.Text = revert;
newBlock.main = this;
changes_panel.Children.Add(newBlock);
UIpokelist.Add(instuctions, newBlock);
}
}
}
}
// to keep track of the UI elements we're gonna use a dictionary, will probably be better
public Dictionary<string, TagChangesBlock> UIpokelist = new(); // i *think* we can just leave this as is
private void Save_pokes(object sender, RoutedEventArgs e)
{
var sfd = new Microsoft.Win32.SaveFileDialog
{
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 (var 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 Open_pokes(object sender, RoutedEventArgs e)
{
if (!loadedTags)
{
HookAndLoad();
}
// Create OpenFileDialog
Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog();
// Set filter for file extension and default file extension
dlg.DefaultExt = ".irtv";
dlg.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);
}
}
public void recieve_file_to_inhalo_pokes(string filename)
{
int prev = 0;
int fails = 0;
// Open document
add_new_section_to_pokelist(Path.GetFileName(filename));
using (StreamReader inputFile = new StreamReader(filename))
{
string line;
while ((line = inputFile.ReadLine()) != null)
{
string[] parts = line.Split(";");
if (parts.Length == 3)
{
prev++;
AddPokeChange(new TagEditorDefinition { OffsetOverride = parts[0], MemoryType = parts[1], }, parts[2]);
}
}
}
// nothing could cause an issue here // was that sarcastic lol
if (fails < 1)
{
poke_text.Text = prev + " Loaded!";
if (mwidow != null)
{
mwidow.debug_text.Text = prev + " Changes Loaded!";
}
}
else
{
poke_text.Text = prev + " Loaded, " + fails + " Failed";
if (mwidow != null)
{
mwidow.debug_text.Text = prev + " Changes Loaded, " + fails + " Changes Failed";
}
}
}
public void AddPokeChange(TagEditorDefinition def, string value)
{
// Hmm we need to change this so we either update or add a new UI element
//used things
// offset override
// memory type
// value
// tagname
Pokelistlist[current_pokelist].Pokelist[def.OffsetOverride] = new KeyValuePair<string, string>(def.MemoryType, value);
// there we go, now we aren't touching the pokelist code
if (UIpokelist.ContainsKey(def.OffsetOverride))
{
TagChangesBlock updateElement = UIpokelist[def.OffsetOverride];
updateElement.address.Text = def.OffsetOverride;
updateElement.sig_address_path = def.OffsetOverride;
updateElement.type.Text = def.MemoryType;
updateElement.value.Text = value;
//updateElement.tagSource.Text = def.TagStruct.TagFile + " + " + def.GetTagOffset();
string dont_Be_null = convert_ID_to_tag_name(def.OffsetOverride.Split(":").FirstOrDefault());
updateElement.tagSource.Text = dont_Be_null;
updateElement.bordercolor.BorderBrush = new SolidColorBrush(Colors.Yellow);
}
else
{
TagChangesBlock newBlock = new()
{
address = { Text = def.OffsetOverride },
type = { Text = def.MemoryType },
value = { Text = value },
};
string dont_Be_null = convert_ID_to_tag_name(def.OffsetOverride.Split(":").FirstOrDefault());
newBlock.tagSource.Text = dont_Be_null;
newBlock.sig_address_path = def.OffsetOverride;
newBlock.main = this;
changes_panel.Children.Add(newBlock);
UIpokelist.Add(def.OffsetOverride, newBlock);
}
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";
}
if (CbxAutoPokeChanges.IsChecked)
{
bool passed = pokesingle(def.OffsetOverride, def.MemoryType, value, current_pokelist);
if (!passed)
{
UIpokelist[def.OffsetOverride].bordercolor.BorderBrush = new SolidColorBrush(Colors.Red);
}
else
{
UIpokelist[def.OffsetOverride].bordercolor.BorderBrush = null;
}
}
}
// need this to read tagref blocks - because we only get a datnum to figure out the name with
// so we find what else has the same datnum and then run the other method to get name based off of ID
public string get_tagid_by_datnum(string datnum)
{
foreach (KeyValuePair<string, TagStruct> t in TagsList)
{
if (t.Value.Datnum == datnum)
{
return t.Value.ObjectId;
}
}
return "Tag not present(" + datnum + ")";
}
// wtf is this one for
// WHY ARE THEY BOTH USED HAHAHAHA
public string get_tagID_by_datnum(string datnum)
{
//tag_struct t in Tags_List
foreach (KeyValuePair<string, TagStruct> curr_tag in TagsList)
{
if (curr_tag.Value.Datnum == datnum)
{
return curr_tag.Key;
}
}
return "FFFFFFFF"; // ok i found out what this was for: when we poke FFFFFFFF tag // annnnd it didnt work
}
public void PokeChanges()
{
if (!hooked)
{
poke_text.Text = "you MUST 'Load' first";
return;
}
int fails = 0;
int pokes = 0;
for (int q = 0; q < Pokelistlist.Count; q++)
{
KeyValuePair<int, int> kv = pokelist(Pokelistlist.ElementAt(q).Key);
fails += kv.Value;
pokes += kv.Key;
}
if (fails < 1)
{
poke_text.Text = pokes + " changes poked!";
if (mwidow != null)
{
mwidow.debug_text.Text = pokes + " changes poked!";
}
}
else
{