With this tutorial you will be able to access the RAM and to modify it.
All is done using C language. If you wanna learn C, you can look here.
The compilation of the C code will produce, through some programs, a binary code that will be converted then in a GameShark code.
Toolchain 1.0 by gzrt
Includes by frauber
Fixes in 1.0.1 by DamiHack
To try we'll do an Hello World. The game we are going to edit is Super Mario 64.
Good job!
All is done using C language. If you wanna learn C, you can look here.
The compilation of the C code will produce, through some programs, a binary code that will be converted then in a GameShark code.
Toolchain 1.0 by gzrt
Includes by frauber
Fixes in 1.0.1 by DamiHack
Menu
- Installation
- Compilation
Installation
STEP 1
Install MinGW
- Download the installer here
- Launch it
- Click on Next
- Click on Next again
- Click on Download latest repository catalogues
- Click on Next
- Click on I accept the agreement
- Click on Next
- (Not recommended) If you want, change the Destination Location
- Click on Next
- (Not recommended) If you want, change or don't create the Start Menu Folder
- Click on Next
- Select C Compiler
- If you want, select also other components
- Select MSYS Basic System
- Select MinGW Developer Toolkit
- Click on Next
- Click on Install
- Wait the completion of the installation
- Unselect Display mingw-get log
- Click on Finish
STEP 2
Configure MinGW
- Download the Toolchain here
- Extract it in C:\MinGW
- Launch MinGW Shell
- Wait the loading of the console
- Enter cd /c/MinGW/n64tree-win32/bin ("/c/" is the equivalent of "C:/", replace "/c/MinGW/" with your Destination Location if you edited it)
- Enter export PATH=$PATH: 'pwd'
- Close MinGW Shell
Compilation
STEP 1
Prepare your own code
To try we'll do an Hello World. The game we are going to edit is Super Mario 64.
- Create a new folder in "n64tree-win32" called hacks (or whatever you want) where you'll put your hacks
- Create a new folder called "HelloWorld" (or whatever you want) in the folder you've just created
- Here create a new text file called "hook.txt"
- In the file you've just created enter this GameShark code:Code
812CB26C 0C10 812CB26E 0000 812CB278 1000 812CB27A 0040
- Now create a new file called main.c (or whatever you want in .c)
- In the file jou've just created, enter:Code
#include "n64.h" // Include Standard N64 Library #include "explode.h" // Include SM64 Library void _start() { asm volatile("la $gp, _gp"); // Ensure the correct data pointer is loaded PrintXY(80, 75, "Hello World"); // Print "Hello World" on X: 80 and Y: 75 }
- Save it
- At this point create a new file called "Makefile" without any extension
- In the file you've just created enter:Code
# Name PRJNAME = main PARTS = $(PRJNAME).o # Vars N64_ROOT = ../.. N64_PREFIX = mips64- N64_BIN = $(N64_ROOT)/bin INC_ROOT = include INC_FLAGS = -I. -I $(N64_ROOT)/$(INC_ROOT) LIB_FLAGS = -L. -T $(N64_ROOT)/$(INC_ROOT)/mario64.x GS_TYPE = default # Flags NOBUILTIN = -fno-builtin CFLAGS = -std=gnu99 -nodefaultlibs -march=vr4300 -mtune=vr4300 -mabi=32 $(INC_FLAGS) $(NOBUILTIN) -o3 ASFLAGS = -march=vr4300 -mabi=32 LINK_FLAGS = $(LIB_FLAGS) $(LIBS) # Programs CC = $(N64_BIN)/$(N64_PREFIX)gcc LD = $(N64_BIN)/$(N64_PREFIX)ld OBJCOPY = $(N64_BIN)/$(N64_PREFIX)objcopy CHEAT = $(N64_BIN)/$(GS_TYPE)cheat BINCODE = $(N64_BIN)/bin2code # Process all: $(PRJNAME).bin $(BINCODE) $(PRJNAME).bin 80400000 codes.txt # Turn binary into GS code cat hook.txt codes.txt | $(CHEAT) "Mario 64" 0 > Cheats.ini # Turn into cheat format $(PRJNAME).bin: $(PRJNAME).elf $(OBJCOPY) $(PRJNAME).elf $(PRJNAME).bin -O binary $(PRJNAME).elf: $(PARTS) $(LD) -o $(PRJNAME).elf $(PARTS) $(LINK_FLAGS) clean: rm *.o *.elf *~ *.bin Cheats.ini codes.txt -vf
PRJNAME is the name of the C file without the extension
GS_TYPE is the output format. You can choose "nemu" for formatted nemu cheat or "default" for simple code
STEP 2
Compile your own code
- Open MinGW Shell
- Enter cd /c/MinGW/n64tree-win32/hacks ("/c/" is the equivalent of "C:/", replace "/c/MinGW/" with your Destination Location if you edited it and replace "hacks" with the name of the folder where all your hacks are placed, if you edited it)
- Enter cd HelloWorld (Replace "HelloWorld" with the name of the folder where all the files you've just created are placed, if you edited it)
- Enter make on MinGW Shell
- If you didn't any error, a file called Cheats.ini will be created
- Open Cheats.ini where the code is finally produced
- Insert the GameShark code in an emulator
- Launch the SM64 US 1.0 ROM
- The result will be this:
- If you want to apply some changes to the C code:
- Enter make clean on MinGW Shell
- Edit the C file
- Enter make on MinGW Shell
- Close MinGW Shell
Good job!