Jump to content

cbox


Recommended Posts

Posted (edited)

C#, Ah what a language!

This will teach you how to start a foundation for modding applications. Most tutorials on the internet deal with editing text files, creating useless apps. If your really into modifying save games, this is the tutorial for you.

 

Ok, create a new windows form application in C# 2008 .NET.

 

post-1274-1237151285_thumb.png

 

The first thing I like to do is set up my form properties. What I do is the following settings:

  1. Maximize Box = false.
  2. Form Border Style = Fixed Single.
  3. Change the text of my form.

post-1274-1237152350_thumbpng

 

Now we throw a button and label it open along with a textbox.

 

Now, we will learn the basic terminology to open a file.

  1. Double click your button to bring up the code.
  2. Type the following

OpenFileDialog ofd = new OpenFileDialog();
           ofd.Filter = "All Files|*.*";
           if (ofd.ShowDialog() == DialogResult.OK)
           {
               textBox1.Text = ofd.FileName;
           }
           else { }

 

Explanation of code - The ofd is giving the OpenFileDialog a nickname. We can now refer to it as ofd. The ofd.Filter is the type of files we can select. In this instance we want all files. Now, the if statement is basically saying "if a user selects a file and clicks ok, this will happen. The else statement is telling what happens if they cancel or X out. In this instance nothing special happens. When the OK is selected, the textbox will display the file path of the file selected so now the application knows what file to access.

 

Now your form should look like the following:

 

post-1274-1237152899_thumb.png

 

Go ahead and debug your app (by clicking the play button [circled in blue])

 

Now time for the real code after the file is loaded. So, navigate to the namespace (see below) and add the following code:

 

 using System.IO; 

 

post-1274-1237153061_thumbpng

 

Explanation of code - Adding the System.IO will give you more features into your app for Binary Reading/Writing (hex editing).

 

Ok, now that you have set that up we will create a setup on how to display the image in the CON header into a picturebox. So, add a button and name it Show Image, and add a picturebox onto your form. Change the picturebox's properties to 'Stretch Image'.

 

post-1274-1237153309_thumbpng

 

Now double click on the Show Image button so we can add some code. This is where I may lose you in the tutorial, if you don't understand something, read the explanation below.

 

Add the following code, I will explain it after you add it:

 

FileStream fs = File.OpenRead(textBox1.Text);
           BinaryReader br = new BinaryReader(fs);
           br.BaseStream.Position = 0x171A;
           Stream image = new MemoryStream(br.ReadBytes(16000));
           pictureBox1.Image = Image.FromStream(image);
           fs.Close();
           br.Close();

 

Explanation of code:

  • The fs is creating a filestream or 'file browser'. What it does is will "open and read" the hex data of the file we selected.
  • The textBox1.Text is the file location.
  • BinaryReader is what reads the hex data we want.
  • The BaseStream.Position is where we want to set the 'cursor' at so we can begin our read.
  • The Memory Stream is reading 16000 (enough) bytes (which is the image's hex) and sending it to memory so we can later use it.

  • Then the picturebox is showing the stream of the image so we can show it.
  • The Close(); is just closing all our Streams and Readers so we don't get an error later that the file is in use with another process.

post-1274-1237153878_thumbpng

 

Now, go debug you app and test it out. Open a file then show image. It will show the game's image. This is just a small step and soon when I get more time I will create on how to find and edit data in a save. Good luck and happy coding.

 

Result:

 

post-1274-1237154061_thumbpng

Edited by yungbol
  • Like 2
Posted (edited)
I did the same thing Peaches, when I started coding like 2 months ago, I was wandering between VB and C#. So many people told me C# will be better once you learn it and you can get help from a lot of the 'top coders'... So I went with c# at first I was confused, I kept trying getting help studying sources and it paid off. I am still not great at coding, but with a hex app, I can do a lot. Edited by yungbol
Posted

In vb you can do a messagebox 2 ways.. either:

 

MsgBox("text")

or

MessageBox.Show("text")

 

In c# it is the same as the 2nd way in VB,

 

MessageBox.Show("Your text here", "Your title here", MessageBoxButtons.OK, MessageBoxIcon.Asterisk);

Posted

After I posted that I found out. Thanks.

 

I was trying MsgBox the whole time, I guess I forgot the other one. I copied your program exactly (so not posting anything) but I'm getting more comfortable with it.

 

I'm making a screenshot extractor and injector as my next project. Except widescreen and fullscreen xboxes generate different screenshots at different places, so I'm working on that.

Posted

No prob, listen to gabe, he is the one that helped me :)...

 

If anyone needs any help on accomplishing a task just make a topic and post it rather then PM it. I've been getting quite a few PM's for help, but if you post it and I solve it, it will benefit more people.

  • 10 months later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...