2017-09-21 18:33:05 +08:00
using CodeWalker.GameFiles ;
using CodeWalker.Properties ;
using System ;
using System.Collections.Generic ;
using System.ComponentModel ;
using System.Data ;
using System.Drawing ;
using System.IO ;
using System.Linq ;
using System.Text ;
using System.Threading.Tasks ;
using System.Windows.Forms ;
namespace CodeWalker
{
public partial class ExtractKeysForm : Form
{
private volatile bool KeysLoaded = false ;
private volatile bool InProgress = false ;
private volatile bool AbortOperation = false ;
public ExtractKeysForm ( )
{
InitializeComponent ( ) ;
}
private void ExtractKeysForm_Load ( object sender , EventArgs e )
{
2018-02-21 17:12:17 +08:00
FolderTextBox . Text = GTAFolder . CurrentGTAFolder ;
2017-09-21 18:33:05 +08:00
try
{
2018-02-24 21:59:00 +08:00
GTA5Keys . LoadFromPath ( GTAFolder . CurrentGTAFolder , Settings . Default . Key ) ;
2017-09-21 18:33:05 +08:00
KeysLoaded = true ;
UpdateStatus ( "Keys loaded. Nothing to do here!" ) ;
}
catch
{
//default label text has this case
//UpdateStatus("Keys not found! Please scan a GTA 5 exe...");
}
}
private void FolderBrowseButton_Click ( object sender , EventArgs e )
{
2018-02-21 17:12:17 +08:00
GTAFolder . UpdateGTAFolder ( false ) ;
FolderTextBox . Text = GTAFolder . CurrentGTAFolder ;
ExeTextBox . Text = GTAFolder . CurrentGTAFolder + @"\GTA5.exe" ;
2017-09-21 18:33:05 +08:00
}
private void ExeBrowseButton_Click ( object sender , EventArgs e )
{
if ( ! string . IsNullOrEmpty ( FolderTextBox . Text ) & & ! string . IsNullOrEmpty ( ExeTextBox . Text ) )
{
OpenFileDialog . InitialDirectory = FolderTextBox . Text ;
OpenFileDialog . FileName = ExeTextBox . Text ;
}
DialogResult res = OpenFileDialog . ShowDialog ( ) ;
if ( res = = DialogResult . OK )
{
ExeTextBox . Text = OpenFileDialog . FileName ;
}
}
private void UpdateStatus ( string text )
{
try
{
if ( InvokeRequired )
{
Invoke ( new Action ( ( ) = > { UpdateStatus ( text ) ; } ) ) ;
}
else
{
StatusLabel . Text = text ;
}
}
catch { }
}
private void BeginButton_Click ( object sender , EventArgs e )
{
if ( InProgress ) return ;
if ( KeysLoaded )
{
if ( MessageBox . Show ( "Keys are already loaded. Do you wish to do the extraction anyway?" , "Keys already loaded" , MessageBoxButtons . OKCancel ) ! = DialogResult . OK )
{
return ;
}
}
InProgress = true ;
AbortOperation = false ;
string exepath = ExeTextBox . Text ;
Task . Run ( ( ) = >
{
try
{
if ( AbortOperation )
{
UpdateStatus ( "Key extraction aborted." ) ;
return ;
}
FileInfo dmpfi = new FileInfo ( exepath ) ;
UpdateStatus ( string . Format ( "Scanning {0} for keys..." , dmpfi . Name ) ) ;
byte [ ] exedat = File . ReadAllBytes ( exepath ) ;
GTA5Keys . GenerateV2 ( exedat , UpdateStatus ) ;
UpdateStatus ( "Saving found keys..." ) ;
2018-02-24 19:52:58 +08:00
Settings . Default . Key = Convert . ToBase64String ( GTA5Keys . PC_AES_KEY ) ;
Settings . Default . Save ( ) ;
2017-09-21 18:33:05 +08:00
//GTA5Keys.SaveToPath();
UpdateStatus ( "Keys extracted successfully." ) ;
KeysLoaded = true ;
InProgress = false ;
}
catch ( Exception ex )
{
UpdateStatus ( "Error - " + ex . ToString ( ) ) ;
InProgress = false ;
}
} ) ;
}
}
}