Skip to content

Commit

Permalink
initial fm8 support
Browse files Browse the repository at this point in the history
  • Loading branch information
szaaamerik committed Jan 7, 2024
1 parent 20d4549 commit a579969
Show file tree
Hide file tree
Showing 5 changed files with 203 additions and 69 deletions.
1 change: 0 additions & 1 deletion Forza-Mods-AIO/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,6 @@ private static void ClearDetours()
EnvironmentPage.WasTimeDetoured = false;
TeleportsPage.WaypointDetoured = false;
Clear();
IsScanRunning = false;
}
#endregion
#region Exit Handling
Expand Down
77 changes: 61 additions & 16 deletions Forza-Mods-AIO/Resources/Bypass.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
using System;
using System.Linq;
using System.Threading.Tasks;
using static System.BitConverter;
using static Memory.Imps;
using static System.BitConverter;
using static Forza_Mods_AIO.MainWindow;

namespace Forza_Mods_AIO.Resources;
Expand All @@ -17,12 +16,18 @@ public abstract class Bypass

private static readonly Detour CheckDetour = new(true);
private static UIntPtr _memCopyAddress = UIntPtr.Zero;

private static UIntPtr _protectedAddresses = UIntPtr.Zero;

public static bool DisableAntiCheat()
{
if (!Mw.Gvp.Name.Contains('4'))
if (Mw.Gvp.Name.Contains('5'))
{
return PointChecksToCopy();
return PointChecksToCopyFh5();
}

if (Mw.Gvp.Name.Contains('8'))
{
return PointChecksToCopyFm8();
}

DisableFh4();
Expand All @@ -31,13 +36,12 @@ public static bool DisableAntiCheat()

public static void EnableAntiCheat()
{
if (Mw.Gvp.Name.Contains('5'))
if (Mw.Gvp.Name.Contains('5') || Mw.Gvp.Name.Contains('8'))
{
Destroy();
return;
}


var ntDll = GetModuleHandle("ntdll.dll");

if (_rtlUserThreadStartOrig != null)
Expand All @@ -62,23 +66,15 @@ private static void DisableFh4()
Mw.M.WriteArrayMemory(ntCreateThreadEx, NtCreateThreadExPatch);
}

public static bool IsScanRunning { get; set; }
private static bool Bypassed { get; set; }

private static bool PointChecksToCopy()
private static bool PointChecksToCopyFh5()
{
if (Bypassed)
{
return true;
}

if (IsScanRunning)
{
return false;
}

IsScanRunning = true;

const string sig = "40 8A ? E9 ? ? ? ? CC";
var checkAddr = Mw.M.ScanForSig(sig).FirstOrDefault();

Expand Down Expand Up @@ -110,6 +106,55 @@ private static bool PointChecksToCopy()
return Bypassed = true;
}

private static bool PointChecksToCopyFm8()
{
if (Bypassed)
{
return true;
}

const string sig = "E8 ? ? ? ? 40 8A ? E9 ? ? ? ? CC";
var checkAddr = Mw.M.ScanForSig(sig).FirstOrDefault() + 5;

if (checkAddr < (UIntPtr)Mw.Gvp.Process.MainModule!.BaseAddress)
{
return false;
}

checkAddr += Mw.Gvp.Plat == "MS" ? (UIntPtr)329 : 337;
var procHandle = Mw.Gvp.Process.Handle;
var memSize = (uint)Mw.Gvp.Process.MainModule.ModuleMemorySize;

const int protectedAddressesSize = 0x800;
_memCopyAddress = VirtualAllocEx(procHandle, UIntPtr.Zero, memSize, MemCommit | MemReserve, ExecuteReadwrite);
_protectedAddresses = VirtualAllocEx(procHandle, UIntPtr.Zero, protectedAddressesSize, MemCommit | MemReserve, ExecuteReadwrite);
WriteProcessMemory(procHandle, _memCopyAddress, Mw.M._memoryCache["default"], memSize, nint.Zero);

const string checkBytes = "51 56 53 52 48 31 C9 48 8B 35 48 00 00 00 48 8B 14 CE 48 83 FA 00 74 30 48 8B DA " +
"48 81 EA 00 10 00 00 48 39 D0 72 1C 48 81 C3 00 10 00 00 48 39 D8 77 10 48 2B 05 " +
"24 00 00 00 48 03 05 25 00 00 00 EB 05 48 FF C1 EB C6 5A 5B 5E 59 F3 0F 6F 50 F0";

const string checkOriginalBytes = "F3 0F 6F 50 F0";

if (!CheckDetour.Setup(checkAddr, checkOriginalBytes, checkBytes, 5, true))
{
Destroy();
return false;
}

var baseAddress = Mw.Gvp.Process.MainModule.BaseAddress;
var addresses = GetBytes(_protectedAddresses).Concat(GetBytes(baseAddress)).Concat(GetBytes(_memCopyAddress)).ToArray();
CheckDetour.UpdateVariable(addresses);
AddProtectAddress(checkAddr);
return Bypassed = true;
}

public static void AddProtectAddress(UIntPtr address)
{
Mw.M.WriteMemory(_protectedAddresses, address);
_protectedAddresses += 8;
}

private static void Destroy()
{
CheckDetour.Destroy();
Expand Down
17 changes: 13 additions & 4 deletions Forza-Mods-AIO/Resources/Detour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@ public Detour(bool bypassDetour = false)
}

var process = Mw.Gvp.Process;
if (5 > replaceCount || process?.MainModule == null || addr <= (UIntPtr)process.MainModule.BaseAddress)
process.Refresh();
if (5 > replaceCount || process.MainModule == null || addr <= (UIntPtr)process.MainModule.BaseAddress)
{
return false;
}
Expand Down Expand Up @@ -94,18 +95,23 @@ public Detour(bool bypassDetour = false)
finalDetourBytes = combinedBytes;
}

if (Mw.Gvp.Name.Contains('5') && !_bypassDetour && !Bypass.DisableAntiCheat())
if ((Mw.Gvp.Name.Contains('5') || Mw.Gvp.Name.Contains('8')) && !_bypassDetour && !Bypass.DisableAntiCheat())
{
ToggleButton(button, true);
return false;
}


if (Mw.Gvp.Name.Contains('8'))
{
Bypass.AddProtectAddress(addr);
}

if (!CreateDetour(finalDetourBytes, replaceCount))
{
ToggleButton(button, true);
return false;
}

if (useVarAddress)
{
VariableAddress = _allocatedAddress + (UIntPtr)finalDetourBytes.Length + varAddressOffset + 5;
Expand Down Expand Up @@ -192,6 +198,7 @@ public void Toggle()
return;
}

Mw.Gvp.Process.Refresh();
var currentBytes = Mw.M.ReadArrayMemory<byte>(_detourAddr, _realOriginalBytes.Length);

if (currentBytes.SequenceEqual(_realOriginalBytes))
Expand Down Expand Up @@ -222,6 +229,7 @@ private bool CreateDetour(byte[] caveBytes, int replaceCount)
return;
}

Mw.Gvp.Process.Refresh();
Mw.M.WriteMemory(VariableAddress + varOffset, value);
}

Expand All @@ -232,6 +240,7 @@ private bool CreateDetour(byte[] caveBytes, int replaceCount)
return;
}

Mw.Gvp.Process.Refresh();
Mw.M.WriteArrayMemory(VariableAddress + varOffset, value);
}

Expand Down

0 comments on commit a579969

Please sign in to comment.