News: 11 March 2016 - Forum Rules, Mobile Version
Current Moderators - DarkSol, KingMike, MathOnNapkins, Azkadellia

Author Topic: Can You Use C++ For ROM Hacking?  (Read 1452 times)

Bob789

  • Jr. Member
  • **
  • Posts: 24
    • View Profile
Can You Use C++ For ROM Hacking?
« 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

mz

  • Sr. Member
  • ****
  • Posts: 305
    • View Profile
Re: Can You Use C++ For ROM Hacking?
« Reply #1 on: August 31, 2017, 02:16:36 pm »
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.
« Last Edit: August 31, 2017, 02:30:16 pm by mz »
There has to be a better life.

Gideon Zhi

  • IRC Staff
  • Hero Member
  • *****
  • Posts: 3394
    • View Profile
    • Aeon Genesis
Re: Can You Use C++ For ROM Hacking?
« Reply #2 on: August 31, 2017, 02:30:16 pm »
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

  • Jr. Member
  • **
  • Posts: 24
    • View Profile
Re: Can You Use C++ For ROM Hacking?
« Reply #3 on: August 31, 2017, 03:03:24 pm »
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

  • Hero Member
  • *****
  • Posts: 1943
  • 時を越えよう、そして彼女の元に戻ろう
    • View Profile
    • Apple of Eden
Re: Can You Use C++ For ROM Hacking?
« Reply #4 on: August 31, 2017, 07:20:56 pm »
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.
I am the lord, you all know my name, now. I got it all: cash, money, and fame.

Psyklax

  • Sr. Member
  • ****
  • Posts: 481
    • View Profile
    • Psyklax Translations
Re: Can You Use C++ For ROM Hacking?
« Reply #5 on: September 01, 2017, 04:12:18 am »
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

  • Hero Member
  • *****
  • Posts: 775
    • View Profile
    • Super Robot Wars A Portable translation thread
Re: Can You Use C++ For ROM Hacking?
« Reply #6 on: September 02, 2017, 06:36:05 pm »
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

  • Hero Member
  • *****
  • Posts: 2916
  • 2 + 2 = 5
    • View Profile
Re: Can You Use C++ For ROM Hacking?
« Reply #7 on: September 02, 2017, 06:46:31 pm »
Sounds like C would be pretty useful on the N64:

http://n64.icequake.net/doc/n64intro/kantan/step2/index1.html
War is Peace. Freedom is Slavery. Ignorance is Strength.

pianohombre

  • Full Member
  • ***
  • Posts: 224
    • View Profile
    • My personal website of short stories and comics
Re: Can You Use C++ For ROM Hacking?
« Reply #8 on: September 28, 2017, 07:34:44 am »
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.
One small step for man,
one giant leap for mankind. -Neil Armstrong

Gemini

  • Hero Member
  • *****
  • Posts: 1943
  • 時を越えよう、そして彼女の元に戻ろう
    • View Profile
    • Apple of Eden
Re: Can You Use C++ For ROM Hacking?
« Reply #9 on: September 28, 2017, 10:37:47 am »
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.
I am the lord, you all know my name, now. I got it all: cash, money, and fame.

pianohombre

  • Full Member
  • ***
  • Posts: 224
    • View Profile
    • My personal website of short stories and comics
Re: Can You Use C++ For ROM Hacking?
« Reply #10 on: October 07, 2017, 02:40:34 am »
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.
One small step for man,
one giant leap for mankind. -Neil Armstrong