yungbol Posted March 15, 2009 Report Posted March 15, 2009 (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. The first thing I like to do is set up my form properties. What I do is the following settings:Maximize Box = false.Form Border Style = Fixed Single.Change the text of my form. Now we throw a button and label it open along with a textbox. Now, we will learn the basic terminology to open a file.Double click your button to bring up the code.Type the followingOpenFileDialog 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: 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; 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'. 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. 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: Edited March 15, 2009 by yungbol 2
iBotPeaches Posted March 15, 2009 Report Posted March 15, 2009 Yep, classes didn't teach me that. Thanks, I think I'll just messing around with C# again, hopefully this time I can get some things out. Very good tutorial, excellently written.
yungbol Posted March 15, 2009 Author Report Posted March 15, 2009 (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 March 15, 2009 by yungbol
Korupt Data Posted March 15, 2009 Report Posted March 15, 2009 Excellent tutorial Yung, i know nothing about coding but id love to give it a go
yungbol Posted March 15, 2009 Author Report Posted March 15, 2009 Thanks, next time maybe I'll show how to inject images.
iBotPeaches Posted March 15, 2009 Report Posted March 15, 2009 Does Maximum Box = false, prevent them from changing the size of the window?
yungbol Posted March 15, 2009 Author Report Posted March 15, 2009 No, the maximum box to false means they can't click the maximize button in the corner. The form border style to Fixed prevents them from resizing it.
Joe Walls Posted March 16, 2009 Report Posted March 16, 2009 Makes we want to use C# but VB is easy and I like easy lol
yungbol Posted March 16, 2009 Author Report Posted March 16, 2009 Lol, I used to think the same thing. Finally I forced myself to go to C# and am proud of it!
iBotPeaches Posted March 16, 2009 Report Posted March 16, 2009 I tried some simple programs I made in VB for C#, I don't even know how to make a god damn message box.
yungbol Posted March 16, 2009 Author Report Posted March 16, 2009 In vb you can do a messagebox 2 ways.. either: MsgBox("text")orMessageBox.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);
iBotPeaches Posted March 16, 2009 Report Posted March 16, 2009 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.
gabe_k Posted March 16, 2009 Report Posted March 16, 2009 The length for the PNG is right before it in the CON file, so you can just read that and set it as the length to read the image.
iBotPeaches Posted March 16, 2009 Report Posted March 16, 2009 Thanks gabe that made it 100x easier then what I was starting to do. I should have looked into it more. And thanks yungbol for that next tutorial.
yungbol Posted March 16, 2009 Author Report Posted March 16, 2009 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.
ixGAMEOVERxixx Posted February 2, 2010 Report Posted February 2, 2010 Nice, this really helped! Could you please convert this to VB for me? The converter doesn't like the code
ATTIKIT Posted February 2, 2010 Report Posted February 2, 2010 Lol, I used to think the same thing. Finally I forced myself to go to C# and am proud of it! word up C# FTW
Recommended Posts
Please sign in to comment
You will be able to leave a comment after signing in
Sign In Now