Skip to content

Commit

Permalink
flyhack improvements and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
szaaamerik committed Jan 6, 2024
1 parent 71f0565 commit b25d053
Show file tree
Hide file tree
Showing 4 changed files with 133 additions and 264 deletions.
25 changes: 19 additions & 6 deletions Forza-Mods-AIO/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -210,16 +210,28 @@ private void IsAttached()
if (Attached)
continue;

GvpMaker(5);
const string name = "Forza Horizon 5";
GvpMaker(name);
ToggleButtons(true);
Attached = true;
}
else if (M.OpenProcess("ForzaHorizon4"))
{
if (Attached)
continue;

GvpMaker(4);

const string name = "Forza Horizon 4";
GvpMaker(name);
ToggleButtons(true);
Attached = true;
}
else if (M.OpenProcess("forza_gaming.desktop.x64_release_final"))
{
if (Attached)
continue;

const string name = "Forza Motorsport 8";
GvpMaker(name);
ToggleButtons(true);
Attached = true;
}
Expand Down Expand Up @@ -253,14 +265,15 @@ private void ToggleButtons(bool on)
});
}

private void GvpMaker(int ver)
private void GvpMaker(string name)
{
string platform;
string? update;
var process = M.MProc.Process;
var gamePath = process.MainModule!.FileName;

if (gamePath.Contains("Microsoft.624F8B84B80") || gamePath.Contains("Microsoft.SunriseBaseGame"))
if (gamePath.Contains("Microsoft.624F8B84B80") || gamePath.Contains("Microsoft.SunriseBaseGame") ||
gamePath.Contains("Microsoft.ForzaMotorsport"))
{
platform = "MS";
var filePath = Combine(GetDirectoryName(gamePath) ?? throw new Exception(), "appxmanifest.xml");
Expand All @@ -276,7 +289,7 @@ private void GvpMaker(int ver)
update = GetVersionInfo(process.MainModule!.FileName).FileVersion;
}

Gvp = new GameVerPlat($"Forza Horizon {ver}", platform, process, update);
Gvp = new GameVerPlat(name, platform, process, update);

Dispatcher.Invoke(delegate
{
Expand Down
179 changes: 31 additions & 148 deletions Forza-Mods-AIO/Tabs/Self-Vehicle/DropDownTabs/HandlingPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -653,26 +653,19 @@ private void StopAllWheelsSwitch_OnToggled(object sender, RoutedEventArgs e)
while (true)
{
bool toggled = true;
var toggled = true;
Dispatcher.Invoke(delegate { toggled = StopAllWheelsSwitch.IsOn; });
if (!toggled)
{
break;
}
if (Mw.Gvp.Process!.MainWindowHandle != GetForegroundWindow())
{
Task.Delay(25).Wait();
continue;
}
if (GetCarSpeed() < 10)
if (Mw.Gvp.Process!.MainWindowHandle != GetForegroundWindow() || GetCarSpeed() < 10)
{
Task.Delay(25).Wait();
continue;
}
if (GetAsyncKeyState(Hk.BrakeHack) is not (1 or short.MinValue) &&
!Mw.Gamepad.IsButtonPressed(BrakeHackController))
{
Expand All @@ -690,20 +683,18 @@ private void StopAllWheelsSwitch_OnToggled(object sender, RoutedEventArgs e)

private void FlyHackSwitch_OnToggled(object sender, RoutedEventArgs e)
{
if (!Mw.Attached)
if (!Mw.Attached || FlyHackSwitch == null)
{
return;
}

if (Mw.Gvp.Name.Contains('4'))
{
Detour.FailedHandler(sender, FlyHackSwitch_OnToggled, true);
return;
}

GravitySetSwitch.IsEnabled = !GravitySetSwitch.IsEnabled;
FlyHackDetour.Toggle();

if (!FlyHackSwitch.IsOn)
{
Gravity = _originalGrav;
Expand All @@ -715,173 +706,67 @@ private void FlyHackSwitch_OnToggled(object sender, RoutedEventArgs e)
GravitySetSwitch.IsOn = false;
}

const string bytes = "48 39 0D 10 00 00 00 74 09 F3 44 0F 10 89 94 00 00 00";
if (!FlyHackDetour.Setup(sender, FlyhackHookAddr, null, bytes, 9, true))
{
Detour.FailedHandler(sender, FlyHackSwitch_OnToggled);
FlyHackDetour.Clear();
return;
}
_originalGrav = Gravity;
FlyHackDetour.UpdateVariable(BitConverter.GetBytes(PlayerCarEntity));
Gravity = 0f;

// Rotation
Task.Run(() =>
{
CultureInfo.CurrentCulture = new CultureInfo("en-GB");
var aDown = false;
var dDown = false;
while (true)
{
var toggled = true;
Dispatcher.Invoke(() => toggled = FlyHackSwitch.IsOn);
if (!toggled)
{
break;
}
if (Mw.Gvp.Process.MainWindowHandle != GetForegroundWindow())
{
Task.Delay(25).Wait();
continue;
}
bool aDown = false, dDown = false;
bool wDown = false, sDown = false, shiftDown = false, controlDown = false;
UpdateRotationKeyStates(ref aDown, ref dDown);
if (!aDown && !dDown)
{
Task.Delay(25).Wait();
continue;
}
var flyHackRotSpeed = 1f;
Dispatcher.Invoke(() => flyHackRotSpeed = ToSingle(FlyHackRotSpeedNum.Value / 2));
HandleRotation(flyHackRotSpeed, aDown, dDown);
Task.Delay(10).Wait();
}
});

// Movement
Task.Run(() =>
{
CultureInfo.CurrentCulture = new CultureInfo("en-GB");
while (true)
{
var toggled = true;
Dispatcher.Invoke(delegate { toggled = FlyHackSwitch.IsOn; });
Dispatcher.Invoke(() => toggled = FlyHackSwitch.IsOn);
if (!toggled)
{
break;
}
Rotation = Rotation with { Z = 1f };
LinearVelocity = new Vector3 { X = 0f, Z = 0f, Y = 0f };
AngularVelocity = new Vector3 { X = 0f, Z = 0f, Y = 0f };
if (Mw.Gvp.Process.MainWindowHandle != GetForegroundWindow())
{
Task.Delay(25).Wait();
continue;
}
bool wDown = false, sDown = false, shiftDown = false, controlDown = false;
UpdateRotationKeyStates(ref aDown, ref dDown);
UpdateMovementKeyStates(ref wDown, ref sDown, ref shiftDown, ref controlDown);
if (!wDown && !sDown && !shiftDown && !controlDown)
if (aDown || dDown)
{
Task.Delay(25).Wait();
continue;
var flyHackRotSpeed = 1f;
Dispatcher.Invoke(() => flyHackRotSpeed = ToSingle(FlyHackRotSpeedNum.Value / 2));
HandleRotation(flyHackRotSpeed, aDown);
}
var angle = (float)((float)Atan2(Rotation.X, Rotation.Y) * (180 / PI));
if (angle < 0)
if (wDown || sDown || shiftDown || controlDown)
{
angle += 360;
var angle = (float)((float)Atan2(Rotation.M13, Rotation.M11) * (180 / PI));
if (angle < 0)
{
angle += 360;
}
var flyHackMoveSpeed = Dispatcher.Invoke(() => (float)FlyHackMoveSpeedNum.Value / 2);
HandleMovement(angle, flyHackMoveSpeed, wDown, sDown, shiftDown, controlDown);
}
float flyHackMoveSpeed = 1;
Dispatcher.Invoke(() => flyHackMoveSpeed = ToSingle(FlyHackMoveSpeedNum.Value / 2));
HandleMovement(angle,flyHackMoveSpeed,wDown,sDown,shiftDown,controlDown);
Task.Delay(10).Wait();
}
});
}

private static void HandleRotation(float speed, bool aDown, bool dDown)
private static void HandleRotation(float speed, bool aDown)
{
if (aDown)
{
Rotation = Rotation.X switch
{
// Top right
>= 0 when Rotation.Y >= 0 => Rotation with
{
X = Rotation.X + speed / 10,
Y = Rotation.Y - speed / 10
},
// Bottom right
>= 0 when Rotation.Y <= 0 => Rotation with
{
X = Rotation.X - speed / 10,
Y = Rotation.Y - speed / 10
},
// Bottom Left
<= 0 when Rotation.Y <= 0 => Rotation with
{
X = Rotation.X - speed / 10,
Y = Rotation.Y + speed / 10
},
// Top Left
<= 0 when Rotation.Y >= 0 => Rotation with
{
X = Rotation.X + speed / 10,
Y = Rotation.Y + speed / 10
},
_ => Rotation
};
}

else if (dDown)
{
Rotation = Rotation.X switch
{
// Top right
>= 0 when Rotation.Y >= 0 => Rotation with
{
X = Rotation.X - speed / 10,
Y = Rotation.Y + speed / 10
},
// Bottom right
>= 0 when Rotation.Y <= 0 => Rotation with
{
X = Rotation.X + speed / 10,
Y = Rotation.Y + speed / 10
},
// Bottom Left
<= 0 when Rotation.Y <= 0 => Rotation with
{
X = Rotation.X + speed / 10,
Y = Rotation.Y - speed / 10
},
// Top Left
<= 0 when Rotation.Y >= 0 => Rotation with
{
X = Rotation.X - speed / 10,
Y = Rotation.Y - speed / 10
},
_ => Rotation
};
}
var angle = (aDown ? -1 : 1) * speed / 10;
var rotationQuaternion = Quaternion.CreateFromAxisAngle(Vector3.UnitY, angle);
var rotationMatrix = Matrix4x4.CreateFromQuaternion(rotationQuaternion);
Rotation *= rotationMatrix;
}

private static void HandleMovement(float angle, float speed, bool wDown, bool sDown, bool shiftDown, bool controlDown)
Expand Down Expand Up @@ -963,14 +848,12 @@ private static void HandleMovement(float angle, float speed, bool wDown, bool sD
break;
}
}

Position = Position with
{
X = Position.X + speed * 5 * xComp,
Z = Position.Z + speed * 5 * zComp
};
}

if (shiftDown)
{
Position = Position with { Y = Position.Y + speed * 5 };
Expand All @@ -981,7 +864,7 @@ private static void HandleMovement(float angle, float speed, bool wDown, bool sD
}
}

private void UpdateMovementKeyStates(ref bool wDown, ref bool sDown, ref bool shiftDown, ref bool controlDown)
private static void UpdateMovementKeyStates(ref bool wDown, ref bool sDown, ref bool shiftDown, ref bool controlDown)
{
if (GetAsyncKeyState(Keys.W) is 1 or short.MinValue && !wDown)
{
Expand Down Expand Up @@ -1024,7 +907,7 @@ private void UpdateMovementKeyStates(ref bool wDown, ref bool sDown, ref bool sh
}
}

private void UpdateRotationKeyStates(ref bool aDown, ref bool dDown)
private static void UpdateRotationKeyStates(ref bool aDown, ref bool dDown)
{
if (GetAsyncKeyState(Keys.A) is 1 or short.MinValue && !aDown)
{
Expand Down

0 comments on commit b25d053

Please sign in to comment.