• 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 Conquest 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.

Make your own ROM hacking tool (C#)

xGal

Mhm
  • 241
    Posts
    13
    Years
    INTRODUCTION
    Spoiler:


    THE CODE
    Spoiler:


    DECORATE IT
    Spoiler:


    NOTES
    Spoiler:

    CREDITS
    Spoiler:



     
    Last edited:
    Overall, pretty good. But you should make a note that the program will crash if the rom is opened in A-Map, at least that's what happened to me

    Yeah, I'll guess that's what is going to happen because unlike my code, aMap uses the rom all the time it's being opened by advanced map. The good thing about my code is that it's only using the file in the opening and saving processes :). Anyways, thanks for your feedback :D. BTW guys I'll fix my grammar errors as soon I get back on my computer :).
     
    Last edited:
    This is great, I plan on learning C+ very soon and help make some tools. I will be bookmarking this for the future but I also do recommend a check to see if the ROM is already open (like HxD and Jambo's tools do).
     
    I'm not a C# programmer, but I think you should at least alert people to the existence of Mono - the community is moving towards being cross platform and I think most tool makers should be told how to do this. I'd guess i18n is also important, but I'm really not so sure how to do this in C#.

    Anyway, I dislike C# much more than I dislike Java, so that might does make me biased, but is C# really the best language for people to lean? (Does anyone else hate how in Chrome, if you type "C#" as the first part of your query in the omnibox, it doesn't work? Another reason to hate the language) It's not exactly cross-platform, and it's hardly user-friendly. Additionally it's very Microsoft-centric. Besides, it's not exactly difficult to create a GUI in Java (by Java standards, that is), so why don't you just use that?

    Also, why do we need a tool to do every little thing for us? This is easily done in a hex editor. Besides, I'm of the opinion that programmers should try and integrate their tools into something cohesive, rather than fragment functionality like this.
     
    I would really recommend programmers to use object oriented elements if you want to use an object oriented language... Also: Get yourselves some basic style of coding. Even if you do not follow any damn standard that exists out there (And there are lots) - give your variables consistant names, do not name something "classnameAlphanumericalNumber" because it gives a potential reader headaches!

    As for C# I wrote a library: https://github.com/SBird1337/Single.net feel free to use it as it implements most of the stuff you could possibly want to access in a gba rom (Header Data, Graphics, raw byte manipulation, etc) even if im not yet fully statisfied with the text encoding / decoding which probably needs rework.

    When interacting with files, regardless(for most parts) of the language: Error freaking handling! What happens if a user wants to open a non-existant file or if its currently in use? Your program will throw an exception, an ugly wall-of-error will fill the users screen (Which is basically good, because if its a smart user he will give you the error message and you can fix the problem, anyways if you caught the exception in the first place you would be able to give him a proper error message instead of a long list of stack traces etc)

    For all the Java, insert-other-language-that-is-so-much-better-then-c# and other fanboys: Stop that, there are many reasons why you would prefer a language over another, as for C# its an awesome IDE, a freaking huge framework with all you will probably ever need, syntax elements such as LINQ, generics, lambda functions and so on, i'm sure you can find some for your prefered language too, but keep in mind: I don't even care!

    ~SBird
     
    The code you use for reading the ROM code is okay, but not really as good as it could be. Here's what I would do:

    Code:
    string gameCode = string.Empty;
    using (BinaryReader br = new BinaryReader(File.OpenRead(ofd.FileName)))
    {
         br.BaseStream.Seek(0xAC, SeekOrigin.Begin);
         gameCode = Encoding.UTF8.GetString(br.ReadBytes(4));
    }

    Using this method is a lot cleaner, and it guarantees that the file stream is disposed of correctly. ;)

    Then, for the enable/disable stuff, try this:

    Code:
    using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(ofd.FileName)))
    {
         bw.Seek(0xBD494, SeekOrigin.Begin);
         bw.Write((byte)0x00); // or bw.Write((byte)0x08); // Change depending on use.
    }

    The way you use the for loop coupled with setting the stream's position each time you write is a BAD idea, because it just slows things down.
     
    Last edited:
    I would really recommend programmers to use object oriented elements if you want to use an object oriented language... Also: Get yourselves some basic style of coding. Even if you do not follow any damn standard that exists out there (And there are lots) - give your variables consistant names, do not name something "classnameAlphanumericalNumber" because it gives a potential reader headaches!

    As for C# I wrote a library: https://github.com/SBird1337/Single.net feel free to use it as it implements most of the stuff you could possibly want to access in a gba rom (Header Data, Graphics, raw byte manipulation, etc) even if im not yet fully statisfied with the text encoding / decoding which probably needs rework.

    When interacting with files, regardless(for most parts) of the language: Error freaking handling! What happens if a user wants to open a non-existant file or if its currently in use? Your program will throw an exception, an ugly wall-of-error will fill the users screen (Which is basically good, because if its a smart user he will give you the error message and you can fix the problem, anyways if you caught the exception in the first place you would be able to give him a proper error message instead of a long list of stack traces etc)

    For all the Java, insert-other-language-that-is-so-much-better-then-c# and other fanboys: Stop that, there are many reasons why you would prefer a language over another, as for C# its an awesome IDE, a freaking huge framework with all you will probably ever need, syntax elements such as LINQ, generics, lambda functions and so on, i'm sure you can find some for your prefered language too, but keep in mind: I don't even care!

    ~SBird

    The code you use for reading the ROM code is okay, but not really as good as it could be. Here's what I would do:

    Code:
    string gameCode = string.Empty;
    using (BinaryReader br = new BinaryReader(File.OpenRead(ofd.FileName)))
    {
         br.BaseStream.Seek(0xAC, SeekOrigin.Begin);
         gameCode = Encoding.UTF8.GetString(br.ReadBytes(4));
    }

    Using this method is a lot cleaner, and it guarantees that the file stream is disposed of correctly. ;)

    Then, for the enable/disable stuff, try this:

    Code:
    using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(ofd.FileName)))
    {
         bw.Seek(0xBD494, SeekOrigin.Begin);
         bw.Write((byte)0x00); // or bw.Write((byte)0x08); // Change depending on use.
    }

    The way you use the for loop coupled with setting the stream's position each time you write is a BAD idea, because it just slows things down.

    Thanks for your contributions, I will add them in the main post :).
     
    I like this contribution a lot. There are a few tool ideas I've had in mind forever but don't know where to begin for which type of language to use or whatever. This gives me a great idea and will help a lot. If you're willing, maybe even expand on this tutorial to add more tidbits of knowledge in the future until we overdose on C+ knowledge? Great tutorial and I know it'll help people steer in the right direction.
     
    I would really recommend programmers to use object oriented elements if you want to use an object oriented language... Also: Get yourselves some basic style of coding. Even if you do not follow any damn standard that exists out there (And there are lots) - give your variables consistant names, do not name something "classnameAlphanumericalNumber" because it gives a potential reader headaches!

    As for C# I wrote a library: https://github.com/SBird1337/Single.net feel free to use it as it implements most of the stuff you could possibly want to access in a gba rom (Header Data, Graphics, raw byte manipulation, etc) even if im not yet fully statisfied with the text encoding / decoding which probably needs rework.

    When interacting with files, regardless(for most parts) of the language: Error freaking handling! What happens if a user wants to open a non-existant file or if its currently in use? Your program will throw an exception, an ugly wall-of-error will fill the users screen (Which is basically good, because if its a smart user he will give you the error message and you can fix the problem, anyways if you caught the exception in the first place you would be able to give him a proper error message instead of a long list of stack traces etc)

    For all the Java, insert-other-language-that-is-so-much-better-then-c# and other fanboys: Stop that, there are many reasons why you would prefer a language over another, as for C# its an awesome IDE, a freaking huge framework with all you will probably ever need, syntax elements such as LINQ, generics, lambda functions and so on, i'm sure you can find some for your prefered language too, but keep in mind: I don't even care!

    ~SBird

    I was not recommending any one language. I was merely recommending that you choose a language that is designed to be cross-platform, instead of one that is quite anchored to one platform. What's wrong with wanting tools to be more accessible to the community? Besides, none of the features you listed are at all unique to C#. Any high-level language will boast similar features.
     
    I really enjoyed this little tutorial. Being a C# programmer myself it motivated me to make my own tool...

    I am pretty well finished except I cant for the life of me figure out how to open images inside the game... My tool is a Item editor... and i want to be able to edit the items images(along with all the other stuff), but I cant figure out how to decompress them, then recompress them (after they have been altered)...

    any one have any ideas (or a pre written class) imput an offset (int or string) and return a bitmap lol
     
    Last edited:
    I really enjoyed this little tutorial. Being a C# programmer myself it motivated me to make my own tool...

    I am pretty well finished except I cant for the life of me figure out how to open images inside the game... My tool is a Item editor... and i want to be able to edit the items images(along with all the other stuff), but I cant figure out how to decompress them, then recompress them (after they have been altered)...

    any one have any ideas (or a pre written class) imput an offset (int or string) and return a bitmap lol

    Image data like that is LZSS compressed. You can either implement your own given the spec on GBATek or use this library.
     
    Image data like that is LZSS compressed. You can either implement your own given the spec on GBATek or use this library.

    Spoiler:


    Its not too complicated... but what do MSBs and LSBs mean?

    Ive seen dsdecmp before but it does not seem to work like I want (cant get output to image) or im messing up somewhere else, could be anything... who knows
     
    Spoiler:


    Its not too complicated... but what do MSBs and LSBs mean?

    Ive seen dsdecmp before but it does not seem to work like I want (cant get output to image) or im messing up somewhere else, could be anything... who knows

    https://en.wikipedia.org/wiki/Most_significant_bit
    https://en.wikipedia.org/wiki/Least_significant_bit

    You can't just decompress the image; its not just a standard array of pixels. Its basically each 8x8 tile stored sequentially. You have to read it 64 pixels at a time (items are 4bpp). Keep in mind that you also have to load the palette, etc. etc. Also, a number of other image formats are used. Take a look at Tile Molester to see how many image codecs can be used.
     
    As for C# I wrote a library: https://github.com/SBird1337/Single.net feel free to use it as it implements most of the stuff you could possibly want to access in a gba rom (Header Data, Graphics, raw byte manipulation, etc) even if im not yet fully statisfied with the text encoding / decoding which probably needs rework.
    I would like to use your functions in my own tool but I don't know how to import them in and use them in my project. Could you please help?
     
    I would like to use your functions in my own tool but I don't know how to import them in and use them in my project. Could you please help?

    If you want, I could help. Just download the files from his GitHub, open your project in Visual Studio, press Shift+Alt+A and choose the functions you have downloaded.
     
    I would like to use your functions in my own tool but I don't know how to import them in and use them in my project. Could you please help?

    You can either download and compile the project and just reference the library file (.dll) in your projects, that should work.

    If you want to view the code in the debugger I recommend adding the whole project to your project folder. In case you are using visual studio do as follows: Right click in your solution explorer on the solution you are currently working on and select: Add - Existing project. Select the project file from the github master folder and (very important) reference the Single project from your main project (just like adding a normal reference, but checking the project tab - its where you find libraries that are already inside your solution.

    The code is currently partly commended, but in german. I will probably recomment most of it when I find the time to, but most of the stuff is pretty self-explaining.

    Keep in mind that the library will copy any rom object into the memory and work with a byte[] object. In order write changes to files you have to use Rom.Save or Rom.Patch, which will either overwrite a file / create a new one or patch a file.

    Good luck programming :)

    ~SBird
     
    This is how to make the BinaryWriter write a specified offset and a specified byte from textboxes:

    Code:
                using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(ofd.FileName)))
                {
                    bw.Seek(Convert.ToInt32([OffsetMessageBox].Text, 16), SeekOrigin.Begin);
                    bw.Write((byte)Convert.ToInt32([ByteMessageBox].Text));
                }

    Replace [OffsetMessageBox] to the textbox where the user should put the offset and the [ByteMessageBox] to the byte you want the BinaryWriter to change.
     
    Back
    Top