Skip to content

Commit

Permalink
performance fixes & shit
Browse files Browse the repository at this point in the history
  • Loading branch information
szaaamerik committed Jan 12, 2024
1 parent 47487e5 commit ed70aa2
Show file tree
Hide file tree
Showing 18 changed files with 477 additions and 349 deletions.
4 changes: 2 additions & 2 deletions Forza-Mods-AIO/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -365,7 +365,7 @@ private static void ClearDetours()
{
UnlocksPage.XpDetour.Clear();
UnlocksPage.CrDetour.Clear();
UnlocksPage.CrCompareDetour.Clear();
UnlocksPage.CrCmpDetour.Clear();
CustomizationPage.GlowingPaintDetour.Clear();
CustomizationPage.HeadlightDetour.Clear();
CustomizationPage.CleanlinessDetour.Clear();
Expand Down Expand Up @@ -422,7 +422,7 @@ private static void DestroyDetours()
UnlocksPage.CrDetour.Destroy();
UnlocksPage.SeasonalDetour.Destroy();
UnlocksPage.SeriesDetour.Destroy();
UnlocksPage.CrCompareDetour.Destroy();
UnlocksPage.CrCmpDetour.Destroy();
UnlocksPage.SpinsDetour.Destroy();
UnlocksPage.SkillPointsDetour.Destroy();
CustomizationPage.GlowingPaintDetour.Destroy();
Expand Down
14 changes: 13 additions & 1 deletion Forza-Mods-AIO/Resources/Bypass.cs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,12 @@ private static bool PointChecksToCopyFh5()
}

checkAddr += Mw.Gvp.Plat == "MS" ? (UIntPtr)325 : 333;

if (Mw.M.ReadMemory<byte>(checkAddr) == 0xE9)
{
return true;
}

var procHandle = Mw.Gvp.Process.Handle;
var memSize = (uint)Mw.Gvp.Process.MainModule.ModuleMemorySize;

Expand Down Expand Up @@ -130,7 +136,13 @@ private static bool PointChecksToCopyFm8()
return false;
}

checkAddr += Mw.Gvp.Plat == "MS" ? (UIntPtr)329 : 337;
checkAddr += 329;

if (Mw.M.ReadMemory<byte>(checkAddr) == 0xE9)
{
return true;
}

var procHandle = Mw.Gvp.Process.Handle;
var memSize = (uint)Mw.Gvp.Process.MainModule.ModuleMemorySize;

Expand Down
13 changes: 8 additions & 5 deletions Forza-Mods-AIO/Resources/Detour.cs
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,14 @@ public static void FailedHandler(object @switch, RoutedEventHandler action, bool
{
return;
}

toggleSwitch.Toggled -= action;
toggleSwitch.IsOn = false;
toggleSwitch.Toggled += action;


Application.Current.Dispatcher.Invoke(() =>
{
toggleSwitch.Toggled -= action;
toggleSwitch.IsOn = false;
toggleSwitch.Toggled += action;
});

const string fh4String = "This feature was never ported to FH4";
const string failedString = "Failed";
MessageBox.Show(fh4 ? fh4String : failedString);
Expand Down
30 changes: 20 additions & 10 deletions Forza-Mods-AIO/Tabs/Self-Vehicle/DropDownTabs/HandlingPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@
Margin="7.5 0 0 0"
SelectedIndex="0"
Background="#FF2E3440"
BorderBrush="#FF2E3440">
BorderBrush="#FF2E3440"
SelectionChanged="VelModeBox_OnSelectionChanged">

<ComboBoxItem Content="Dynamic"/>
<ComboBoxItem Content="Direct"/>
Expand Down Expand Up @@ -80,7 +81,8 @@
TrackMouseWheelWhenMouseOver="True"
Culture="en-GB"
Background="#FF2E3440"
BorderBrush="#FF2E3440"/>
BorderBrush="#FF2E3440"
ValueChanged="VelLimitBox_OnValueChanged"/>


</StackPanel>
Expand Down Expand Up @@ -132,7 +134,8 @@
TrackMouseWheelWhenMouseOver="True"
Culture="en-GB"
Background="#FF2E3440"
BorderBrush="#FF2E3440"/>
BorderBrush="#FF2E3440"
ValueChanged="StrengthBox_OnValueChanged"/>


<Label Content="Interval"
Expand All @@ -155,7 +158,8 @@
TrackMouseWheelWhenMouseOver="True"
Culture="en-GB"
Background="#FF2E3440"
BorderBrush="#FF2E3440"/>
BorderBrush="#FF2E3440"
ValueChanged="IntervalBox_OnValueChanged"/>



Expand All @@ -169,7 +173,8 @@
Width="78.5"
VerticalAlignment="Center"
Background="#FF2E3440"
BorderBrush="#FF2E3440">
BorderBrush="#FF2E3440"
SelectionChanged="WheelSpeedModeBox_OnSelectionChanged">
<ComboBoxItem Content="Static"/>
<ComboBoxItem Content="Linear"/>
<ComboBoxItem Content="Power"/>
Expand Down Expand Up @@ -292,7 +297,8 @@
TrackMouseWheelWhenMouseOver="True"
Culture="en-GB"
Background="#FF2E3440"
BorderBrush="#FF2E3440"/>
BorderBrush="#FF2E3440"
ValueChanged="TurnAssistStrengthBox_OnValueChanged"/>


<Label Content="Interval"
Expand All @@ -314,7 +320,8 @@
UpDownButtonsFocusable="False"
TrackMouseWheelWhenMouseOver="True"
Background="#FF2E3440"
BorderBrush="#FF2E3440"/>
BorderBrush="#FF2E3440"
ValueChanged="TurnAssistIntervalBox_OnValueChanged"/>


<Label Content="Ratio"
Expand All @@ -337,7 +344,8 @@
TrackMouseWheelWhenMouseOver="True"
Culture="en-GB"
Background="#FF2E3440"
BorderBrush="#FF2E3440"/>
BorderBrush="#FF2E3440"
ValueChanged="TurnAssistRatioBox_OnValueChanged"/>

</Grid>
</Border>
Expand Down Expand Up @@ -415,7 +423,8 @@
TrackMouseWheelWhenMouseOver="True"
Background="#FF2E3440"
BorderBrush="#FF2E3440"
Width="90"/>
Width="90"
ValueChanged="FlyHackMoveSpeedNum_OnValueChanged"/>

<Label Content="Rotation Speed"
HorizontalAlignment="Center"
Expand All @@ -436,7 +445,8 @@
UpDownButtonsFocusable="False"
TrackMouseWheelWhenMouseOver="True"
Background="#FF2E3440"
BorderBrush="#FF2E3440"/>
BorderBrush="#FF2E3440"
ValueChanged="FlyHackRotSpeedNum_OnValueChanged"/>


</Grid>
Expand Down
159 changes: 106 additions & 53 deletions Forza-Mods-AIO/Tabs/Self-Vehicle/DropDownTabs/HandlingPage.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,8 @@
using static System.Math;
using static System.Convert;
using static Forza_Mods_AIO.MainWindow;
using static Forza_Mods_AIO.Resources.KeyStates;
using static Forza_Mods_AIO.Tabs.Self_Vehicle.Entities.CarEntity;
using static Forza_Mods_AIO.Tabs.Self_Vehicle.SelfVehicleAddresses;
using static Forza_Mods_AIO.Tabs.Keybindings.DropDownTabs.HandlingKeybindings;

namespace Forza_Mods_AIO.Tabs.Self_Vehicle.DropDownTabs;

Expand Down Expand Up @@ -80,7 +78,7 @@ public async void PullButton_Click(object sender, RoutedEventArgs e)

private void SetSwitch_Toggled(object sender, RoutedEventArgs e)
{
if (!Mw.Attached || sender is not ToggleSwitch { IsOn: true } toggleSwitch)
if (sender is not ToggleSwitch { IsOn: true } toggleSwitch)
{
return;
}
Expand Down Expand Up @@ -152,33 +150,14 @@ private void StopAllWheelsSwitch_OnToggled(object sender, RoutedEventArgs e)
Task.Run(Braking.StopAllWheels.Run);
}

private float _originalGrav;

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

GravitySetSwitch.IsEnabled = !GravitySetSwitch.IsEnabled;
if (!FlyHackSwitch.IsOn)
if (!Mw.Attached)
{
Gravity = _originalGrav;
return;
}

GravitySetSwitch.IsOn = false;

var count = 0;
while (_originalGrav == 0 && count < 50)
{
++count;
_originalGrav = Gravity;
Task.Delay(5).Wait();
}

Gravity = 0f;
Task.Run(FlyHack.Run);
}

Expand Down Expand Up @@ -220,44 +199,17 @@ private void JumpHackVelocityNum_OnValueChanged(object sender, RoutedPropertyCha
}

JumpHackSlider.Value = ToDouble(JumpHackVelocityNum.Value);
JumpHack.SetBoost(JumpHackVelocityNum.Value);
}

private void JumpHackSwitch_OnToggled(object sender, RoutedEventArgs e)
{
if (!JumpHackSwitch.IsOn || !Mw.Attached)
if (!JumpHackSwitch.IsOn)
{
return;
}

Task.Run(() =>
{
while (true)
{
var toggled = true;
Dispatcher.Invoke(() => toggled = JumpHackSwitch.IsOn);
if (!toggled)
{
break;
}
if (!IsKeyPressed(Hk.JmpHack) && !Mw.Gamepad.IsButtonPressed(JmpHackController))
{
Task.Delay(25).Wait();
continue;
}
var jmpVal = 1f;
Dispatcher.Invoke(() => jmpVal = ToSingle(JumpHackVelocityNum.Value));
LinearVelocity = LinearVelocity with { Y = LinearVelocity.Y + jmpVal };
while (IsKeyPressed(Hk.JmpHack) || Mw.Gamepad.IsButtonPressed(JmpHackController))
{
Task.Delay(50).Wait();
}
}
});
Task.Run(JumpHack.Run);
}

private void VelValueNum_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double?> e)
Expand All @@ -268,6 +220,7 @@ private void VelValueNum_OnValueChanged(object sender, RoutedPropertyChangedEven
}

VelValueNum.Value = Round(ToDouble(e.NewValue), 2);
Velocity.SetBoost(VelValueNum.Value);
}

private void StopAllWheelsModeBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
Expand Down Expand Up @@ -324,4 +277,104 @@ private void SuperBrakeSlider_OnValueChanged(object sender, RoutedPropertyChange
SuperBrakeVelocity.Value = Round(slider.Value, 4);
Braking.SuperBrake.SetStrength(slider.Value);
}

private void FlyHackMoveSpeedNum_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double?> e)
{
if (sender is not NumericUpDown numericUpDown)
{
return;
}

FlyHack.SetMoveSpeed(numericUpDown.Value);
}

private void FlyHackRotSpeedNum_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double?> e)
{
if (sender is not NumericUpDown numericUpDown)
{
return;
}

FlyHack.SetRotSpeed(numericUpDown.Value);
}

private void StrengthBox_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double?> e)
{
if (sender is not NumericUpDown numericUpDown)
{
return;
}

Features.WheelSpeed.SetBoostFactor(numericUpDown.Value);
}

private void IntervalBox_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double?> e)
{
if (sender is not NumericUpDown numericUpDown)
{
return;
}

Features.WheelSpeed.SetInterval(numericUpDown.Value);
}

private void WheelSpeedModeBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is not ComboBox comboBox)
{
return;
}

Features.WheelSpeed.SetMode(comboBox.SelectedIndex);
}

private void VelModeBox_OnSelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (sender is not ComboBox comboBox)
{
return;
}

Velocity.SetMode(comboBox.SelectedIndex);
}

private void VelLimitBox_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double?> e)
{
if (sender is not NumericUpDown numericUpDown)
{
return;
}

Velocity.SetLimit(numericUpDown.Value);
}

private void TurnAssistStrengthBox_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double?> e)
{
if (sender is not NumericUpDown numericUpDown)
{
return;
}

TurnAssist.SetStrength(numericUpDown.Value);
}

private void TurnAssistIntervalBox_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double?> e)
{
if (sender is not NumericUpDown numericUpDown)
{
return;
}

TurnAssist.SetInterval(numericUpDown.Value);
}

private void TurnAssistRatioBox_OnValueChanged(object sender, RoutedPropertyChangedEventArgs<double?> e)
{
if (sender is not NumericUpDown numericUpDown)
{
return;
}

TurnAssist.SetRatio(numericUpDown.Value);
}
}

0 comments on commit ed70aa2

Please sign in to comment.