Skip to content

Commit

Permalink
changes
Browse files Browse the repository at this point in the history
- stop tuning from writing values when they update
- improve bypass stuff
- add byte checks before detouring
- fixed aero offsets
- attach is faster if you are already ingame, bc you dont wait the second thats for the Task.Delay
  • Loading branch information
szaaamerik committed Jan 5, 2024
1 parent 0daa35f commit 71f0565
Show file tree
Hide file tree
Showing 25 changed files with 590 additions and 410 deletions.
126 changes: 80 additions & 46 deletions Forza-Mods-AIO/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,10 @@
using Memory;
using Forza_Mods_AIO.Overlay;
using Forza_Mods_AIO.Resources;
using Forza_Mods_AIO.Tabs.AutoShowTab;
using Forza_Mods_AIO.Tabs.Keybindings.DropDownTabs;
using Forza_Mods_AIO.Tabs.Self_Vehicle.DropDownTabs;
using Forza_Mods_AIO.Tabs.Self_Vehicle.Entities;
using Forza_Mods_AIO.Tabs.Tuning;
using Lunar;
using MahApps.Metro.Controls;
using static System.Diagnostics.FileVersionInfo;
using static System.IO.Path;
Expand Down Expand Up @@ -94,8 +92,11 @@ public MainWindow()
TopBar1.Background = Monet.DarkColour;
TopBar2.Background = Monet.DarkColour;
CategoryButton_Click(AIO_Info, new RoutedEventArgs());
Loaded += (_, _) => ToggleButtons(false);
Task.Run(IsAttached);
Loaded += (_, _) =>
{
Task.Run(IsAttached);
ToggleButtons(false);
};
}

private async void UpdateAio()
Expand Down Expand Up @@ -194,9 +195,16 @@ public void CategoryButton_Click(object sender, RoutedEventArgs e)

private void IsAttached()
{
var firstTime = true;
while (true)
{
Task.Delay(Attached ? 1000 : 500).Wait();
if (!firstTime)
{
Task.Delay(Attached ? 1000 : 500).Wait();
}

firstTime = false;

if (M.OpenProcess("ForzaHorizon5"))
{
if (Attached)
Expand Down Expand Up @@ -386,13 +394,19 @@ private void Window_Closing(object sender, CancelEventArgs e)
}
catch { /* ignored */ }

if (!Attached)
if (!Attached || Gvp.Process?.MainModule == null || Gvp.Name == null)
{
Environment.Exit(0);
}

//TODO Cleanup here

DestroyDetours();
RevertWrites();
EnableAntiCheat();
Environment.Exit(0);
}

private static void DestroyDetours()
{
TuningAsm.Cleanup();
UnlocksPage.XpDetour.Destroy();
UnlocksPage.CrDetour.Destroy();
Expand All @@ -409,7 +423,6 @@ private void Window_Closing(object sender, CancelEventArgs e)
LocatorEntity.WaypointDetour.Destroy();
EnvironmentPage.TimeDetour.Destroy();
EnvironmentPage.FreezeAiDetour.Destroy();
LocatorEntity.WaypointDetour.Destroy();
HandlingPage.FlyHackDetour.Destroy();
MiscellaneousPage.Build1Detour.Destroy();
MiscellaneousPage.Build2Detour.Destroy();
Expand All @@ -420,48 +433,71 @@ private void Window_Closing(object sender, CancelEventArgs e)
MiscellaneousPage.SkillCostDetour.Destroy();
MiscellaneousPage.DriftDetour.Destroy();
MiscellaneousPage.TimeScaleDetour.Destroy();
MiscellaneousPage.UnbSkillDetour.Destroy();
BackFirePage.BackFire.BackfireTimeDetour.Destroy();
BackFirePage.BackFire.BackfireTypeDetour.Destroy();
}

try
private void RevertWrites()
{
if (Gvp.Name != "Forza Horizon 5" && SuperCarAddr > (UIntPtr)Gvp.Process.MainModule.BaseAddress)
{
if (Gvp.Name == "Forza Horizon 5")
{
M.WriteArrayMemory(SuperCarAddr - 4, new byte[] { 0x0F, 0x11, 0x41, 0x10 });
}

M.WriteArrayMemory(SuperCarAddr + 4, Gvp.Name == "Forza Horizon 4" ? new byte[] { 0x0F, 0x11, 0x41, 0x10 } : new byte[] { 0x0F, 0x11, 0x49, 0x20 });
M.WriteArrayMemory(SuperCarAddr + 12, Gvp.Name == "Forza Horizon 4" ? new byte[] { 0x0F, 0x11, 0x49, 0x20 } : new byte[] { 0x0F, 0x11, 0x41, 0x30 });
M.WriteArrayMemory(SuperCarAddr + 20, Gvp.Name == "Forza Horizon 4" ? new byte[] { 0x0F, 0x11, 0x41, 0x30 } : new byte[] { 0x0F, 0x11, 0x49, 0x40 });
M.WriteArrayMemory(SuperCarAddr + 32, Gvp.Name == "Forza Horizon 4" ? new byte[] { 0x0F, 0x11, 0x49, 0x40 } : new byte[] { 0x0F, 0x11, 0x41, 0x50 });

M.WriteMemory(SunRedAddr, 0.003921568859f);
M.WriteMemory(SunGreenAddr, 0.003921568859f);
M.WriteMemory(SunBlueAddr, 0.003921568859f);
M.WriteArrayMemory(SuperCarAddr + 4, new byte[] { 0x0F, 0x11, 0x41, 0x10 });
M.WriteArrayMemory(SuperCarAddr + 12, new byte[] { 0x0F, 0x11, 0x49, 0x20 });
M.WriteArrayMemory(SuperCarAddr + 20, new byte[] { 0x0F, 0x11, 0x41, 0x30 });
M.WriteArrayMemory(SuperCarAddr + 32, new byte[] { 0x0F, 0x11, 0x49, 0x40 });
}

if (SunRedAddr > (UIntPtr)Gvp.Process.MainModule.BaseAddress)
{
Mw.M.WriteArrayMemory(SunRedAddr, new byte[] { 0x81, 0x80, 0x80, 0x3B, 0x81, 0x80, 0x80, 0x3B, 0x81, 0x80, 0x80, 0x3B, 0x81, 0x80, 0x80, 0x3B });
}

if (WaterAddr > (UIntPtr)Gvp.Process.MainModule.BaseAddress)
{
M.WriteMemory(WaterAddr, new Vector3(0f, 3700f, 13500f));

M.WriteArrayMemory(Wall1Addr, Gvp.Name == "Forza Horizon 4" ? new byte[] { 0x0F, 0x84, 0x29, 0x02, 0x00, 0x00 } : new byte[] { 0x0F, 0x84, 0x60, 0x02, 0x00, 0x00 });
M.WriteArrayMemory(Wall2Addr, Gvp.Name == "Forza Horizon 4" ? new byte[] { 0x0F, 0x84, 0x2A, 0x02, 0x00, 0x00 } : new byte[] { 0x0F, 0x84, 0x7E, 0x02, 0x00, 0x00 });
M.WriteArrayMemory(Car1Addr, Gvp.Name == "Forza Horizon 4" ? new byte[] { 0x0F, 0x84, 0xB5, 0x01, 0x00, 0x00 } : new byte[] { 0x0F, 0x84, 0x65, 0x03, 0x00, 0x00 });
}

if (WorldCollisionThreshold != 0)
{
Mw.M.WriteMemory(WorldCollisionThreshold, 12f);
Mw.M.WriteMemory(CarCollisionThreshold,12f);
Mw.M.WriteMemory(SmashableCollisionTolerance,22f);
}
if (Wall1Addr > (UIntPtr)Gvp.Process.MainModule.BaseAddress)
{
M.WriteArrayMemory(Wall1Addr, Gvp.Name == "Forza Horizon 4"
? new byte[] { 0x0F, 0x84, 0x29, 0x02, 0x00, 0x00 }
: new byte[] { 0x0F, 0x84, 0x60, 0x02, 0x00, 0x00 });
}

Mw.M.WriteArrayMemory(XpAmountAddr, Mw.Gvp.Name.Contains('5')
? new byte[] { 0x8B, 0x89, 0xB8, 0x00, 0x00, 0x00 }
: new byte[] { 0x8B, 0x89, 0xC0, 0x00, 0x00, 0x00 });

if (Wall2Addr > (UIntPtr)Gvp.Process.MainModule.BaseAddress)
{
M.WriteArrayMemory(Wall2Addr, Gvp.Name == "Forza Horizon 4"
? new byte[] { 0x0F, 0x84, 0x2A, 0x02, 0x00, 0x00 }
: new byte[] { 0x0F, 0x84, 0x7E, 0x02, 0x00, 0x00 });
}

if (Car1Addr > (UIntPtr)Gvp.Process.MainModule.BaseAddress)
{
M.WriteArrayMemory(Car1Addr, Gvp.Name == "Forza Horizon 4"
? new byte[] { 0x0F, 0x84, 0xB5, 0x01, 0x00, 0x00 }
: new byte[] { 0x0F, 0x84, 0x65, 0x03, 0x00, 0x00 });
}

if (Car2Addr > (UIntPtr)Gvp.Process.MainModule.BaseAddress)
{
M.WriteArrayMemory(Car2Addr, new byte[] { 0x0F, 0x84, 0x3A, 0x03, 0x00, 0x00 });
}
catch { /* ignored */ }

EnableAntiCheat();
Environment.Exit(0);
if (WorldCollisionThreshold != 0)
{
Mw.M.WriteMemory(WorldCollisionThreshold, 12f);
Mw.M.WriteMemory(CarCollisionThreshold,12f);
Mw.M.WriteMemory(SmashableCollisionTolerance,22f);
}

if (XpAmountAddr > (UIntPtr)Gvp.Process.MainModule.BaseAddress)
{
Mw.M.WriteArrayMemory(XpAmountAddr, Gvp.Name.Contains('5')
? new byte[] { 0x8B, 0x89, 0x88, 0x00, 0x00, 0x00 }
: new byte[] { 0x8B, 0x89, 0xC0, 0x00, 0x00, 0x00 });
}

}
#endregion

Expand Down Expand Up @@ -576,18 +612,16 @@ public static IEnumerable<Visual> GetChildren(this Visual? parent, Visual? targe
return GetChildrenPrivate(parent, target, recurse);
}

private static bool IsOnTarget(DependencyObject visual, Visual target)
private static bool IsOnTarget(DependencyObject? visual, Visual target)
{
var currentVisual = visual;

while (currentVisual != null)
while (visual != null)
{
if (currentVisual == target)
if (visual == target)
{
return true;
}

currentVisual = GetParent(currentVisual);
visual = GetParent(visual);
}

return false;
Expand Down
119 changes: 64 additions & 55 deletions Forza-Mods-AIO/Overlay/Menus/TuningMenu/SubMenus/Gearing/Gearing.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public abstract class Gearing
private static readonly FloatOption NinthGearValue = new("Ninth Gear", 0f);
private static readonly FloatOption TenthGearValue = new("Tenth Gear", 0f);

private static readonly ButtonOption GearingPull = new("Pull values", () =>
private static readonly ButtonOption GearingPull = new("Pull values", PullValues);

public static void PullValues()
{
FinalDriveValue.Value = Convert.ToSingle(G.FinalDriveBox.Value);
ReverseGearValue.Value = Convert.ToSingle(G.ReverseGearBox.Value);
Expand All @@ -34,119 +36,126 @@ public abstract class Gearing
EighthGearValue.Value = Convert.ToSingle(G.EighthGearBox.Value);
NinthGearValue.Value = Convert.ToSingle(G.NinthGearBox.Value);
TenthGearValue.Value = Convert.ToSingle(G.TenthGearBox.Value);
});
}

private static void FinalDriveValueChanged(object s, EventArgs e)
{
var gearing = G;
gearing.Dispatcher.Invoke(() =>
if (s is not FloatOption floatOption)
{
gearing.FinalDriveBox.Value = (float)s.GetType().GetProperty("Value")!.GetValue(s)!;
});
return;
}

G.FinalDriveBox.Value = floatOption.Value;
}

private static void ReverseGearValueChanged(object s, EventArgs e)
{
var gearing = G;
gearing.Dispatcher.Invoke(() =>
if (s is not FloatOption floatOption)
{
gearing.FinalDriveBox.Value = (float)s.GetType().GetProperty("Value")!.GetValue(s)!;
});
return;
}

G.FinalDriveBox.Value = floatOption.Value;
}

private static void FirstGearValueChanged(object s, EventArgs e)
{
var gearing = G;
gearing.Dispatcher.Invoke(() =>
if (s is not FloatOption floatOption)
{
gearing.FinalDriveBox.Value = (float)s.GetType().GetProperty("Value")!.GetValue(s)!;
});
return;
}

G.FinalDriveBox.Value = floatOption.Value;
}

private static void SecondGearValueChanged(object s, EventArgs e)
{
var gearing = G;
gearing.Dispatcher.Invoke(() =>
if (s is not FloatOption floatOption)
{
gearing.SecondGearBox.Value = (float)s.GetType().GetProperty("Value")!.GetValue(s)!;
});
return;
}

G.SecondGearBox.Value = floatOption.Value;
}

private static void ThirdGearValueChanged(object s, EventArgs e)
{
var gearing = G;
gearing.Dispatcher.Invoke(() =>
if (s is not FloatOption floatOption)
{
gearing.ThirdGearBox.Value = (float)s.GetType().GetProperty("Value")!.GetValue(s)!;
});
return;
}

G.ThirdGearBox.Value = floatOption.Value;
}

private static void FourthGearValueChanged(object s, EventArgs e)
{
var gearing = G;
gearing.Dispatcher.Invoke(() =>
if (s is not FloatOption floatOption)
{
gearing.FourthGearBox.Value = (float)s.GetType().GetProperty("Value")!.GetValue(s)!;
});
return;
}

G.FourthGearBox.Value = floatOption.Value;
}

private static void FifthGearValueChanged(object s, EventArgs e)
{
var gearing = G;
gearing.Dispatcher.Invoke(() =>
if (s is not FloatOption floatOption)
{
gearing.FifthGearBox.Value = (float)s.GetType().GetProperty("Value")!.GetValue(s)!;
});
return;
}

G.FifthGearBox.Value = floatOption.Value;
}

private static void SixthGearValueChanged(object s, EventArgs e)
{
var gearing = G;

gearing.Dispatcher.Invoke(() =>
if (s is not FloatOption floatOption)
{
gearing.SixthGearBox.Value = (float)s.GetType().GetProperty("Value")!.GetValue(s)!;
});
return;
}

G.SixthGearBox.Value = floatOption.Value;
}

private static void SeventhGearValueChanged(object s, EventArgs e)
{
var gearing = G;

gearing.Dispatcher.Invoke(() =>
if (s is not FloatOption floatOption)
{
gearing.SeventhGearBox.Value = (float)s.GetType().GetProperty("Value")!.GetValue(s)!;
});
return;
}

G.SeventhGearBox.Value = floatOption.Value;
}

private static void EighthGearValueChanged(object s, EventArgs e)
{
var gearing = G;

gearing.Dispatcher.Invoke(() =>
if (s is not FloatOption floatOption)
{
gearing.EighthGearBox.Value = (float)s.GetType().GetProperty("Value")!.GetValue(s)!;
});
return;
}

G.EighthGearBox.Value = floatOption.Value;
}

private static void NinthGearValueChanged(object s, EventArgs e)
{
var gearing = G;

gearing.Dispatcher.Invoke(() =>
if (s is not FloatOption floatOption)
{
gearing.NinthGearBox.Value = (float)s.GetType().GetProperty("Value")!.GetValue(s)!;
});
return;
}

G.NinthGearBox.Value = floatOption.Value;
}

private static void TenthGearValueChanged(object s, EventArgs e)
{
var gearing = G;

gearing.Dispatcher.Invoke(() =>
if (s is not FloatOption floatOption)
{
gearing.TenthGearBox.Value = (float)s.GetType().GetProperty("Value")!.GetValue(s)!;
});
return;
}

G.TenthGearBox.Value = floatOption.Value;
}

public static readonly List<MenuOption> GearingOptions = new()
Expand Down

0 comments on commit 71f0565

Please sign in to comment.