Skip to content

Commit

Permalink
Implement import and export
Browse files Browse the repository at this point in the history
  • Loading branch information
kidfearless committed Aug 31, 2020
1 parent 72606ab commit 33ddfca
Show file tree
Hide file tree
Showing 2 changed files with 87 additions and 35 deletions.
8 changes: 4 additions & 4 deletions MainWindow.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,11 @@
<Button x:Name="BtnAddCheater" Content="Add Cheater" HorizontalAlignment="Left" Margin="113,58,0,0" VerticalAlignment="Top" Height="66" Width="120" RenderTransformOrigin="1.635,0.554" Click="AddCheaterButtonClicked"/>
<Button x:Name="BtnImport" Content="Import" HorizontalAlignment="Left" Margin="398,58,0,0" VerticalAlignment="Top" RenderTransformOrigin="0.52,1.485" Height="66" Width="120" Click="ImportClicked"/>
<Button x:Name="BtnExport" Content="Export" HorizontalAlignment="Left" Margin="537,58,0,0" VerticalAlignment="Top" Height="66" Width="120" Click="ExportClicked"/>
<TextBox x:Name="TxtSteamID" HorizontalAlignment="Left" Margin="113,10,0,0" Text="STEAM:0:1:12354847" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" GotFocus="SteamID_GotFocus" Height="24" />
<TextBox x:Name="TxtSteamID" HorizontalAlignment="Left" Margin="113,10,0,0" Text="STEAM:0:1:12354847" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" GotFocus="SteamID_GotFocus" LostFocus="SteamID_LostFocus" Height="24" />
<Button x:Name="BtnAutoStatus" Content="Status Key Bind" HorizontalAlignment="Left" Margin="256,58,0,0" VerticalAlignment="Top" Height="66" Width="120" RenderTransformOrigin="1.635,0.554" Click="StatusButtonClicked"/>
<TextBox x:Name="TxtCheats" HorizontalAlignment="Left" Margin="256,10,0,0" Text="Spinbot, Aimbot, Wallhacks" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Height="24" GotFocus="Cheats_GotFocus"/>
<TextBox x:Name="TxtThreatLevel" HorizontalAlignment="Left" Margin="398,10,0,0" Text="1-10" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Height="24" GotFocus="ThreatLevel_GotFocus"/>
<TextBox x:Name="TxtName" HorizontalAlignment="Left" Margin="537,10,0,0" Text="The Suspect" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Height="24" GotFocus="Name_GotFocus"/>
<TextBox x:Name="TxtCheats" HorizontalAlignment="Left" Margin="256,10,0,0" Text="Spinbot, Aimbot, Wallhacks" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Height="24" GotFocus="Cheats_GotFocus" LostFocus="Cheats_LostFocus"/>
<TextBox x:Name="TxtThreatLevel" HorizontalAlignment="Left" Margin="398,10,0,0" Text="1-10" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Height="24" GotFocus="ThreatLevel_GotFocus" LostFocus="ThreatLevel_LostFocus"/>
<TextBox x:Name="TxtName" HorizontalAlignment="Left" Margin="537,10,0,0" Text="The Suspect" TextWrapping="Wrap" VerticalAlignment="Top" Width="120" Height="24" GotFocus="Name_GotFocus" LostFocus="Name_LostFocus"/>
<ScrollViewer Background="Black" x:Name="ScrollPlayers"
HorizontalScrollBarVisibility="Auto" Margin="32,148,32,48">
<StackPanel x:Name="StackPanel" Background="#FF232323" Margin="0,0,0,0">
Expand Down
114 changes: 83 additions & 31 deletions MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public MainWindow()
CommunityURLRegex = new Regex(@"(\d+)");
CommunityProfilePictureRegex = new Regex(string.Format(@"<link rel={0}image_src{0} href={0}(.*){0}>", '"'));

if(!Directory.Exists(Path.GetDirectoryName(Constants.DatabasePath)))
if (!Directory.Exists(Path.GetDirectoryName(Constants.DatabasePath)))
{
Directory.CreateDirectory(Path.GetDirectoryName(Constants.DatabasePath));
}
Expand Down Expand Up @@ -120,8 +120,8 @@ public async void ShowToastAsync(Cheater cheater)
var notificationManager = new NotificationManager();
await notificationManager.ShowAsync(new NotificationContent()
{
Title = $"Hacker {cheater.LastKnownName} Found In Game",
Message = $"Threat Level: {cheater.ThreatLevel}\n" +
Title = $"Hacker {cheater.LastKnownName} Found In Game",
Message = $"Threat Level: {cheater.ThreatLevel}\n" +
$"Known Cheats: {cheater.CheatList}",
Type = NotificationType.Error
});
Expand All @@ -145,7 +145,7 @@ private void Timer_CheckStatus(object sender, System.Timers.ElapsedEventArgs e)
Keyboard.SendKey(KeyConvert.ToDirectXKeyCode(StatusKey), true, Keyboard.InputType.Keyboard);
}
}
catch (Exception _) {}
catch (Exception _) { }
}

/// <summary>
Expand All @@ -157,7 +157,7 @@ private void ReadConsole(object nill)
// Open the file in a way that won't bother csgo.
using var stream = File.Open(Path.Combine(path, "console.log"), FileMode.Open, FileAccess.ReadWrite, FileShare.ReadWrite);
using var reader = new StreamReader(stream, true);
if(reader.BaseStream.Length < 0)
if (reader.BaseStream.Length < 0)
{
return;
}
Expand All @@ -171,7 +171,7 @@ private void ReadConsole(object nill)
{
var mapMatch = MapNameRegex.Match(line);
// The first group match will be the current map on the server
if(mapMatch.Success && mapMatch.Groups[1].Value != CurrentMap)
if (mapMatch.Success && mapMatch.Groups[1].Value != CurrentMap)
{
AlertedPlayers.Clear();
CurrentMap = mapMatch.Groups[1].Value;
Expand Down Expand Up @@ -216,7 +216,7 @@ private void ReadConsole(object nill)
stream.SetLength(0);
stream.Close();

if(tempUsers.Count != Users.Count && tempUsers.Count != 0)
if (tempUsers.Count != Users.Count && tempUsers.Count != 0)
{
Users = tempUsers;
// can only update controls from the main thread, which we are not in. So we invoke an inline function to do it for us.
Expand All @@ -238,20 +238,38 @@ private void ExportClicked(object sender, RoutedEventArgs e)
var dialog = new SaveFileDialog();
dialog.FileName = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments), "exported_cheaters.sq3");
dialog.DefaultExt = ".sq3";
if((bool)dialog.ShowDialog())
dialog.Filter = "sqlite files (*.sq3)|*.sq3|All Files (*.*)|*.*";

if ((bool)dialog.ShowDialog())
{
File.Copy(Constants.DatabasePath, dialog.FileName);
// Try to save the database file
try
{
if(File.Exists(dialog.FileName))
{
File.Delete(dialog.FileName);
}
File.Copy(Constants.DatabasePath, dialog.FileName);
}
// If we fail try to save it under a unique name
catch
{
try
{
File.Copy(Constants.DatabasePath, dialog.FileName + "." + Guid.NewGuid());
}
catch { }
}
}

//dialog.Filter = "sqlite files (*.sq3)|*.sq3|All Files (*.*)|*.*";
}

private void ImportClicked(object sender, RoutedEventArgs e)
{
var dialog = new OpenFileDialog();
dialog.Filter = "sqlite files (*.sq3)|*.sq3|All Files (*.*)|*.*";
dialog.Multiselect = false;
if((bool)dialog.ShowDialog())
if ((bool)dialog.ShowDialog())
{
using var otherDB = new SQLiteConnection(dialog.FileName, Constants.Flags);
var cheaterList = otherDB.Table<Cheater>().ToList();
Expand Down Expand Up @@ -283,25 +301,33 @@ private void StatusButtonClicked(object sender, RoutedEventArgs e)
/// <param name="e"></param>
private void AddCheaterButtonClicked(object sender, RoutedEventArgs e)
{
SteamID steamAccount;
if (TxtSteamID.Text.Contains("community"))
try
{
steamAccount = new SteamID(CommunityURLRegex.Match(TxtSteamID.Text).Groups[1].Value);
SteamID steamAccount;
if (TxtSteamID.Text.Contains("community"))
{
var steam64 = CommunityURLRegex.Match(TxtSteamID.Text).Groups[1].Value;
steamAccount = new SteamID(Convert.ToUInt64(steam64));
}
else
{
steamAccount = new SteamID(TxtSteamID.Text);
}

using var db = new DatabaseConnection();
int.TryParse(TxtThreatLevel.Text.Trim(), out int threat);
db.InsertOrReplace(new Cheater()
{
AccountID = steamAccount.AccountID,
ThreatLevel = threat,
CheatList = TxtCheats.Text,
LastKnownName = TxtName.Text
});
}
else
catch
{
steamAccount = new SteamID(TxtSteamID.Text);
}

using var db = new DatabaseConnection();
int.TryParse(TxtThreatLevel.Text.Trim(), out int threat);
db.Insert(new Cheater()
{
AccountID = steamAccount.AccountID,
ThreatLevel = threat,
CheatList = TxtCheats.Text,
LastKnownName = TxtName.Text
});
}

// reset the default placeholders
TxtCheats.Text = "Spinbot, Aimbot, Wallhacks";
Expand Down Expand Up @@ -344,6 +370,13 @@ private void SteamID_GotFocus(object sender, RoutedEventArgs e)
TxtSteamID.Text = "";
}
}
private void SteamID_LostFocus(object sender, RoutedEventArgs e)
{
if (TxtSteamID.Text == "")
{
TxtSteamID.Text = "STEAM:0:1:12354847";
}
}

private void ThreatLevel_GotFocus(object sender, RoutedEventArgs e)
{
Expand All @@ -352,6 +385,13 @@ private void ThreatLevel_GotFocus(object sender, RoutedEventArgs e)
TxtThreatLevel.Text = "";
}
}
private void ThreatLevel_LostFocus(object sender, RoutedEventArgs e)
{
if (TxtThreatLevel.Text == "")
{
TxtThreatLevel.Text = "1-10";
}
}

private void Name_GotFocus(object sender, RoutedEventArgs e)
{
Expand All @@ -360,6 +400,13 @@ private void Name_GotFocus(object sender, RoutedEventArgs e)
TxtName.Text = "";
}
}
private void Name_LostFocus(object sender, RoutedEventArgs e)
{
if (TxtName.Text == "")
{
TxtName.Text = "The Suspect";
}
}

private void Cheats_GotFocus(object sender, RoutedEventArgs e)
{
Expand All @@ -368,7 +415,13 @@ private void Cheats_GotFocus(object sender, RoutedEventArgs e)
TxtCheats.Text = "";
}
}

private void Cheats_LostFocus(object sender, RoutedEventArgs e)
{
if (TxtCheats.Text == "")
{
TxtCheats.Text = "Spinbot, Aimbot, Wallhacks";
}
}
#endregion

/// <summary>
Expand Down Expand Up @@ -435,7 +488,7 @@ private Grid CreateUserRow(string name, SteamID steamid)
Label lName = new Label()
{
Content = name.Replace("_", "__"),
Margin = new Thickness(0.0, 48/4, 48/4, 5.0)
Margin = new Thickness(0.0, 48 / 4, 48 / 4, 5.0)
};
// single underscores have special meanings and have to be escaped
Label steamID = new Label()
Expand Down Expand Up @@ -540,10 +593,10 @@ private string GetProfilePictureURL(string url)
}

string line;
while((line = readStream.ReadLine()) != null)
while ((line = readStream.ReadLine()) != null)
{
var match = CommunityProfilePictureRegex.Match(line);
if(match.Success)
if (match.Success)
{
response.Close();
readStream.Close();
Expand All @@ -561,7 +614,6 @@ private string GetProfilePictureURL(string url)

private Image GetProfilePicture(SteamID steam)
{

var url = $"http://steamcommunity.com/profiles/{steam.ConvertToUInt64()}";
var profilePicURL = GetProfilePictureURL(url);
var image = CreateImage(profilePicURL);
Expand Down

0 comments on commit 33ddfca

Please sign in to comment.