Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Tags Tree Optimizations, Event Logger #137

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 27 additions & 0 deletions EventLogger.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace InfiniteRuntimeTagViewer
{
public class EventLogger
{

public static void LogEvent(string message)
{
//Log to file

using (StreamWriter w = File.AppendText("log.txt"))
{
w.WriteLine(message);
}

}

}


}
14 changes: 11 additions & 3 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
</Grid>

<!-- Tags Tree -->
<TreeView x:Name="TagsTree" Grid.Row="1" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling">
<TreeView x:Name="TagsTree" Grid.Row="1" VirtualizingPanel.IsVirtualizing="True" VirtualizingPanel.VirtualizationMode="Recycling" >
<TreeViewItem Header="[Tutorial]" />
<TreeViewItem Header="1. Press the load button to get started!" />
<TreeViewItem Header="2. Press again whenever the map/zoneset changes." />
Expand All @@ -257,8 +257,16 @@
<TextBlock x:Name="statusText" Text="Not hooked" VerticalAlignment="Center"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Grid.Column="1">
<Button x:Name="LoadBtn" Content="Load" Click="BtnLoadTags_Click" Width="60" Height="25" />
<Button x:Name="Reload_Button" Content="Reload" Click="BtnReLoadTags_Click" Margin="5, 0, 0, 0" IsEnabled="False" Width="60" Height="25" />
<Button x:Name="LoadBtn" Content="Load" Click="BtnLoadTags_Click" Width="60" Height="25">
<Button.ToolTip>
<TextBlock Foreground="Black">Load New Tags</TextBlock>
</Button.ToolTip>
</Button>
<Button x:Name="Reload_Button" Content="Reload" Click="BtnReLoadTags_Click" Margin="5, 0, 0, 0" IsEnabled="False" Width="60" Height="25" >
<Button.ToolTip>
<TextBlock Foreground="Black">Clear Tags List And Hard Reload</TextBlock>
</Button.ToolTip>
</Button>
</StackPanel>
</Grid>
</Grid>
Expand Down
200 changes: 130 additions & 70 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
using Newtonsoft.Json.Linq;
using System.Xml;
using InfiniteRuntimeTagViewer.Halo.TagStructDump;
using System.Text;

namespace InfiniteRuntimeTagViewer
{
Expand Down Expand Up @@ -167,6 +168,9 @@ private void window_SizeChanged(object sender, SizeChangedEventArgs e)
}
}




private void BtnReloadProcessClick(object sender, RoutedEventArgs e)
{
foreach (Process? process in Process.GetProcessesByName("HaloInfinite"))
Expand Down Expand Up @@ -289,6 +293,7 @@ private void Search()
string search = Searchbox.Text;
foreach (TreeViewItem tv in TagsTree.Items)
{

if (!tv.Header.ToString().Contains(search))
{
tv.Visibility = Visibility.Collapsed;
Expand All @@ -315,6 +320,11 @@ private void Search()
}
}
}

private void Tv_Expanded(object sender, RoutedEventArgs e)
{
throw new NotImplementedException();
}
#endregion

#region MenuCommands
Expand All @@ -338,7 +348,7 @@ public ProcessSelector GetProcessSelector()

public void UnloadTags(object sender, RoutedEventArgs e)
{
TagsTree.Items.Clear();
Tags.Clear();
loadedTags = false;
}

Expand Down Expand Up @@ -730,14 +740,15 @@ private void UpdateOption_for_hiding_unloaded(object sender, RoutedEventArgs e)
// load tags from Mem
public void BtnReLoadTags_Click(object sender, RoutedEventArgs e)
{
TagsTree.Items.Clear();
Tags.Clear();
groups_headers.Clear();
tags_headers.Clear();
HookAndLoad();
}

private void BtnLoadTags_Click(object sender, RoutedEventArgs e)
{
//Tags.Clear();
HookAndLoad();
Reload_Button.IsEnabled = true;
}
Expand Down Expand Up @@ -827,7 +838,7 @@ public bool SlientHookAndLoad(bool load_tags_too)
{
if (load_tags_too)
{
TagsTree.Items.Clear();
Tags.Clear();
groups_headers.Clear();
tags_headers.Clear();
LoadTagsMem(true);
Expand All @@ -854,7 +865,7 @@ private async Task HookProcessAsync()
BaseAddress = -1;
hooked = false;
loadedTags = false;
TagsTree.Items.Clear();
Tags.Clear();
}

if (!hooked || reset)
Expand Down Expand Up @@ -1007,102 +1018,139 @@ await Task.Run((Action) (() =>
}
}

public void Loadtags()
public string GetTagNameFromCache(string objectId)
{
Dictionary<string, TreeViewItem> tags_headers_diff = new();
Dictionary<string, TreeViewItem> groups_headers_diff = new();
loadedTags = true;

for (int i = 0; i < TagGroups.Count; i++)
if (InhaledTagnames.TryGetValue(objectId, out string tagName))
{
return tagName;
}
else
{
// Handle the case where the objectId is not in the cache
// This could involve fetching the tag name from a database or file, for example
// For simplicity, we'll just return the objectId
return objectId;
}
}
private ObservableCollection<TreeViewItem> _tags = new ObservableCollection<TreeViewItem>();
public ObservableCollection<TreeViewItem> Tags
{
get { return _tags; }
set
{
KeyValuePair<string, GroupTagStruct> goop = TagGroups.ElementAt(i);
_tags = value;
OnPropertyChanged("Tags");
}
}

if (groups_headers.Keys.Contains(goop.Key))
{
TreeViewItem t = groups_headers[goop.Key];
groups_headers_diff.Add(goop.Key, t);
groups_headers.Remove(goop.Key);
public event PropertyChangedEventHandler PropertyChanged;

GroupTagStruct displayGroup = goop.Value;
displayGroup.TagCategory = t;
TagGroups[goop.Key] = displayGroup;
}
else
{
GroupTagStruct displayGroup = goop.Value;
TreeViewItem sortheader = new();
protected virtual void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public async void Loadtags()
{

if (TagsTree.ItemsSource == null)
{
TagsTree.Items.Clear();
}

sortheader.Header = displayGroup.TagGroupName + " (" + displayGroup.TagGroupDesc + ")";
sortheader.ToolTip = new TextBlock { Foreground = Brushes.Black, Text = displayGroup.TagGroupDefinitition };
displayGroup.TagCategory = sortheader;
TagsTree.ItemsSource = Tags;

TagGroups[goop.Key] = displayGroup;
TagsTree.Items.Add(sortheader);
Dictionary<string, GroupTagStruct> tempTagGroups = new(TagGroups);
Dictionary<string, TreeViewItem> tags_headers_diff = new();
Dictionary<string, TreeViewItem> groups_headers_diff = new();
loadedTags = true;

groups_headers_diff.Add(goop.Key, sortheader);
foreach (var goop in tempTagGroups)
{
if (!groups_headers.TryGetValue(goop.Key, out TreeViewItem t))
{
GroupTagStruct displayGroup = goop.Value;
// Check if the tree view item already exists in the UI
if (!Tags.Any(item => item.Header.ToString() == new StringBuilder().Append(displayGroup.TagGroupName).Append(" (").Append(displayGroup.TagGroupDesc).Append(")").ToString()))
{
t = new TreeViewItem
{
Header = new StringBuilder().Append(displayGroup.TagGroupName).Append(" (").Append(displayGroup.TagGroupDesc).Append(")").ToString(),
ToolTip = new TextBlock { Foreground = Brushes.Black, Text = displayGroup.TagGroupDefinitition },


};
displayGroup.TagCategory = t;
Tags.Add(t);
}
}

TagGroups[goop.Key] = goop.Value;
groups_headers_diff.Add(goop.Key, t);
}

foreach (KeyValuePair<string, TagStruct> curr_tag in TagsList.OrderBy(key => key.Value.TagFullName))

foreach (KeyValuePair<string, TagStruct> curr_tag in TagsList)
{
if (!curr_tag.Value.unloaded)
{
if (tags_headers.Keys.Contains(curr_tag.Key))
if (tags_headers.TryGetValue(curr_tag.Key, out TreeViewItem t))
{
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
{
TreeViewItem t = new();
TagStruct tag = curr_tag.Value;
TagGroups.TryGetValue(tag.TagGroup, out GroupTagStruct? dictTagGroup);
// Check if a TreeViewItem with the same tag datnum and object id already exists
bool itemExists = false;
if (Tags.Count > 0)
{
itemExists = Tags.Any(item => item.Tag != null && ((string) item.Tag).Split(' ')[0] == curr_tag.Value.Datnum && ((string) item.Tag).Split(' ')[1] == GetTagNameFromCache(curr_tag.Value.ObjectId));

}

t.Header = "(" + tag.Datnum + ") " + convert_ID_to_tag_name(tag.ObjectId);
t.Tag = curr_tag.Key;
t.Selected += Select_Tag_click;

if (dictTagGroup != null && dictTagGroup.TagCategory != null)
if (!itemExists)
{
dictTagGroup.TagCategory.Items.Add(t);
}
TreeViewItem tr = new();
TagStruct tag = curr_tag.Value;
TagGroups.TryGetValue(tag.TagGroup, out GroupTagStruct? dictTagGroup);

tags_headers_diff.Add(curr_tag.Key, t);
}
}
}
tr.Header = new StringBuilder().Append("(").Append(tag.Datnum).Append(") ").Append(GetTagNameFromCache(tag.ObjectId)).ToString();
tr.Tag = curr_tag.Key;
tr.Selected += Select_Tag_click;

foreach (KeyValuePair<string, TreeViewItem> poop in groups_headers)
{
if (poop.Value != null)
{
TagsTree.Items.Remove(poop.Value);
}
}
if (dictTagGroup != null && dictTagGroup.TagCategory != null)
{
dictTagGroup.TagCategory.Items.Add(tr);
}

foreach (KeyValuePair<string, TreeViewItem> poop in tags_headers)
{
if (poop.Value != null)
{
TreeViewItem ownber = (TreeViewItem) poop.Value.Parent;
ownber.Items.Remove(poop.Value);
tags_headers_diff.Add(curr_tag.Key, tr);
}
}
}
}

tags_headers = tags_headers_diff;
groups_headers = groups_headers_diff;

if (TagsTree.Items.Count < 1)
{
loadedTags = false;
}

//foreach (var item in tags_headers.Values)
// {
// TreeViewItem owner = (TreeViewItem)item.Parent;
// owner.Items.Remove(item);
// }

tags_headers = tags_headers_diff;
groups_headers = groups_headers_diff;

if (TagsTree.Items.Count < 1)
{
loadedTags = false;
}

TagsTree.Items.SortDescriptions.Add(new SortDescription("Header", ListSortDirection.Ascending));

SetStatus("Loaded Tags!");
}
SetStatus("Loaded Tags!");
}


public async Task ScanMem()
{
Expand Down Expand Up @@ -1160,7 +1208,17 @@ public async Task ScanMem()
Settings.Default.ProcAsyncBaseAddr = "HaloInfinite.exe+0x" + (pointer - haloInfinite).ToString("X");
Settings.Default.Save();
Debug.WriteLine(Settings.Default.ProcAsyncBaseAddr);

EventLogger.LogEvent("AOB Scan Dump:");
EventLogger.LogEvent("AOB Scan: " + aobSingle);
EventLogger.LogEvent("AOB Scan Result: " + aobScan.ToString("X"));
EventLogger.LogEvent("AOB Scan Result (Reversed): " + aobSingle);
EventLogger.LogEvent("AOB Scan Result (Pointer): " + pointer.ToString("X"));
EventLogger.LogEvent("AOB Scan Result (Pointer - HaloInfinite.exe): " + (pointer - haloInfinite).ToString("X"));
EventLogger.LogEvent("AOB Scan Result (HaloInfinite.exe+0x): " + Settings.Default.ProcAsyncBaseAddr);
foreach (long aobResult in aobScanResults)
{
EventLogger.LogEvent("AOB Scan Result (All): " + aobResult.ToString("X"));
}
}

// Failed to find base tag address
Expand All @@ -1178,9 +1236,11 @@ public async Task ScanMem()
hooked = true;
}
}
catch (Exception)
catch (Exception ex)
{
SetStatus("Cant find HaloInfinite.exe");
EventLogger.LogEvent("Exception Thrown:");
EventLogger.LogEvent(ex.ToString());
}
}
}
Expand Down
Loading