![]() |
Using C language to hack Pokemon (3rd Gen)
2 Attachment(s)
Hello everybody,
Today I'm going to share my knowledge about how to use C for hacking pokemon roms instead of ASM. Ive been polishing this method for last few days. EDIT 16.8.2011: Added updated useful.h with header guard #define, remove .txt extension to use it Required Tools & Knowledge ---------------------------- Spoiler:
Compilation & Usage ------------------------------ EDIT 16.8.2011: Added Optimisation Switches Spoiler:
Action Time 1: Compiling, Using and Explanation of GetPokemonLevel.c -------------------------------------------------------------------- Spoiler:
Action Time 2: Calling Another Function (ASM or C) ----------------------------------------------- Spoiler:
That should be all regarding C & pokemon games :) If you have any questions post here. Do not copy without permission. Thanks to: HackMew for creating ASM compiler package and bat file Appendix: Pros and cons (if you think you have more say so in comments) Spoiler:
|
Very nice, I guess I thought the size of the routine would have been much larger from past experience. But with your options it appears as though it does perfectly fine. Props to you, my man. :)
|
Oh, I forgot to attach zip with examples and it was on HDD I reformated >.< . Dont worry i still have files but i need to repack them.
|
That would be useful. hahaha. XD { Failolol }
|
Updated, ive noticed that I have forgotten zip just after i clicked submit
|
I''m not the best in C...
So is it possible to call a SWI function or other code from the ROM (for example the script handler)? |
I have tested it with two C routines(see example two), but i think it should be possible with any ASM routine in rom.
|
Quote:
^ Or something to that effect. |
Quote:
ie. void (*func) (); func = 0x8romoffset; func(); |
Quote:
|
Yes!! Someone who uses Linux!
Uh, I mean, great tutorial. Seems a bit complicated though, I think I'll stick to ASM. Low-Level is kinda fun, because it poses more of a challenge. Plus you can't hack existing routines with C Code too easily, if at all. Maybe once I up my C skills, I'll look back into this. :) |
Quote:
Quote:
OT: I use linux and windows and my recent windows reinstalling screwed linux so I need to reinstall it >.< |
Quote:
|
Quote:
|
I guess. haha. Not much else choice we have, eh? XD
|
-mthumb means create THUMB code, not ARM code, which is probably what you want
-mthumb-interwork allows you to create calls between ARM and THUMB code Just sayin' Also, to account for the size of the assembled C code, that can be fixed with a simple optimisation switch (-O). -O0 : no optimisation Also, please use include guards on your header, it may help us if we use more than one C file... |
Quote:
Quote:
Quote:
Anyway thanks for noticing, I will edit tutorial accordingly. EDIT: Updated first post. |
hey, nice tutorial!
I'm REALLY REALLY sorry for updating the thread after such HUGE amount of time, but, you know, bookmarks naturally age ; ) :3c May I ask some questions, please? I was wondering if I could use a library, so downloaded libtonc, but couldn't manage to get it working, because it has to be linked, something you definitely do only when compiling a game from scratch. I tried all sort of things, but didn't work for me. Do you know a good GBA library to just #include in my C file? yes, I know that including everything in a single file is bad, but I'm allergic to makefiles and such things :p If the C file remains short, everything works fine, but I remain limited to very poor things. If I begin to put toghether some H and C files made by me (to try to supply a library) in the main one, it is really probable that everything messes up and the ROM crashes upon calling the routine. Moreover, the GCC and tge AS are tricking me in some strange ways. >:) thanks in advance, goodbye ^^ |
There unfortunately isn't (at least I assume so) a GBA library that will give you every definition in a single header file, because it's a huge mess design-wise. As long as you are using one source file only, you should also not be bothering with makefiles.
Code:
|
Quote:
Quote:
Code:
so, you enlighted me! could I "skip a step" compiling with gcc? it would save me a lot of time, because the assembly output is always really messy, in comparison to what an human would be, so I developed some tools in java to try to patch things up. and I should really try doing so, maybe I will not experiment some of the strange issues GCC and AS are giving me, and MAYBE my naive method of including everything will work! (I doubt, maybe it's my code wrong. may I upload it to ask you to look at it, please?) thanks, now I will let this topic rest in peace and continue posting on another recent one wich I missed out. really thankyou, good morning. |
Quote:
Code:
Code:
|
Quote:
but... doesn't suffice to include the header in the source? do I really have to specify things via command line? anyway, thank you for the support! sorry for having bothered you :) |
There's a library in C:\devkitPro\libgba by default if you have installed devkitarm. I dislike using a make file myself for this sort of thing, I'm pretty sure it doesn't even support things like extern.
You could try using the Python and DevkitARM dependent setup here: https://github.com/EternalCode/Empty-Template/tree/master/Sample%20Project If I recall correctly, you need to execute scripts/build and scripts/insert for Linux, and windows required scripts/build2 and scripts/insert3. Sorry for the poor names. This setup is far superior for bigger projects as it also supports direct insertion and various other perks like hooking and address repointing. It works well for small single-file projects as well. |
Quote:
.woah, I just discovered that also libtonc comes with an A file... so now how to compile properly? (sorry if I'm an hassle) if I look at openpoke, he does #include <libtonc> and lets the makefile do the rest. but you said me completely different things! Code:
(i did a mistake, I don't have gcc but devkit, with arm-none-eabi-gcc) excuse me, I don't understand very well the parameters "path to library" and "libraryname". dees the latter have to match something in particular or can it be anything? and in "path to library", what does "library" identify? the A file? therefore, assuming I want to use libtonc and didn't change the folder directory, what are the steps neded to compile? sorry if I'm demanding for such a great detail but as you can imagine I'm a total newbie in this kind of things. I feel really bad for bothering a "god" and a recently signed-up user :p well, I primarily use windows :p what do your scripts do? I used to use a simple program developed in java by me to insert a routine in the ROM :p and once compiled, what do I have to search to branch to? I saw your template in the other post (have to reply yet), but don't have looked at it for now. I will do, but I use ruby, does anithing change (hope/think not) ? |
I also recommend FBI's method, unfortunately you have to modify their python scripts to link to external stuff.
Your lines above would be correct, just your source file is missing somewhere at the beginning. /path/to/library simply refers to the folder where the library file is located in. libraryname would be libtonc then. (as far as I know, GCC automatically appends .lib or .a) So it would basically be (libtonc in the same directory as main.c): Code:
|
| All times are GMT -8. The time now is 9:07 AM. |
![]()
© 2002 - 2018 The PokéCommunity™, pokecommunity.com.
Pokémon characters and images belong to The Pokémon Company International and Nintendo. This website is in no way affiliated with or endorsed by Nintendo, Creatures, GAMEFREAK, The Pokémon Company or The Pokémon Company International. We just love Pokémon.
All forum styles, their images (unless noted otherwise) and site designs are © 2002 - 2016 The PokéCommunity / PokéCommunity.com.
PokéCommunity™ is a trademark of The PokéCommunity. All rights reserved. Sponsor advertisements do not imply our endorsement of that product or service. User generated content remains the property of its creator.
Acknowledgements
Use of PokéCommunity Assets
vB Optimise by DragonByte Technologies Ltd © 2023.