Jump to content

  •  

  • iBotModz CBox


    Photo

    [C#] Basic Info for Modding Apps.


    • Please log in to reply
    16 replies to this topic

    #1 yungbol

    yungbol

      Firmware Expert

    • Global Mods

    • 1,461 posts
    • Joined: 09-April 08
    • Gender:Male
    • Location:Philly

    Posted 15 March 2009 - 03:52 PM

    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.

    tut1.png

    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.
    tut2.png

    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 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:

    tut3.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;

    tut4.png

    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'.

    tut5.png

    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.
    tut6.png

    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:

    tut7.png

    Edited by yungbol, 15 March 2009 - 03:54 PM.


    #2 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 15 March 2009 - 04:08 PM

    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.

    #3 yungbol

    yungbol

      Firmware Expert

    • Global Mods

    • 1,461 posts
    • Joined: 09-April 08
    • Gender:Male
    • Location:Philly

    Posted 15 March 2009 - 04:12 PM

    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, 15 March 2009 - 04:13 PM.


    #4 Korupt Data

    Korupt Data

      SoOoO KoRuPtAbLe

    • Retired Staff

    • 3,503 posts
    • Joined: 12-May 08
    • Gender:Male
    • Location:That file you downloaded

    Posted 15 March 2009 - 04:41 PM

    Excellent tutorial Yung, i know nothing about coding but id love to give it a go :p

    #5 yungbol

    yungbol

      Firmware Expert

    • Global Mods

    • 1,461 posts
    • Joined: 09-April 08
    • Gender:Male
    • Location:Philly

    Posted 15 March 2009 - 04:44 PM

    Thanks, next time maybe I'll show how to inject images.

    #6 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 15 March 2009 - 04:44 PM

    Does Maximum Box = false, prevent them from changing the size of the window?

    #7 yungbol

    yungbol

      Firmware Expert

    • Global Mods

    • 1,461 posts
    • Joined: 09-April 08
    • Gender:Male
    • Location:Philly

    Posted 15 March 2009 - 04:51 PM

    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.

    #8 Joe Walls

    Joe Walls

      Corporal Grade 2

    • Members+

    • 258 posts
    • Joined: 12-February 09
    • Location:United States (WA)

    Posted 15 March 2009 - 06:16 PM

    Makes we want to use C# but VB is easy and I like easy :) lol

    #9 yungbol

    yungbol

      Firmware Expert

    • Global Mods

    • 1,461 posts
    • Joined: 09-April 08
    • Gender:Male
    • Location:Philly

    Posted 15 March 2009 - 06:21 PM

    Lol, I used to think the same thing. Finally I forced myself to go to C# and am proud of it!

    #10 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 16 March 2009 - 10:28 AM

    I tried some simple programs I made in VB for C#, I don't even know how to make a god damn message box.

    #11 yungbol

    yungbol

      Firmware Expert

    • Global Mods

    • 1,461 posts
    • Joined: 09-April 08
    • Gender:Male
    • Location:Philly

    Posted 16 March 2009 - 10:50 AM

    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);

    #12 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 16 March 2009 - 11:07 AM

    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.

    #13 gabe_k

    gabe_k

      Corporal Grade 2

    • Donors+

    • 360 posts
    • Joined: 02-May 08
    • Gender:Male

    Posted 16 March 2009 - 01:16 PM

    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.

    #14 iBotPeaches

    iBotPeaches

      General Grade 6

    • Owner

    • 6,570 posts
    • Joined: 29-July 07
    • Gender:Male
    • Location:Kansas

    Posted 16 March 2009 - 03:06 PM

    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.

    #15 yungbol

    yungbol

      Firmware Expert

    • Global Mods

    • 1,461 posts
    • Joined: 09-April 08
    • Gender:Male
    • Location:Philly

    Posted 16 March 2009 - 03:24 PM

    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.

    #16 ixGAMEOVERxixx

    ixGAMEOVERxixx

      Private Grade 2

    • VIP

    • 478 posts
    • Joined: 27-October 08
    • Gender:Not Telling
    • Location:Custom Games

    Posted 02 February 2010 - 02:26 AM

    Nice, this really helped! Could you please convert this to VB for me? The converter doesn't like the code

    #17 ATTIKIT

    ATTIKIT

      Private Grade 2

    • Members+

    • 80 posts
    • Joined: 21-February 09
    • Gender:Male

    Posted 02 February 2010 - 07:17 AM

    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