Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/build-test-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,8 @@ jobs:
google_drive_url_secret: PH_US_DPAD_GOOGLE_DRIVE_ID
steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Set up Python
uses: actions/setup-python@v5
Expand Down Expand Up @@ -404,6 +406,7 @@ jobs:
steps:
- uses: actions/checkout@v4
with:
submodules: recursive
# Also retrieve previous commit so we can check if there are relevant changes
fetch-depth: 2

Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "base/code/external/ph-decomp"]
path = base/code/external/ph-decomp
url = https://github.com/zeldaret/ph
1 change: 1 addition & 0 deletions base/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ RUN pip install -r requirements.txt
# Add needed source files to the docker build
ADD data/* /app/
ADD code/* /app/code/
ADD code/external/ /app/code/external/
ADD extract_rom.py /app
ADD rebuild_rom.py /app
ADD Makefile /app
Expand Down
29 changes: 21 additions & 8 deletions base/Makefile
Original file line number Diff line number Diff line change
@@ -1,16 +1,21 @@
.PHONY: all debug

# Set ARM compiler
# Set ARM compiler (using g++ for C++ support)
CXX=arm-none-eabi-g++
CC=arm-none-eabi-gcc

# Set up compilation flags
CFLAGS := -marm -mno-thumb-interwork -march=armv5te -mtune=arm946e-s -fno-inline -Wall -Os

# C source file directory
# C++ source file directory
SRC_DIR=code
SRC=$(wildcard $(SRC_DIR)/*.c)
OBJ=$(SRC:.c=.o)
ASM=$(SRC:.c=.asm)
SRC_CPP=$(wildcard $(SRC_DIR)/*.cpp)
SRC_C=$(wildcard $(SRC_DIR)/*.c)
OBJ_CPP=$(SRC_CPP:.cpp=.o)
OBJ_C=$(SRC_C:.c=.o)
OBJ=$(OBJ_CPP) $(OBJ_C)
ASM=$(SRC_CPP:.cpp=.asm) $(SRC_C:.c=.asm)

# Set up compilation flags
CXXFLAGS := -marm -mno-thumb-interwork -march=armv5te -mtune=arm946e-s -fno-inline -Os -nostdlib -fno-exceptions -fno-rtti -Wno-multichar -fpermissive -I$(SRC_DIR)/external/ph-decomp/include -I$(SRC_DIR)/external/ph-decomp/libs/nds/include -I$(SRC_DIR)/external/ph-decomp/libs/c/include
CFLAGS := -marm -mno-thumb-interwork -march=armv5te -mtune=arm946e-s -fno-inline -Wall -Os -nostdlib

INPUT_NDS_FILE=$(PH_ROM_PATH)
PREPATCHED_NDS_FILE=prepatched.nds
Expand All @@ -35,10 +40,18 @@ $(PREPATCHED_NDS_FILE): $(INPUT_NDS_FILE)
# Same as `all`, but also includes readable .asm file
debug: $(OBJ) $(ASM)

# Compile C++ source file to assembly code
%.asm: %.cpp
$(CXX) $(CXXFLAGS) -S "$<" -o "$@" -fverbose-asm

# Compile C source file to assembly code
%.asm: %.c
$(CC) $(CFLAGS) -S "$<" -o "$@" -fverbose-asm

# Compile C++ source file to object file
%.o: %.cpp
$(CXX) $(CXXFLAGS) -c "$<" -o "$@"

# Compile C source file to object file
%.o: %.c
$(CC) $(CFLAGS) -c "$<" -o "$@"
Expand Down
27 changes: 0 additions & 27 deletions base/code/custom_salvage_item.c

This file was deleted.

30 changes: 30 additions & 0 deletions base/code/custom_salvage_item.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#include "ph.hpp"

#define MAX_HEALTH_ADDR 0x021BA348
#define CURRENT_HEALTH_ADDR 0x021BA34A
#define PLAYER_HEALTH_PTR_ADDR 0x2146470

extern "C" {

void custom_salvage_item(u32 item_id_with_flag) {
u16 item_id = item_id_with_flag & 0x7FFF; // Unset the most significant bit

// The salvage arm "get item" code doesn't properly set memory values for items
// that it was never intended to give, so we need to manually set them here.
switch (item_id) {
case 0xA: // heart container
gPlayerManager->mMaxHealth += 4; // Increment max health by 4 (one heart container)
gPlayerManager->mHealth =
gPlayerManager->mMaxHealth; // Restore the player's health to the new maximum
break;
case 0x45: // phantom sword
gItemManager->mItemFlags.flags[1] = gItemManager->mItemFlags.flags[1] | 0x20;
break;
}

u32 *player_health_ptr = (u32 *)PLAYER_HEALTH_PTR_ADDR;
u32 player_data = *player_health_ptr;
*((u16 *)(player_data + 0xEC)) = item_id; // Store the item ID in the specified offset
}

} // extern "C"
10 changes: 7 additions & 3 deletions base/code/extend_RUPY_npc.c → base/code/extend_RUPY_npc.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
#include <stdint.h>
#include "ph.hpp"

uint32_t extend_RUPY_npc(uint32_t *addr) {
uint32_t rupy_type = addr[0x56];
extern "C" {

u32 extend_RUPY_npc(u32 *addr) {
u32 rupy_type = addr[0x56];
switch (rupy_type) {
case 3:
return 9;
Expand All @@ -24,3 +26,5 @@ uint32_t extend_RUPY_npc(uint32_t *addr) {
return 0xffffffff;
}
}

} // extern "C"
10 changes: 0 additions & 10 deletions base/code/extend_give_item_function.c

This file was deleted.

13 changes: 13 additions & 0 deletions base/code/extend_give_item_function.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#include "ph.hpp"

extern "C" {

void extend_give_item_function(ItemManager *inventory, s32 item_id) {
switch (item_id) {
case 0x45: // phantom sword
inventory->mItemFlags.flags[1] = inventory->mItemFlags.flags[1] | 0x20;
break;
}
}

} // extern "C"
1 change: 1 addition & 0 deletions base/code/external/ph-decomp
Submodule ph-decomp added at 5b1587
14 changes: 9 additions & 5 deletions base/code/faster_boat.c → base/code/faster_boat.cpp
Original file line number Diff line number Diff line change
@@ -1,19 +1,21 @@
#include <stdint.h>
#include "ph.hpp"

extern "C" {

void faster_boat() {
uint32_t boat_speed_offset = (*(uint32_t *)(0x20EE4B4) + 0xF7FFF5B4);
u32 boat_speed_offset = (*(u32 *)(0x20EE4B4) + 0xF7FFF5B4);

int16_t *boat_speed = (int16_t *)(0x8000000 + boat_speed_offset);
s16 *boat_speed = (s16 *)(0x8000000 + boat_speed_offset);

// Increase boat speed if R button is pressed and the current speed is less
// than max speed
if (((*((uint16_t *)0x4000130) >> 8) & 1) == 0 && *boat_speed < 0x540) {
if (((*((u16 *)0x4000130) >> 8) & 1) == 0 && *boat_speed < 0x540) {
*boat_speed += 0x20;
}

// Decrease boat speed if L button is pressed and the current speed is greater
// than zero
if (((*((uint16_t *)0x4000130) >> 9) & 1) == 0 && *boat_speed > 0) {
if (((*((u16 *)0x4000130) >> 9) & 1) == 0 && *boat_speed > 0) {
*boat_speed -= 0x20;
}

Expand All @@ -22,3 +24,5 @@ void faster_boat() {
}
return;
}

} // extern "C"
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
#include <stdint.h>
#include "ph.hpp"

extern "C" {

__attribute__((target("thumb"))) void
fixed_random_treasure_in_shop(char *stack_ptr, char *nsbmd_file, char *nsbtx_file) {
Expand All @@ -7,3 +9,5 @@ fixed_random_treasure_in_shop(char *stack_ptr, char *nsbmd_file, char *nsbtx_fil
stack_ptr[i + 0x44] = nsbmd_file[i];
}
}

} // extern "C"
9 changes: 6 additions & 3 deletions base/code/get_item_model.c → base/code/get_item_model.cpp
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
#include "ph.h"
#include <stdint.h>
#include "ph.hpp"

#define NEW_DATA_FILE_PATH_PREFIX "r/"

void get_item_model(uint32_t item_id, char *nsbmd_dest, char *nsbtx_dest) {
extern "C" {

void get_item_model(u32 item_id, char *nsbmd_dest, char *nsbtx_dest) {
char *model_name;
char *model_file_path_prefix = NEW_DATA_FILE_PATH_PREFIX;

Expand All @@ -29,3 +30,5 @@ void get_item_model(uint32_t item_id, char *nsbmd_dest, char *nsbtx_dest) {
strcat(nsbtx_dest, model_name);
strcat(nsbtx_dest, ".nsbtx");
}

} // extern "C"
3 changes: 1 addition & 2 deletions base/code/ph.asm
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,4 @@
.definelabel got_new_item_model_path_prefix, 0x20e5da8
.definelabel item_id_to_string, 0x20e5c3c
.definelabel gItemManager, 0x27e0fb4
.definelabel GiveItem, 0x20adc7c
.definelabel gHealthManager, 0x27e0fbc
.definelabel gPlayerManager, 0x27e0fbc
104 changes: 0 additions & 104 deletions base/code/ph.h

This file was deleted.

Loading