mirror of
https://mirror.ghproxy.com/https://github.com/dexyfex/CodeWalker
synced 2024-11-23 07:22:52 +08:00
146 lines
4.1 KiB
C#
146 lines
4.1 KiB
C#
|
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)
|
|||
|
{
|
|||
|
FolderTextBox.Text = Settings.Default.GTAFolder;
|
|||
|
|
|||
|
try
|
|||
|
{
|
|||
|
GTA5Keys.LoadFromPath(Settings.Default.GTAFolder);
|
|||
|
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 FolderTextBox_TextChanged(object sender, EventArgs e)
|
|||
|
{
|
|||
|
Settings.Default.GTAFolder = FolderTextBox.Text;
|
|||
|
ExeTextBox.Text = FolderTextBox.Text + "\\" + "GTA5.exe";
|
|||
|
}
|
|||
|
|
|||
|
private void FolderBrowseButton_Click(object sender, EventArgs e)
|
|||
|
{
|
|||
|
FolderBrowserDialog.SelectedPath = Settings.Default.GTAFolder;
|
|||
|
DialogResult res = FolderBrowserDialog.ShowDialog();
|
|||
|
if (res == DialogResult.OK)
|
|||
|
{
|
|||
|
FolderTextBox.Text = FolderBrowserDialog.SelectedPath;
|
|||
|
}
|
|||
|
}
|
|||
|
|
|||
|
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...");
|
|||
|
|
|||
|
//GTA5Keys.SaveToPath();
|
|||
|
|
|||
|
UpdateStatus("Keys extracted successfully.");
|
|||
|
KeysLoaded = true;
|
|||
|
InProgress = false;
|
|||
|
}
|
|||
|
catch (Exception ex)
|
|||
|
{
|
|||
|
UpdateStatus("Error - " + ex.ToString());
|
|||
|
|
|||
|
InProgress = false;
|
|||
|
}
|
|||
|
});
|
|||
|
}
|
|||
|
}
|
|||
|
}
|