diff --git a/GTAOnlineCasinoHelper/App.xaml b/GTAOnlineCasinoHelper/App.xaml index 6eac5f5..f62b993 100644 --- a/GTAOnlineCasinoHelper/App.xaml +++ b/GTAOnlineCasinoHelper/App.xaml @@ -2,6 +2,7 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="clr-namespace:GTAOnlineCasinoHelper" + xmlns:system="clr-namespace:System;assembly=mscorlib" StartupUri="MainWindow.xaml"> diff --git a/GTAOnlineCasinoHelper/Assets/GTA5.ico b/GTAOnlineCasinoHelper/Assets/GTA5.ico new file mode 100644 index 0000000..7dccb71 Binary files /dev/null and b/GTAOnlineCasinoHelper/Assets/GTA5.ico differ diff --git a/GTAOnlineCasinoHelper/Assets/GTA5.png b/GTAOnlineCasinoHelper/Assets/GTA5.png new file mode 100644 index 0000000..fa36d49 Binary files /dev/null and b/GTAOnlineCasinoHelper/Assets/GTA5.png differ diff --git a/GTAOnlineCasinoHelper/Extensions/ImageExtension.cs b/GTAOnlineCasinoHelper/Extensions/ImageExtension.cs new file mode 100644 index 0000000..7f15644 --- /dev/null +++ b/GTAOnlineCasinoHelper/Extensions/ImageExtension.cs @@ -0,0 +1,39 @@ +using System; +using System.Collections.Generic; +using System.Drawing; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Media.Imaging; + +namespace GTAOnlineCasinoHelper.Extensions +{ + public static class ImageExtension + { + + [DllImport("gdi32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + internal static extern bool DeleteObject(IntPtr value); + + public static BitmapSource GetBitmapSource(this Image image) + { + Bitmap bitmap = new Bitmap(image); + IntPtr bmpPt = bitmap.GetHbitmap(); + BitmapSource bitmapSource = + System.Windows.Interop.Imaging.CreateBitmapSourceFromHBitmap( + bmpPt, + IntPtr.Zero, + Int32Rect.Empty, + BitmapSizeOptions.FromEmptyOptions()); + + //freeze bitmapSource and clear memory to avoid memory leaks + bitmapSource.Freeze(); + DeleteObject(bmpPt); + + return bitmapSource; + } + + } +} diff --git a/GTAOnlineCasinoHelper/GTAOnlineCasinoHelper.csproj b/GTAOnlineCasinoHelper/GTAOnlineCasinoHelper.csproj index 5463fb7..ebe88a2 100644 --- a/GTAOnlineCasinoHelper/GTAOnlineCasinoHelper.csproj +++ b/GTAOnlineCasinoHelper/GTAOnlineCasinoHelper.csproj @@ -37,6 +37,9 @@ prompt 4 + + Assets\GTA5.ico + ..\packages\ControlzEx.4.0.1\lib\net45\ControlzEx.dll @@ -60,6 +63,7 @@ + @@ -78,11 +82,12 @@ MSBuild:Compile Designer + ThemeView.xaml - - TestTwo.xaml + + AutoLobby.xaml LuckyWheel.xaml @@ -105,7 +110,7 @@ MSBuild:UpdateDesignTimeXaml - + MSBuild:UpdateDesignTimeXaml Designer @@ -144,6 +149,12 @@ + + + + + + diff --git a/GTAOnlineCasinoHelper/MainWindow.xaml b/GTAOnlineCasinoHelper/MainWindow.xaml index a16bddc..6a5e291 100644 --- a/GTAOnlineCasinoHelper/MainWindow.xaml +++ b/GTAOnlineCasinoHelper/MainWindow.xaml @@ -37,6 +37,13 @@ + + + + + \ No newline at end of file diff --git a/GTAOnlineCasinoHelper/Views/AutoLobby.xaml.cs b/GTAOnlineCasinoHelper/Views/AutoLobby.xaml.cs new file mode 100644 index 0000000..fdf77b9 --- /dev/null +++ b/GTAOnlineCasinoHelper/Views/AutoLobby.xaml.cs @@ -0,0 +1,249 @@ +using MahApps.Metro.Controls; +using MahApps.Metro.Controls.Dialogs; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Runtime.InteropServices; +using System.Text; +using System.Threading; +using System.Threading.Tasks; +using System.Windows; +using System.Windows.Controls; + +namespace GTAOnlineCasinoHelper.Views +{ + + public partial class AutoLobby : UserControl + { + + [Flags] + public enum ThreadAccess : int + { + TERMINATE = (0x0001), + SUSPEND_RESUME = (0x0002), + GET_CONTEXT = (0x0008), + SET_CONTEXT = (0x0010), + SET_INFORMATION = (0x0020), + QUERY_INFORMATION = (0x0040), + SET_THREAD_TOKEN = (0x0080), + IMPERSONATE = (0x0100), + DIRECT_IMPERSONATION = (0x0200) + } + + [DllImport("kernel32.dll")] + static extern IntPtr OpenThread(ThreadAccess dwDesiredAccess, bool bInheritHandle, uint dwThreadId); + [DllImport("kernel32.dll")] + static extern uint SuspendThread(IntPtr hThread); + [DllImport("kernel32.dll")] + static extern int ResumeThread(IntPtr hThread); + [DllImport("kernel32", CharSet = CharSet.Auto, SetLastError = true)] + static extern bool CloseHandle(IntPtr handle); + + private const int SECONDS = 8; + private const int TIMER_INTERVAL = 50; + private const string PROCESS_NAME = "GTA5"; + + private int Seconds + { + get + { + if (CheckBox_OverrideTimeout.IsChecked.HasValue && CheckBox_OverrideTimeout.IsChecked.Value && int.TryParse(TextBox_TimeoutSeconds.Text, out int seconds)) + { + return seconds; + } + else + { + return SECONDS; + } + } + } + private string ProcessName + { + get + { + return (CheckBox_OverrideProcessName.IsChecked.HasValue && CheckBox_OverrideProcessName.IsChecked.Value) ? TextBox_ProcessName.Text : PROCESS_NAME; + } + } + private bool IsSuspended + { + get + { + return suspendedProcesses != null && suspendedProcesses.Length > 0; + } + } + private Process[] suspendedProcesses = new Process[0]; + private Timer timer; + private DateTimeOffset timestamp = DateTimeOffset.MinValue; + + public AutoLobby() + { + this.InitializeComponent(); + this.TextBox_ProcessName.Text = PROCESS_NAME; + this.TextBox_TimeoutSeconds.Text = SECONDS.ToString(); + this.timer = new Timer(Timer_Tick, this, Timeout.Infinite, TIMER_INTERVAL); + } + + private double GetMilliseconds() + { + return DateTime.Now.ToUniversalTime().Subtract( + new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc) + ).TotalMilliseconds; + } + + private void Timer_Tick(object state) + { + Dispatcher.Invoke(() => + { + if (!IsSuspended) + { + TextBlock_Status.Text = ""; + this.timer.Change(Timeout.Infinite, 50); + } + TimeSpan timeSpan = timestamp - DateTimeOffset.Now; + if (timeSpan.TotalMilliseconds < 0) + { + ResumeGTA(); + TextBlock_Status.Text = ""; + return; + } + TextBlock_Status.Text = $"{timeSpan.TotalSeconds.ToString("F3")}s"; + }); + } + + private void CheckBox_OverrideProcessName_Checked(object sender, RoutedEventArgs e) + { + TextBox_ProcessName.Visibility = Visibility.Visible; + } + + private void CheckBox_OverrideProcessName_Unchecked(object sender, RoutedEventArgs e) + { + TextBox_ProcessName.Visibility = Visibility.Collapsed; + } + + private void CheckBox_OverrideTimeout_Checked(object sender, RoutedEventArgs e) + { + TextBox_TimeoutSeconds.Visibility = Visibility.Visible; + } + + private void CheckBox_OverrideTimeout_Unchecked(object sender, RoutedEventArgs e) + { + TextBox_TimeoutSeconds.Visibility = Visibility.Collapsed; + } + + private async void Button_AutoLobby_Click(object sender, RoutedEventArgs e) + { + if (IsSuspended) + { + await MainWindow.Instance.ShowMessageAsync("GTA V is already suspended", $"GTA V ({ProcessName}.exe) is already suspended"); + return; + } + if (!SuspendGTA()) + { + await MainWindow.Instance.ShowMessageAsync("GTA V is not running", $"GTA V ({ProcessName}.exe) is not running"); + return; + } + timestamp = DateTimeOffset.Now + new TimeSpan(0, 0, Seconds); + TextBlock_Status.Text = $"{Seconds}.000s"; + timer.Change(TIMER_INTERVAL, TIMER_INTERVAL); + } + + private async void Button_Suspend_Click(object sender, RoutedEventArgs e) + { + if (IsSuspended) + { + await MainWindow.Instance.ShowMessageAsync("GTA V is already suspended", $"GTA V ({ProcessName}.exe) is already suspended"); + return; + } + SuspendGTA(); + TextBlock_Status.Text = "Suspended"; + } + + private async void Button_Resume_Click(object sender, RoutedEventArgs e) + { + if (!IsSuspended) + { + await MainWindow.Instance.ShowMessageAsync("GTA V is not suspended", $"GTA V ({ProcessName}.exe) is not suspended"); + return; + } + ResumeGTA(); + TextBlock_Status.Text = ""; + } + + private static void SuspendProcess(int pid) + { + var process = Process.GetProcessById(pid); + + if (process.ProcessName == string.Empty) + return; + + foreach (ProcessThread pT in process.Threads) + { + IntPtr pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id); + + if (pOpenThread == IntPtr.Zero) + { + continue; + } + + SuspendThread(pOpenThread); + + CloseHandle(pOpenThread); + } + } + + public static void ResumeProcess(int pid) + { + var process = Process.GetProcessById(pid); + + if (process.ProcessName == string.Empty) + return; + + foreach (ProcessThread pT in process.Threads) + { + IntPtr pOpenThread = OpenThread(ThreadAccess.SUSPEND_RESUME, false, (uint)pT.Id); + + if (pOpenThread == IntPtr.Zero) + { + continue; + } + + var suspendCount = 0; + do + { + suspendCount = ResumeThread(pOpenThread); + } while (suspendCount > 0); + + CloseHandle(pOpenThread); + } + } + + private bool SuspendGTA() + { + suspendedProcesses = Process.GetProcessesByName(ProcessName); + if (suspendedProcesses.Length < 1) + { + return false; + } + foreach (Process process in suspendedProcesses) + { + SuspendProcess(process.Id); + } + //labelState.Text = "Suspended"; + return true; + } + + private void ResumeGTA() + { + timer.Change(Timeout.Infinite, TIMER_INTERVAL); + foreach (var process in suspendedProcesses) + { + ResumeProcess(process.Id); + } + suspendedProcesses = new Process[0]; + TextBlock_Status.Text = ""; + } + + } + +} \ No newline at end of file diff --git a/GTAOnlineCasinoHelper/Views/LuckyWheel.xaml b/GTAOnlineCasinoHelper/Views/LuckyWheel.xaml index d88cd88..3e647b4 100644 --- a/GTAOnlineCasinoHelper/Views/LuckyWheel.xaml +++ b/GTAOnlineCasinoHelper/Views/LuckyWheel.xaml @@ -9,7 +9,7 @@ xmlns:GTAOnlineCasinoHelper="clr-namespace:GTAOnlineCasinoHelper"> - 0 5 0 0 + 5 @@ -20,46 +20,40 @@ - -