Login Register






Censure worm 1.0 C# source code filter_list
Author
Message
Censure worm 1.0 C# source code #1
I gotta release some useful stuff for community since i feel like a bad leecher v.v + something which some of you already know . :x

This was my first project in C#, so it could be a little messy. This program is useful for Counter Strike 1.6 players.
Purpose: It blocks the malicious files that are automatically downloaded in your setting files of CS 1.6, and it pretty much ruins your game with those setting. Some people know how to fix the settings back manually but, only few. And thats why i wanted to create this, to help newbies so they can play safely.

Why should it be useful, i don't even play counter strike!? Well if you are C# newbie you can see clear example of how to use Timer, file management, sounds, getting a process and killing it & basic usage of buttons and labels and class variables as global variables..

[Image: RAIV0pu.png]
CODE
Code:
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Windows.Forms; using System.IO; using System.Threading; using System.Diagnostics; // for killing process using System.Media; // For sounds namespace Cworm { public partial class Form1 : Form { public Form1() { InitializeComponent(); } private void toolTip1_Popup(object sender, PopupEventArgs e) { } class data { public static string cstrike = "none"; public static string config = "none"; public static string slot1 = "none declared"; public static string slot2 = "none declared"; public static string shadowcfg = "none declared"; public static string csexe = "none declared"; } private void activate_b_Click(object sender, EventArgs e) { string cstrike = pathbox.Text; string backup_folder = pathbox.Text + @"\backup"; bool CstrikeIsExists = Directory.Exists(pathbox.Text); // i love HC! bool ConfigIsExists = File.Exists(cstrike + @"\config.cfg"); if (CstrikeIsExists == true && ConfigIsExists == true) string cfg = cstrike + @"\config.cfg"; data.config = cstrike + @"\config.cfg"; // config <global> data.cstrike = cstrike; // cstrike <global> data.csexe = cstrike.Replace("cstrike", "Counter-Strike"); // Pokrece backup funkciju var t4 = new System.Windows.Forms.Timer { Enabled = true, Interval = 4000 }; t4.Tick += (o, a) => { t4.Stop(); status.ForeColor = System.Drawing.Color.GreenYellow; status.Text = "Please wait..."; backup(cfg, cstrike); t4.Enabled = false; }; } else { status.Text = "Invalid path"; } } private void backup(string config,string cstrike) { bool backupIsExists = File.Exists(cstrike + @"\backup"); string backup_folder = cstrike + @"\backup"; status.Text = " If block following"; if (backupIsExists == true) { File.Copy(config, backup_folder + @"\config.cfg", true); status.Text = "Cfg backuped"+ config +" to "+ backup_folder; data.shadowcfg = backup_folder + @"\config.cfg"; } else { try { Directory.CreateDirectory(backup_folder); } catch(System.IO.IOException) { status.Text = "Run the program as administrator"; } File.Copy(config, backup_folder + @"\config.cfg", true); status.Text = "Cfg backuped"; status.ForeColor = System.Drawing.Color.GreenYellow; data.shadowcfg = backup_folder + @"\config.cfg"; } activate_b.Enabled = false; stop_b.Enabled = true; pathbox.Enabled = false; button1.Enabled = false; shield(config,cstrike,backup_folder); } private void shield(string config,string cstrike,string backup_folder) { string censure = cstrike + @"\censuree.cfg"; string shadowcfg = backup_folder + @"\config.cfg"; status.Text = "Activated"; status.ForeColor = System.Drawing.Color.GreenYellow; fileSystemWatcher1.Path = cstrike; fileSystemWatcher1.EnableRaisingEvents = true; Resource1.ResourceManager.GetStream("nudgeSound", Resource1.Culture); System.IO.Stream s = Resource1.ResourceManager.GetStream("activated", Resource1.Culture); SoundPlayer player = new SoundPlayer(s); player.Play(); } private void stop_b_Click(object sender, EventArgs e) { stop_b.Enabled = false; activate_b.Enabled = true; fileSystemWatcher1.EnableRaisingEvents = false; status.Text = "Off"; status.ForeColor = System.Drawing.Color.Red; Resource1.ResourceManager.GetStream("disabled", Resource1.Culture); System.IO.Stream s = Resource1.ResourceManager.GetStream("disabled", Resource1.Culture); SoundPlayer player = new SoundPlayer(s); player.Play(); } private void pathbox_TextChanged(object sender, EventArgs e) { } private void button1_Click(object sender, EventArgs e) { try { if (folderBrowserDialog1.ShowDialog() == DialogResult.OK) { pathbox.Text = folderBrowserDialog1.SelectedPath; } } catch (Exception ex) { MessageBox.Show("Exception occured. Make sure you run program as administrator or cstrike folder isn't valid"); } } private void fcreated(object sender, FileSystemEventArgs e) { if (e.Name == "censuree.cfg" || e.Name == "censure.cfg" || e.Name == data.slot1 || e.Name == data.slot2) { File.Delete(data.cstrike + @"\" + e.Name); File.Copy(data.shadowcfg, data.config, true); if (notify.Checked == true) { Resource1.ResourceManager.GetStream("alarm", Resource1.Culture); System.IO.Stream s = Resource1.ResourceManager.GetStream("alarm", Resource1.Culture); SoundPlayer player = new SoundPlayer(s); player.Play(); ; } if (restart.Checked == true) try { foreach (Process proc in Process.GetProcessesByName("hl")) { proc.Kill(); var tstart = new System.Windows.Forms.Timer { Enabled = true, Interval = 4000 }; tstart.Tick += (o, a) => { tstart.Stop(); var msg = MessageBox.Show("Censure is removed, you can continue playing now."); ; }; } } catch (Exception ex) { MessageBox.Show(ex.Message +": "+data.csexe); } } else { status.Text = "Activated"; } } private void Form1_Load(object sender, EventArgs e) { if (Properties.Settings.Default.lastpath != "none") pathbox.Text = Properties.Settings.Default.lastpath; } private void linkLabel1_LinkClicked(object sender, LinkLabelLinkClickedEventArgs e) { MessageBox.Show("Coded by Ante Gulin (Guxi). Contact me on facebook: facebook.com/theguxi. Contact me via emails: theguxi@hotmail.com & theguxi@gmail.com. Skype: ante_gulin."); } } }

If you wish to download it or read more about the program click here!

Reply

RE: Censure worm 1.0 C# source code #2
@Guxi
I relocated your thread to the Visual Basic and .NET Framework Family section based on C# (C Sharp) being a syntax only related C Like Language as C Sharp bears a closer resemblance to Microsoft's Net Framework, etceteral.
And if I didn't move it, @ArkPhaze would be in here first thing to point all of this out.
How would I know that?
Because he went through a very similar subject just yesterday.:lol:

Reply

RE: Censure worm 1.0 C# source code #3
@Guxi
I relocated your thread to the Visual Basic and .NET Framework Family section based on C# (C Sharp) being a syntax only related C Like Language as C Sharp bears a closer resemblance to Microsoft's Net Framework, etceteral.
And if I didn't move it, @ArkPhaze would be in here first thing to point all of this out.
How would I know that?
Because he went through a very similar subject just yesterday.:lol:

Reply

RE: Censure worm 1.0 C# source code #4
(04-30-2013, 09:52 PM)Linuxephus Wrote: @Guxi
I relocated your thread to the Visual Basic and .NET Framework Family section based on C# (C Sharp) being a syntax only related C Like Language as C Sharp bears a closer resemblance to Microsoft's Net Framework, etceteral.
And if I didn't move it, @ArkPhaze would be in here first thing to point all of this out.
How would I know that?
Because he went through a very similar subject just yesterday.:lol:

Thanks for forestalling him! Biggrin

Reply

RE: Censure worm 1.0 C# source code #5
(04-30-2013, 10:00 PM)Guxi Wrote: Thanks for forestalling him! Biggrin

No problem mate.
I read he's all the rage in the Coding Department.Cool
Not to mention, it's already a foregone conclusion that at some point he'll be in here to explain to you directly the differences betwixt C Sharp and the other C Based Languages.
Oh...and he will!:lol:Wink

Reply

RE: Censure worm 1.0 C# source code #6
(04-30-2013, 10:13 PM)Linuxephus Wrote:
(04-30-2013, 10:00 PM)Guxi Wrote: Thanks for forestalling him! Biggrin

No problem mate.
I read he's all the rage in the Coding Department.Cool
Not to mention, it's already a foregone conclusion that at some point he'll be in here to explain to you directly the differences betwixt C Sharp and the other C Based Languages.
Oh...and he will!:lol:Wink

Oh, sh*t!


Is he a vampire?
Arkhize here's something you don't know about C# & other C based languages. ( spoiler)
Spoiler:

[Image: deco_nightstalker_cross.jpg]

Reply

RE: Censure worm 1.0 C# source code #7
Alright, firstly, the reason why C# is not related to C or C++ is, I'm putting this in spoilers because it's quite a bit of reading:

Spoiler:
*Just kidding. Wink



Good share though Smile

For your own benefit I have a few things for you:
Code:
private void toolTip1_Popup(object sender, PopupEventArgs e) { }

Empty methods are not a good thing, I'm assuming in your designer you are assigning an event handler to this method. Although it's never being used here.

Code:
if (CstrikeIsExists == true && ConfigIsExists == true)

You don't need to evaluate against true here, there would be no need for == true or != false. Try this:
Code:
if (CstrikeIsExists && ConfigIsExists)

Because this is much better. What you are doing above is checking a condition, which already represents true or false, and comparing it with true:
Exs:
  • 1) true == true
    -> This gets evaluated down to a single true, because true does equal true.
    -> true

    1) false == true
    -> This gets evaluated down to a single false, because false does not equal true.
    -> false

Lets take a look at this assuming, CstrikeIsExists = true, and ConfigIsExists = false.

Code:
if (CstrikeIsExists == true && ConfigIsExists == true)
Code:
if (true == true && false == true)
Code:
if (true && false)

(Note: obviously that is false overall).

Why go through an extra evaluation though? Smile

If you did:
Code:
if (CstrikeIsExists && ConfigIsExists)

Assuming that each of these still represents, respectively, true and false (in that order). This would be the exact same thing, but evaluated with one less step:
Code:
if (true && false)

Also, you are creating a new instance of a timer everytime. Why do that? You could stick with one timer declared as a member variable to the Form1 class, and initialize it's tick event to a method from the form's constructor, and then you would only be using one timer, instead of having multiple other instances of the Timer out on the heap, which have been used once, but get left alone and become useless. The GC has to clean all of that up at some point, so save it the work? If you have timers that need to do different things then you either should be disposing of these instances properly, or making a couple of them as global instances.

SoundPlayer implements the IDisposable interface as well, so you should be disposing of that object.

You also seem to be overusing the try, catch here as a method of error "handling". You should avoid this as much as possible, or do something with the error other than just swallowing it.

Your data class as well, should not be inside the Form1 class technically. There's almost never a good reason to have subclasses in my opinion. Especially if you want to access this from someplace else, it shouldn't be in there.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Censure worm 1.0 C# source code #8
Alright, firstly, the reason why C# is not related to C or C++ is, I'm putting this in spoilers because it's quite a bit of reading:

Spoiler:
*Just kidding. Wink



Good share though Smile

For your own benefit I have a few things for you:
Code:
private void toolTip1_Popup(object sender, PopupEventArgs e) { }

Empty methods are not a good thing, I'm assuming in your designer you are assigning an event handler to this method. Although it's never being used here.

Code:
if (CstrikeIsExists == true && ConfigIsExists == true)

You don't need to evaluate against true here, there would be no need for == true or != false. Try this:
Code:
if (CstrikeIsExists && ConfigIsExists)

Because this is much better. What you are doing above is checking a condition, which already represents true or false, and comparing it with true:
Exs:
  • 1) true == true
    -> This gets evaluated down to a single true, because true does equal true.
    -> true

    1) false == true
    -> This gets evaluated down to a single false, because false does not equal true.
    -> false

Lets take a look at this assuming, CstrikeIsExists = true, and ConfigIsExists = false.

Code:
if (CstrikeIsExists == true && ConfigIsExists == true)
Code:
if (true == true && false == true)
Code:
if (true && false)

(Note: obviously that is false overall).

Why go through an extra evaluation though? Smile

If you did:
Code:
if (CstrikeIsExists && ConfigIsExists)

Assuming that each of these still represents, respectively, true and false (in that order). This would be the exact same thing, but evaluated with one less step:
Code:
if (true && false)

Also, you are creating a new instance of a timer everytime. Why do that? You could stick with one timer declared as a member variable to the Form1 class, and initialize it's tick event to a method from the form's constructor, and then you would only be using one timer, instead of having multiple other instances of the Timer out on the heap, which have been used once, but get left alone and become useless. The GC has to clean all of that up at some point, so save it the work? If you have timers that need to do different things then you either should be disposing of these instances properly, or making a couple of them as global instances.

SoundPlayer implements the IDisposable interface as well, so you should be disposing of that object.

You also seem to be overusing the try, catch here as a method of error "handling". You should avoid this as much as possible, or do something with the error other than just swallowing it.

Your data class as well, should not be inside the Form1 class technically. There's almost never a good reason to have subclasses in my opinion. Especially if you want to access this from someplace else, it shouldn't be in there.
ArkPhaze
"Object oriented way to get rich? Inheritance"
Getting Started: C/C++ | Common Mistakes
[ Assembly / C++ / .NET / Haskell / J Programmer ]

Reply

RE: Censure worm 1.0 C# source code #9
(05-01-2013, 05:36 AM)ArkPhaze Wrote: Alright, firstly, the reason why C# is not related to C or C++ is, I'm putting this in spoilers because it's quite a bit of reading:

Spoiler:
*Just kidding. Wink



Good share though Smile

For your own benefit I have a few things for you:
Code:
private void toolTip1_Popup(object sender, PopupEventArgs e) { }

Empty methods are not a good thing, I'm assuming in your designer you are assigning an event handler to this method. Although it's never being used here.

Code:
if (CstrikeIsExists == true && ConfigIsExists == true)

You don't need to evaluate against true here, there would be no need for == true or != false. Try this:
Code:
if (CstrikeIsExists && ConfigIsExists)

Because this is much better. What you are doing above is checking a condition, which already represents true or false, and comparing it with true:
Exs:
  • 1) true == true
    -> This gets evaluated down to a single true, because true does equal true.
    -> true

    1) false == true
    -> This gets evaluated down to a single false, because false does not equal true.
    -> false

Lets take a look at this assuming, CstrikeIsExists = true, and ConfigIsExists = false.

Code:
if (CstrikeIsExists == true && ConfigIsExists == true)
Code:
if (true == true && false == true)
Code:
if (true && false)

(Note: obviously that is false overall).

Why go through an extra evaluation though? Smile

If you did:
Code:
if (CstrikeIsExists && ConfigIsExists)

Assuming that each of these still represents, respectively, true and false (in that order). This would be the exact same thing, but evaluated with one less step:
Code:
if (true && false)

Also, you are creating a new instance of a timer everytime. Why do that? You could stick with one timer declared as a member variable to the Form1 class, and initialize it's tick event to a method from the form's constructor, and then you would only be using one timer, instead of having multiple other instances of the Timer out on the heap, which have been used once, but get left alone and become useless. The GC has to clean all of that up at some point, so save it the work? If you have timers that need to do different things then you either should be disposing of these instances properly, or making a couple of them as global instances.

SoundPlayer implements the IDisposable interface as well, so you should be disposing of that object.

You also seem to be overusing the try, catch here as a method of error "handling". You should avoid this as much as possible, or do something with the error other than just swallowing it.

Your data class as well, should not be inside the Form1 class technically. There's almost never a good reason to have subclasses in my opinion. Especially if you want to access this from someplace else, it shouldn't be in there.

Thank you ArkPhaze, i'm glad that someone experienced went through my code and commented it. It was very helpful Confusedmiling: +

Reply