• Just a reminder that providing specifics on, sharing links to, or naming websites where ROMs can be accessed is against the rules. If your post has any of this information it will be removed.
  • Ever thought it'd be cool to have your art, writing, or challenge runs featured on PokéCommunity? Click here for info - we'd love to spotlight your work!
  • Our weekly protagonist poll is now up! Vote for your favorite Trading Card Game 2 protagonist in the poll by clicking here.
  • Welcome to PokéCommunity! Register now and join one of the best fan communities on the 'net to talk Pokémon and more! We are not affiliated with The Pokémon Company or Nintendo.

Making a C# Tool - Step by Step!

xGal

Mhm
  • 241
    Posts
    13
    Years
    Nice, I see someone got inspired from my tutorial ^^ (I think, at least).

    Thank you for making this tutorial you tought me things I still don't know on C#.

    This will sure help me finish my program :D.
     
    How do you make your program as a standalone program?
     
    It basically already is. In your project's folder, there should be another folder called "bin". And in there, depending on whether you've set it as a debug or release build, one of the two folders there will contain your executable file.

    And then you can cut the .EXE file and transfer it in other PCs even if there is no C# installed?
     
    As long as the target computer has the latest (4.5) .NET framework installed, it should run.

    This is the answer I've been looking for! I will try it with another laptop and install .Net framework 4.5 then see if it works.

    For clarification purposes, should I copy the .EXE file only or the whole folder?
     
    As long as the target computer has the latest (4.5) .NET framework installed, it should run.
    In Visual Studio 2013 (I have Ultimate) you can change what version you use so I recommend using 2.0 so it works on older operating systems.

    Also you should mention somewhere for people to avoid using functions like cint, clang, and so on because they crash programs on Mono. (Your example doesn't seem to use them but it's a good thing to keep in mind.)
     
    Afaik you do not have LINQ(Language integrated query) compatability from .net 2 downwards, so I would suggest compiling with .net 3.5, which at least gives you XP support.

    Also, and yeah I know this is just a basic tutorial, I would like to suggest a few things:

    • Use configuration / "ini" files to maintain the locations, otherwise people with different roms might complain
    • Use an encapsulated external class to implement rom functionality, even basic things like reading/writing and probably the rom header, so you do not have to deal with static offsets inside your main code.
    • Label your variables, do not use alphanumerics but actually use names, it will help others understand your basic concept of coding and you will later find your variables again...^^

    It's those things that are very important imo for starters to learn, just because it is somehow hard to change your coding style later on.

    ~SBird
     
    Spoiler:

    Wow, nice tutorial (especially for the lenght {:3}). C# is a good language to start with (I started with VB6, but now it's outdated...).

    • Use configuration / "ini" files to maintain the locations, otherwise people with different roms might complain
    For using INI with C# you need an external library :) . They are good if your program is rather small...
     
    @Gamer2020 You can target previous .NET frameworks in 2010 as well, however, doesn't compatibility with the latest features also break if you use older frameworks?

    I haven't had any problems. Depends on features I guess. Earlier frameworks would just be missing some features I suppose.

    Someone told me that 2.0 is best for XP compatibility but honestly I think some higher versions work as well. Also the frameworks are backwards compatible so if 4.5 is installed you can run 2.0. Microsoft has been making their newer software not install on XP.

    I did some quick research and I think 4.0 works on XP so that should be OK to use.

    I can confirm that 4.5 and 4.0 work on linux as long as you avoid the functions I mentioned in my previous post.
     
    Last edited:
    Yeah, I had to find an INI class, although it's a tad buggy. It's easy to fix though. I might see if I can tend to the bugs in the class I have and try getting it working 100%.

    Well, that'll definitely be something worth keeping in mind for my future development. I could just as easily get VS2013 Ultimate for free (Software from Dreamspark through my school), but 2010 still supports XNA development and deployment to the Xbox 360.

    That is a good point. I also have dreamspark so I usually just get the latest software. I have 2010, 2012, and 2013 all installed alongside each other and they all work fine.

    As for your INI problem you may be able to convert the code from PGE. The code is tested on Linux and Windows and I've had no problems.

    https://github.com/Gamer2020/PokemonGameEditor/blob/master/GBAPokemonGameEditor/INI.vb
     
    OK I know this thread is a few months old so sry about this. But if I wanted to show a successful message after the bytes have been inserted how would I do that?
     
    OK I know this thread is a few months old so sry about this. But if I wanted to show a successful message after the bytes have been inserted how would I do that?

    Just add the following code in:
    Code:
    MessageBox.Show("Success!");

    That should about do it.
    And of course, that's only the messagebox in its most basic form.
     
    Just add the following code in:
    Code:
    MessageBox.Show("Success!");

    That should about do it.
    And of course, that's only the messagebox in its most basic form.

    Ok is there a way then to check if it succeeded? Cause I don't want it to just display a message even if it failed.
     
    Well, the application would fail to write if the file is in use. If you aren't sure if it will work properly, use a try/catch statement.

    Code:
    try
    {
    //code here that has the possibility to fail, such as reading/writing from files that may be in use.
    }
    catch
    {
    //what will happen if the code in the try block fails, such as a messagebox stating the operation failed. Usually, break statements are also put here so the application won't go on with invalid/incorrect data.
    }
    Then, the program will continue on elegantly. I wrote myself a little program for a challenge, but I decided to make sure that I only put numbers in for what is needed, so this is what I wrote:

    Code:
    Console.Write("Enter how many values you'd like to calculate: ");//get # of vals from user.
                try
                {
                    numofelements = Convert.ToInt32(Console.ReadLine());
                }
                catch
                {
                    isValid = false;
                    numofelements = 0;//default in case of error.
                }
    If what the user enters is not numbers, such as a letter or punctuation mark, the system can't convert that to an int32 (Number) value, so it errors. However, since it's in a try statement, it will catch the error, and do whatever is in the catch statement. It's great for making sure you have some kind of default handler in case something goes wrong. In your case, what I'd do is:

    Code:
    try
    {
    //stuff here for file writing
    }
    catch
    {
    //Put messages here if you want...
    break; //break in case the file write fails, exit this chunk of code silently. Anything after the catch statement [i]will not[/i] be executed. It'll just jump to the end of whatever event this was tied to.
    }
    MessageBox.Show("Success!");
    That worked perfectly thank you!
     
    Back
    Top