From 84a4fa7ccb3b44156d8d55512ca8c032ea16edf2 Mon Sep 17 00:00:00 2001 From: szaamerik Date: Wed, 11 Oct 2023 17:07:18 +0200 Subject: [PATCH 1/9] switch to .net 8, make car table faster --- ForzaMods_CarTable/ForzaMods_CarTable.csproj | 6 +- ForzaMods_CarTable/MainWindow.xaml.cs | 114 +++++++------------ 2 files changed, 46 insertions(+), 74 deletions(-) diff --git a/ForzaMods_CarTable/ForzaMods_CarTable.csproj b/ForzaMods_CarTable/ForzaMods_CarTable.csproj index 6d1a2df..10948c4 100644 --- a/ForzaMods_CarTable/ForzaMods_CarTable.csproj +++ b/ForzaMods_CarTable/ForzaMods_CarTable.csproj @@ -2,8 +2,8 @@ WinExe - net7.0-windows - enable + net8.0-windows + disable true app.manifest AnyCPU;x64 @@ -14,6 +14,8 @@ 1.8.0.1 1.8.0.1 en + true + x64 diff --git a/ForzaMods_CarTable/MainWindow.xaml.cs b/ForzaMods_CarTable/MainWindow.xaml.cs index 55c6b43..1aa6d74 100644 --- a/ForzaMods_CarTable/MainWindow.xaml.cs +++ b/ForzaMods_CarTable/MainWindow.xaml.cs @@ -2,6 +2,7 @@ using System.Diagnostics; using System.Globalization; using System.Linq; +using System.Net.Sockets; using System.Runtime.InteropServices; using System.Text.RegularExpressions; using System.Threading; @@ -16,6 +17,9 @@ namespace ForzaMods_CarTable; public partial class MainWindow : Window { + [DllImport("kernel32.dll")] + public static extern int VirtualQueryEx(IntPtr hProcess, IntPtr lpAddress, out MEMORY_BASIC_INFORMATION lpBuffer, uint dwLength); + // variables private readonly Mem M = new(); private string? Address; @@ -25,18 +29,8 @@ public MainWindow() { InitializeComponent(); Task.Run(() => ForzaAttach()); - MessageBox.Show("This is opensource and free." + - "The only official download is the ForzaMods Github or UC. " + - "If you downloaded this off anywhere else than these sources you got scammed. " + - "Please follow the only proper tutorial thats the button in the app or in the UC post." + - "You should never listen to other tutorials that you see."); } - // dll imports - [DllImport("kernel32.dll")] - private static extern int VirtualQueryEx(IntPtr hProcess, IntPtr lpAddress, out MEMORY_BASIC_INFORMATION lpBuffer, - uint dwLength); - // main attach thread private void ForzaAttach() { @@ -129,92 +123,68 @@ private void ScanForID(object sender, RoutedEventArgs e) if (!Attached) return; + Status.Content = "Starting scan"; + Task.Run(async () => { try { - var time = new Stopwatch(); - time.Start(); CultureInfo.CurrentCulture = new CultureInfo("en-GB"); - - Dispatcher.Invoke(() => - { - ScanForIDBtn.IsEnabled = false; - Status.Content = "Scanning for addr"; - }); - var count = 0; - - var si = new SYSTEM_INFO(); - GetSystemInfo(out si); - - long ScanStartAddr; + GetSystemInfo(out var si); + ulong _address = 0xFFFFFFFFFF; + var Proc = M.MProc.Process; + VirtualQueryEx(Proc.Handle, (IntPtr)_address, out var m, (uint)si.PageSize); + _address = (ulong)m.BaseAddress + (ulong)m.RegionSize; + long ScanStartAddr = (long)m.BaseAddress; long ScanEndAddr; + int count = 0; + string AOBString = "BB 0B 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00"; + Address = "0"; - ulong _address = 0xFFFFFFFFFF; - var process = Process.GetProcessesByName("ForzaHorizon5")[0]; - var m = new MEMORY_BASIC_INFORMATION(); - VirtualQueryEx(process.Handle, (IntPtr)_address, out m, si.PageSize); - - _address = m.BaseAddress + (ulong)m.RegionSize; - ScanStartAddr = (long)m.BaseAddress; - while (_address < 0x3FFFFFFFFFF) { - VirtualQueryEx(process.Handle, (IntPtr)_address, out m, si.PageSize); - - if (_address == m.BaseAddress + (ulong)m.RegionSize) + VirtualQueryEx(Proc.Handle, (IntPtr)_address, out m, (uint)si.PageSize); + if (_address == (ulong)m.BaseAddress + (ulong)m.RegionSize) break; - if (m.RegionSize > 70000000000000 && count > 0) break; - ScanEndAddr = (long)m.BaseAddress + m.RegionSize; + ScanEndAddr = (long)m.BaseAddress + (long)m.RegionSize; - if (ScanEndAddr - ScanStartAddr > 500000000) - for (var i = 1; i < 2; i++) - Address = (await M.AoBScan(ScanStartAddr, - ScanStartAddr + (ScanEndAddr - ScanStartAddr) / 2 * i, - "BB 0B 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00", true)).FirstOrDefault().ToString("X"); - else - Address = (await M.AoBScan(ScanStartAddr, ScanEndAddr, - "BB 0B 00 00 00 00 00 00 02 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00", true)).FirstOrDefault().ToString("X"); - - - ScanStartAddr = ScanEndAddr; - - - if (Address != "0") + if (count % 100 == 0) { - Dispatcher.Invoke(() => + if (ScanEndAddr - ScanStartAddr > 500000000) { - time.Stop(); - ScanForIDBtn.IsEnabled = true; - Status.Content = "Scan finished.\nAddr:" + Address + "\nScan took:" + - time.Elapsed.TotalSeconds; - }); - break; + for (int i = 1; i < 2; i++) + { + Address = (await M.AoBScan(ScanStartAddr, ScanStartAddr + (((ScanEndAddr - ScanStartAddr) / 2) * i), AOBString, true, true)).FirstOrDefault().ToString("X"); + } + } + else + { + Address = (await M.AoBScan(ScanStartAddr, ScanEndAddr, AOBString, true, true)).FirstOrDefault().ToString("X"); + } + if (Address != "0") + { + Dispatcher.Invoke(() => Status.Content = $"Finished. Address:\n{Address}"); + break; + } + + ScanStartAddr = ScanEndAddr; } - _address = m.BaseAddress + (ulong)m.RegionSize; + _address = (ulong)m.BaseAddress + (ulong)m.RegionSize; count++; } - if (Address == "0") - Dispatcher.Invoke(() => - { - time.Stop(); - ScanForIDBtn.IsEnabled = true; - Status.Content = "Scan finished. Failed."; - }); + { + Dispatcher.Invoke(() => Status.Content = "Finished. Failed."); + } } - catch (Exception error) + catch (Exception a) { - Dispatcher.Invoke(() => - { - ScanForIDBtn.IsEnabled = true; - Status.Content = "Scan wasnt finished. Failed.\nError: " + error.Message; - }); + Dispatcher.Invoke(() => Status.Content = $"Failed. Exception:\n{a.Message}"); } }); } From 98883a75c33b3d359d7b377de03bb5e49645f006 Mon Sep 17 00:00:00 2001 From: szaamerik <126014478+szaaamerik@users.noreply.github.com> Date: Mon, 4 Dec 2023 18:47:29 +0100 Subject: [PATCH 2/9] delete old files --- ForzaMods_CarTable/App.xaml | 9 - ForzaMods_CarTable/App.xaml.cs | 11 -- ForzaMods_CarTable/AssemblyInfo.cs | 10 - ForzaMods_CarTable/ForzaMods_CarTable.csproj | 35 ---- ForzaMods_CarTable/MainWindow.xaml | 94 --------- ForzaMods_CarTable/MainWindow.xaml.cs | 191 ------------------- ForzaMods_CarTable/Resources/Close.png | Bin 40215 -> 0 bytes ForzaMods_CarTable/Resources/Memory.dll | Bin 68096 -> 0 bytes ForzaMods_CarTable/app.manifest | 79 -------- 9 files changed, 429 deletions(-) delete mode 100644 ForzaMods_CarTable/App.xaml delete mode 100644 ForzaMods_CarTable/App.xaml.cs delete mode 100644 ForzaMods_CarTable/AssemblyInfo.cs delete mode 100644 ForzaMods_CarTable/ForzaMods_CarTable.csproj delete mode 100644 ForzaMods_CarTable/MainWindow.xaml delete mode 100644 ForzaMods_CarTable/MainWindow.xaml.cs delete mode 100644 ForzaMods_CarTable/Resources/Close.png delete mode 100644 ForzaMods_CarTable/Resources/Memory.dll delete mode 100644 ForzaMods_CarTable/app.manifest diff --git a/ForzaMods_CarTable/App.xaml b/ForzaMods_CarTable/App.xaml deleted file mode 100644 index 1a28810..0000000 --- a/ForzaMods_CarTable/App.xaml +++ /dev/null @@ -1,9 +0,0 @@ - - - - - diff --git a/ForzaMods_CarTable/App.xaml.cs b/ForzaMods_CarTable/App.xaml.cs deleted file mode 100644 index ed80c69..0000000 --- a/ForzaMods_CarTable/App.xaml.cs +++ /dev/null @@ -1,11 +0,0 @@ -using System.Windows; - -namespace ForzaMods_CarTable -{ - /// - /// Interaction logic for App.xaml - /// - public partial class App : Application - { - } -} diff --git a/ForzaMods_CarTable/AssemblyInfo.cs b/ForzaMods_CarTable/AssemblyInfo.cs deleted file mode 100644 index 8b5504e..0000000 --- a/ForzaMods_CarTable/AssemblyInfo.cs +++ /dev/null @@ -1,10 +0,0 @@ -using System.Windows; - -[assembly: ThemeInfo( - ResourceDictionaryLocation.None, //where theme specific resource dictionaries are located - //(used if a resource is not found in the page, - // or application resource dictionaries) - ResourceDictionaryLocation.SourceAssembly //where the generic resource dictionary is located - //(used if a resource is not found in the page, - // app, or any theme specific resource dictionaries) -)] diff --git a/ForzaMods_CarTable/ForzaMods_CarTable.csproj b/ForzaMods_CarTable/ForzaMods_CarTable.csproj deleted file mode 100644 index 10948c4..0000000 --- a/ForzaMods_CarTable/ForzaMods_CarTable.csproj +++ /dev/null @@ -1,35 +0,0 @@ - - - - WinExe - net8.0-windows - disable - true - app.manifest - AnyCPU;x64 - - False - sza - Car Table - 1.8.0.1 - 1.8.0.1 - en - true - x64 - - - - - - - - - Resources\Memory.dll - - - - - - - - diff --git a/ForzaMods_CarTable/MainWindow.xaml b/ForzaMods_CarTable/MainWindow.xaml deleted file mode 100644 index 064aa9b..0000000 --- a/ForzaMods_CarTable/MainWindow.xaml +++ /dev/null @@ -1,94 +0,0 @@ - - - -