Skip to content

Commit

Permalink
code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
szaaamerik committed Jan 6, 2024
1 parent 9491a4b commit 6a98b31
Show file tree
Hide file tree
Showing 24 changed files with 345 additions and 609 deletions.
1 change: 0 additions & 1 deletion Forza-Mods-AIO/Forza-Mods-AIO.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@
<PackageReference Include="MahApps.Metro" Version="2.4.9" />
<PackageReference Include="Octokit" Version="9.0.0" />
<PackageReference Include="SharpDX" Version="4.2.0" />
<PackageReference Include="SharpDX.DirectInput" Version="4.2.0" />
<PackageReference Include="SharpDX.XInput" Version="4.2.0" />
</ItemGroup>
<ItemGroup>
Expand Down
2 changes: 1 addition & 1 deletion Forza-Mods-AIO/MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
WindowTransitionsEnabled="False" Title="Forza Mods AIO"
WindowStartupLocation="CenterOwner">

<Border x:Name="Background" Background="#111111"
<Border x:Name="BackgroundBorder" Background="#111111"
CornerRadius="20">
<Grid>
<Grid.ColumnDefinitions>
Expand Down
25 changes: 14 additions & 11 deletions Forza-Mods-AIO/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,12 @@ public partial class MainWindow
{
public class GameVerPlat
{
public string? Name { get; }
public string? Plat { get; }
public Process? Process { get; }
public string? Update { get; }
public string Name { get; }
public string Plat { get; }
public Process Process { get; }
public string Update { get; }

public GameVerPlat(string? name, string? plat, Process? process, string? update)
public GameVerPlat(string name, string plat, Process process, string update)
{
Name = name;
Plat = plat;
Expand All @@ -69,7 +69,7 @@ public GameVerPlat(string? name, string? plat, Process? process, string? update)
public readonly Mem M = new() { SigScanTasks = Environment.ProcessorCount };
//public LibraryMapper Mapper = null!;
public readonly Gamepad Gamepad = new();
public GameVerPlat Gvp = new(null, null, null, null);
public GameVerPlat Gvp = new(string.Empty, string.Empty, new Process(), string.Empty);
public bool Attached { get; private set; }
private IEnumerable<Visual>? _visuals;

Expand All @@ -86,7 +86,7 @@ public MainWindow()
new SolidColorBrush((Color)ConvertFromString("#FF2E3440")!), true, false));
Current.ChangeTheme(Application.Current, "AccentCol");
AIO_Info.IsChecked = true;
Background.Background = Monet.MainColour;
BackgroundBorder.Background = Monet.MainColour;
FrameBorder.Background = Monet.MainColour;
SideBar.Background = Monet.DarkishColour;
TopBar1.Background = Monet.DarkColour;
Expand Down Expand Up @@ -268,7 +268,7 @@ private void ToggleButtons(bool on)
private void GvpMaker(string name)
{
string platform;
string? update;
string update;
var process = M.MProc.Process;
var gamePath = process.MainModule!.FileName;

Expand All @@ -286,7 +286,7 @@ private void GvpMaker(string name)
{
var filePath = Combine(GetDirectoryName(gamePath) ?? throw new Exception(), "OnlineFix64.dll");
platform = File.Exists(filePath) ? "OnlineFix - Steam" : "Steam";
update = GetVersionInfo(process.MainModule!.FileName).FileVersion;
update = GetVersionInfo(process.MainModule!.FileName).FileVersion ?? "Unable to get update info";
}

Gvp = new GameVerPlat(name, platform, process, update);
Expand Down Expand Up @@ -385,7 +385,6 @@ private static void ClearDetours()
MiscellaneousPage.Build2Detour.Clear();
MiscellaneousPage.SkillTreeDetour.Clear();
MiscellaneousPage.ScoreDetour.Clear();
HandlingPage.FlyHackDetour.Clear();
MiscellaneousPage.SkillCostDetour.Clear();
MiscellaneousPage.DriftDetour.Clear();
MiscellaneousPage.TimeScaleDetour.Clear();
Expand Down Expand Up @@ -436,7 +435,6 @@ private static void DestroyDetours()
LocatorEntity.WaypointDetour.Destroy();
EnvironmentPage.TimeDetour.Destroy();
EnvironmentPage.FreezeAiDetour.Destroy();
HandlingPage.FlyHackDetour.Destroy();
MiscellaneousPage.Build1Detour.Destroy();
MiscellaneousPage.Build2Detour.Destroy();
MiscellaneousPage.ScaleDetour.Destroy();
Expand All @@ -453,6 +451,11 @@ private static void DestroyDetours()

private void RevertWrites()
{
if (Gvp.Process.MainModule == null)
{
return;
}

if (Gvp.Name != "Forza Horizon 5" && SuperCarAddr > (UIntPtr)Gvp.Process.MainModule.BaseAddress)
{
M.WriteArrayMemory(SuperCarAddr + 4, new byte[] { 0x0F, 0x11, 0x41, 0x10 });
Expand Down
24 changes: 12 additions & 12 deletions Forza-Mods-AIO/Overlay/Options/FloatOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Forza_Mods_AIO.Overlay.Options;

public class FloatOption : MenuOption
public sealed class FloatOption : MenuOption
{
public float Value
{
Expand All @@ -21,24 +21,24 @@ public float Value
public float Minimum { get; } = float.MinValue;
public float Maximum { get; } = float.MaxValue;

public event EventHandler? ValueChanged;
public event EventHandler? MinimumReached;
public event EventHandler? MaximumReached;
public event RoutedEventHandler? ValueChanged;
public event RoutedEventHandler? MinimumReached;
public event RoutedEventHandler? MaximumReached;

protected virtual void OnValueChanged()
private void OnValueChanged()
{
var handler = ValueChanged;
if (handler == null)
{
return;
}

Application.Current.Dispatcher.BeginInvoke(() => handler(this, EventArgs.Empty));
Application.Current.Dispatcher.BeginInvoke(() => handler(this, new RoutedEventArgs()));
}

protected virtual void OnMinimumReached(float value)
private void OnMinimumReached(float value)
{
if (value != Minimum)
if (Math.Abs(value - Minimum) > 0.000001)
{
return;
}
Expand All @@ -49,12 +49,12 @@ protected virtual void OnMinimumReached(float value)
return;
}

Application.Current.Dispatcher.BeginInvoke(() => handler(this, EventArgs.Empty));
Application.Current.Dispatcher.BeginInvoke(() => handler(this, new RoutedEventArgs()));
}

protected virtual void OnMaximumReached(float value)
private void OnMaximumReached(float value)
{
if (value != Maximum)
if (Math.Abs(value - Maximum) > 0.000001)
{
return;
}
Expand All @@ -65,7 +65,7 @@ protected virtual void OnMaximumReached(float value)
return;
}

Application.Current.Dispatcher.BeginInvoke(() => handler(this, EventArgs.Empty));
Application.Current.Dispatcher.BeginInvoke(() => handler(this, new RoutedEventArgs()));
}

public static FloatOption CreateWithMinimum(string name, float value, float minimum, string? description = null,
Expand Down
20 changes: 10 additions & 10 deletions Forza-Mods-AIO/Overlay/Options/IntOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Forza_Mods_AIO.Overlay.Options;

public class IntOption : MenuOption
public sealed class IntOption : MenuOption
{
public int Value
{
Expand All @@ -21,22 +21,22 @@ public int Value
public int Minimum { get; } = int.MinValue;
public int Maximum { get; } = int.MaxValue;

public event EventHandler? ValueChanged;
public event EventHandler? MinimumReached;
public event EventHandler? MaximumReached;
public event RoutedEventHandler? ValueChanged;
public event RoutedEventHandler? MinimumReached;
public event RoutedEventHandler? MaximumReached;

protected virtual void OnValueChanged()
private void OnValueChanged()
{
var handler = ValueChanged;
if (handler == null)
{
return;
}

Application.Current.Dispatcher.BeginInvoke(() => handler(this, EventArgs.Empty));
Application.Current.Dispatcher.BeginInvoke(() => handler(this, new RoutedEventArgs()));
}

protected virtual void OnMinimumReached(int value)
private void OnMinimumReached(int value)
{
if (Minimum != value)
{
Expand All @@ -49,10 +49,10 @@ protected virtual void OnMinimumReached(int value)
return;
}

Application.Current.Dispatcher.BeginInvoke(() => handler(this, EventArgs.Empty));
Application.Current.Dispatcher.BeginInvoke(() => handler(this, new RoutedEventArgs()));
}

protected virtual void OnMaximumReached(int value)
private void OnMaximumReached(int value)
{
if (Maximum != value)
{
Expand All @@ -65,7 +65,7 @@ protected virtual void OnMaximumReached(int value)
return;
}

Application.Current.Dispatcher.BeginInvoke(() => handler(this, EventArgs.Empty));
Application.Current.Dispatcher.BeginInvoke(() => handler(this, new RoutedEventArgs()));
}

public static IntOption CreateWithMinimum(string name, int value, int minimum, string? description = null, bool isEnabled = true)
Expand Down
9 changes: 7 additions & 2 deletions Forza-Mods-AIO/Overlay/Options/SelectionOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public int Index
private int _index;
public string[] Selections { get; }

public event EventHandler? SelectionChanged;
public event RoutedEventHandler? SelectionChanged;

public SelectionOption(string name, int index, string[] selections, string? description = null, bool isEnabled = true)
{
Expand All @@ -42,6 +42,11 @@ public SelectionOption(string name, int index, string[] selections, string? desc
private void OnSelectionChanged()
{
var handler = SelectionChanged;
Application.Current.Dispatcher.BeginInvoke(() => handler?.Invoke(this, EventArgs.Empty));
if (handler == null)
{
return;
}

Application.Current.Dispatcher.BeginInvoke(() => handler(this, new RoutedEventArgs()));
}
}
8 changes: 4 additions & 4 deletions Forza-Mods-AIO/Overlay/Options/ToggleOption.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

namespace Forza_Mods_AIO.Overlay.Options;

public class ToggleOption : MenuOption
public sealed class ToggleOption : MenuOption
{
public bool IsOn
{
Expand All @@ -21,17 +21,17 @@ public bool IsOn
}
private bool _isOn;

public event EventHandler? Toggled;
public event RoutedEventHandler? Toggled;

protected virtual void OnToggled()
private void OnToggled()
{
var handler = Toggled;
if (handler == null)
{
return;
}

Application.Current.Dispatcher.BeginInvoke(() => handler(this, EventArgs.Empty));
Application.Current.Dispatcher.BeginInvoke(() => handler(this, new RoutedEventArgs()));
}

public ToggleOption(string name, bool isOn, string? description = null, bool isEnabled = true)
Expand Down
3 changes: 2 additions & 1 deletion Forza-Mods-AIO/Overlay/OverlayHandling.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,8 @@ private void SelectHeader()
{
_headerImage = _headerImage.Clone();
}
_headerImage = (BitmapImage)Headers.Find(x => x[0].ToString().Contains(_menuHeaders[HeaderIndex].Split('\\').Last().Split('.').First()))?[1];
_headerImage = (BitmapImage)Headers.Find(x =>
x[0].ToString()!.Contains(_menuHeaders[HeaderIndex].Split('\\').Last().Split('.').First()))![1];
_headerImage?.Dispatcher.Invoke(() => _headerImage.Freeze());
}
}
Expand Down
8 changes: 4 additions & 4 deletions Forza-Mods-AIO/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Reflection;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Windows;

[assembly: AssemblyTitle("WPF-Mockup")]
[assembly: AssemblyDescription("")]
Expand All @@ -12,6 +11,7 @@
[assembly: AssemblyCopyright("Copyright © 2023")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: SuppressMessage("Usage", "CA1416:This call site is reachable on all platforms")]

[assembly: ComVisible(false)]
[assembly: ThemeInfo(ResourceDictionaryLocation.None,ResourceDictionaryLocation.SourceAssembly)]
Expand Down
2 changes: 1 addition & 1 deletion Forza-Mods-AIO/Resources/Detour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public void Toggle()
return;
}

if (!IsSetup)
if (!IsSetup || _realOriginalBytes == null)
{
return;
}
Expand Down

0 comments on commit 6a98b31

Please sign in to comment.