• Our software update is now concluded. You will need to reset your password to log in. In order to do this, you will have to click "Log in" in the top right corner and then "Forgot your password?".
  • 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
12
Years
INTRODUCTION
Spoiler:


THE CODE
Spoiler:


DECORATE IT
Spoiler:


NOTES
Spoiler:

CREDITS
Spoiler:



 
Last edited:

Danny0317

Fluorite's back, brah
1,067
Posts
10
Years
  • Age 24
  • Seen Nov 19, 2023
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
 

xGal

Mhm
241
Posts
12
Years
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:

kearnseyboy6

Aussie's Toughest Mudder
300
Posts
15
Years
  • Seen Jun 22, 2019
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).
 

Touched

Resident ASMAGICIAN
625
Posts
9
Years
  • Age 122
  • Seen Feb 1, 2018
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.
 
91
Posts
14
Years
  • Seen Feb 22, 2023
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
 
3,830
Posts
14
Years
  • Age 27
  • OH
  • Seen Feb 26, 2024
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:

xGal

Mhm
241
Posts
12
Years
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 :).
 

Le pug

Creator of Pokémon: Discovery / Fat Kid
870
Posts
10
Years
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.
 

Touched

Resident ASMAGICIAN
625
Posts
9
Years
  • Age 122
  • Seen Feb 1, 2018
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.
 
416
Posts
11
Years
  • Age 34
  • Seen Feb 10, 2024
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:

Touched

Resident ASMAGICIAN
625
Posts
9
Years
  • Age 122
  • Seen Feb 1, 2018
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.
 
416
Posts
11
Years
  • Age 34
  • Seen Feb 10, 2024
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
 

Touched

Resident ASMAGICIAN
625
Posts
9
Years
  • Age 122
  • Seen Feb 1, 2018
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

http://en.wikipedia.org/wiki/Most_significant_bit
http://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.
 

Sierraffinity

Desperately trying to retire from ROM hacking
1,069
Posts
16
Years
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?
 

xGal

Mhm
241
Posts
12
Years
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.
 
91
Posts
14
Years
  • Seen Feb 22, 2023
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
 

xGal

Mhm
241
Posts
12
Years
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