News:

11 March 2016 - Forum Rules

Main Menu

Can You Use C++ For ROM Hacking?

Started by Bob789, August 31, 2017, 12:51:00 PM

Previous topic - Next topic

Bob789

Hello all,

As the title suggests, I would like to know if it would be possible to use C++ for ROM Hacking. I ask because everything I've seen points to Assembly as the way to go for ROM Hacking, but I'm quite far in C++(which I learned for separate reasons), and I would hate to have to learn an entirely new language. So yeah, is there any way to use C++ for ROM Hacking?

Thanks,
Bob789

mz

#1
You can use any* language you want for ROM hacking, even no language at all, since you can only interact with the actual "raw" bytes.

A lot of people, including me, even use shitty programming languages like PHP, JavaScript and similar.

You may still want to learn assembly to reverse engineer more easily a game's code and create new code for it using an assembler. If you already know another programming language like C++, assembly can be learned in minutes.

* As long as it's possible to read files in binary mode with it.
There has to be a better life.

Gideon Zhi

To clarify:

You can use C++ to write utilities that will help you hack any given game, but if you want to actually reprogram a game, unless there's C++ hooks/standard libraries for the platform (like there are on PSP) then you're going to have to learn the platform's assembly language. And even if there are C++ hooks available you're still probably going to want to study the platform's hardware architecture if you want to do anything remotely complex with the game.

Bob789

Wow, I'm quite surprised my post got replied to so quickly!

Anyways, since I'm more interested in reprogramming the game rather than making utilities, I suppose I could learn Assembly. How hard could it be? :)
If what mz says is true, and it won't take that long, why not?

Thanks both of you for your informative answers.

Gemini

You're still going to need some assembly for understanding the code and for injecting hooks, but yeah, you can hack a game as you please with C/++ as long as you can compile correct binaries.

Psyklax

I don't know any high level programming languages, but I've hacked a few NES games, including assembly hacking. I didn't know anything about it until a few months ago, but it's really quite simple. I can't speak for anything beyond 8-bit because I haven't got there yet, but I know that hacking the 6502 is very straightforward. As mentioned above, though, understanding how the hardware of the specific system works is VERY helpful.

BlackDog61

You could use C here and there, for your newly created functions or routines, provided you can assemble it into the right ASM. Like you can on the PSP with armips, for instance.

SunGodPortal

Cigarettes, ice-cream, figurines of the Virgin Mary...

pianohombre

Quote from: Bob789 on August 31, 2017, 03:03:24 PM
Anyways, since I'm more interested in reprogramming the game rather than making utilities, I suppose I could learn Assembly. How hard could it be? :)
If what mz says is true, and it won't take that long, why not?

Don't be intimidated by Assembly. It is difficult don't go in there thinking it will be easy. Whatever platform you're trying to understand whether it's NES, Sega Genesis, or SNES they all use assembly and many blocks of code will seem impossible to understand. I'd recommend hacking Super Mario Bros. first, that game is heavily documented and you can find documentation at practically any address that will explain what the assembly does.

For less documented games, some piece of assembly could be unintelligible. You could literally work on trying to understand less than 100 lines for six months, if a certain game does something unusual. There are many tools out there to help you- hex editors, disassemblers, emulators with debuggers included, and some games have RAM maps with important known addresses.
"Programming in itself is beauty,
whether or not the operating system actually functions." - Steve Wozniak

Gemini

The problem here isn't really that you need to understand the code fully, but that you need to add new pieces altogether. Assembly, while simple enough in nature, is not exactly the best pragmatic solution, especially when you need to add huge sections of new code. On top of that, C/++ makes it super easy to recycle hacks on different games.

pianohombre

It depends on what exactly you're trying to hack, and whom your audience is. Yes, for hacks such as level and text-editors it's important to know C++, since you're going to want to make a nice simple to use GUI for fans to change the game. If however, you just want to make a few small changes you're going to need to probably learn assembly, and there's no reason to use C++ at all. Assembly can be pretty challenging for first-time learners. There's big and little endian, and short-hand memory addresses used in pointer tables. Just making a simple jump can be a real hassle, but assembly is easier than hex IMHO, and if you learn how to compile assembly files correctly, it's a lot more understandable than working with large chunks of hex.

My first hack was extremely small. All I did was add leg parts to this pre-made Megaman rom hack, but I had to learn where to find free memory space, how to use an if statement, and jump to subroutines. It took me about a week to learn how to properly find the right assembly commands, learn how to make a patch, which memory addresses to edit, getting ROM addresses from RAM addresses, learning all the proper terminology and sections of a rom game, how to use an emulator debugger, and then do it in hex and assembly.
"Programming in itself is beauty,
whether or not the operating system actually functions." - Steve Wozniak

90s comeback

Quote from: Bob789 on August 31, 2017, 12:51:00 PM
Hello all,

As the title suggests, I would like to know if it would be possible to use C++ for ROM Hacking. I ask because everything I've seen points to Assembly as the way to go for ROM Hacking, but I'm quite far in C++(which I learned for separate reasons), and I would hate to have to learn an entirely new language. So yeah, is there any way to use C++ for ROM Hacking?

Thanks,
Bob789
How did your assembly adventure go?, i'm looking forward to knowing if C++ knowledge can be applied to assembly.

KingMike

C++ is a "high level" language, meaning that it is meant to be more abstracted from the CPU instruction set (which is what "Assembly" is).

I would say generally not.
You can't just make a "print" statement in Assembly and have it do something (not unless the particular hardware has a BIOS/firmware designed to provide such pre-writtens function available to the user).

Also, while much of the same concepts can apply between them (with some terminology changes) once learned, the "Assembly" language used will be different between different CPU families.
Assembly is basically machine instructions which explicitly calculate and shift data around between the CPU, memory and I/O. Thus it is needed to know exact technical details of the hardware being written for, such as CPU used, memory map/IO registers and so on.
Languages such as C++ use compilers designed to let the programmer write code which does not need the programmer to know the specific architectural details of the hardware being used.
"My watch says 30 chickens" Google, 2018