Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add "Permadeath" Option #633

Merged
merged 1 commit into from
Feb 14, 2023
Merged
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
12 changes: 12 additions & 0 deletions code/oot.ld
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ SECTIONS
*(.patch_MultiplyPlayerSpeed)
}

.patch_PermadeathDeleteSave 0x252424 : {
*(.patch_PermadeathDeleteSave)
}

.patch_SkipDaruniaDanceThree 0x257F00 : {
*(.patch_SkipDaruniaDanceThree)
}
Expand Down Expand Up @@ -1180,6 +1184,10 @@ SECTIONS
*(.patch_CurseTrapDizzyButtons)
}

.patch_PermadeathSkipMenu 0x41C980 : {
*(.patch_PermadeathSkipMenu)
}

.patch_SaveMenuIgnoreOpen 0x42EC00 : {
*(.patch_SaveMenuIgnoreOpen)
}
Expand Down Expand Up @@ -1320,6 +1328,10 @@ SECTIONS
*(.patch_DeathHandleBButton)
}

.patch_PermadeathForceQuit 0x458E20 : {
*(.patch_PermadeathForceQuit)
}

.patch_SetGameOverEntrance 0x458E3C : {
*(.patch_SetGameOverEntrance)
}
Expand Down
12 changes: 12 additions & 0 deletions code/oot_e.ld
Original file line number Diff line number Diff line change
Expand Up @@ -548,6 +548,10 @@ SECTIONS
*(.patch_MultiplyPlayerSpeed)
}

.patch_PermadeathDeleteSave 0x252424 : {
*(.patch_PermadeathDeleteSave)
}

.patch_SkipDaruniaDanceThree 0x257F00 : {
*(.patch_SkipDaruniaDanceThree)
}
Expand Down Expand Up @@ -1180,6 +1184,10 @@ SECTIONS
*(.patch_CurseTrapDizzyButtons)
}

.patch_PermadeathSkipMenu 0x41C9A4 : {
*(.patch_PermadeathSkipMenu)
}

.patch_SaveMenuIgnoreOpen 0x42EC24 : {
*(.patch_SaveMenuIgnoreOpen)
}
Expand Down Expand Up @@ -1320,6 +1328,10 @@ SECTIONS
*(.patch_DeathHandleBButton)
}

.patch_PermadeathForceQuit 0x458E40 : {
*(.patch_PermadeathForceQuit)
}

.patch_SetGameOverEntrance 0x458E5C : {
*(.patch_SetGameOverEntrance)
}
Expand Down
33 changes: 33 additions & 0 deletions code/src/hooks.s
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
.arm
.text
.syntax unified

.global hook_before_GlobalContext_Update
hook_before_GlobalContext_Update:
Expand Down Expand Up @@ -1137,6 +1138,38 @@ hook_SaveMenuIgnoreOpen:
.endif
bx lr

.global hook_PermadeathDeleteSave
hook_PermadeathDeleteSave:
push {r0-r12, lr}
bl Permadeath_DeleteSave
pop {r0-r12, lr}
bx lr

.global hook_PermadeathSkipMenu
hook_PermadeathSkipMenu:
push {r0-r12, lr}
bl Permadeath_GetOption
cmp r0,#0x0
pop {r0-r12, lr}
movne r0,#0x10
moveq r0,#0x2
bx lr

.global hook_PermadeathForceQuit
hook_PermadeathForceQuit:
ldrbeq r8,[r11,#0x9]
bxne lr
push {r0-r12, lr}
bl Permadeath_GetOption
cmp r0,#0x0
pop {r0-r12, lr}
.if _EUR_==1
bne 0x459014
.else
bne 0x458FF4
.endif
bxeq lr

.global hook_OverrideFogDuringGameplayInit
hook_OverrideFogDuringGameplayInit:
push {r0-r12, lr}
Expand Down
15 changes: 15 additions & 0 deletions code/src/patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -1580,6 +1580,21 @@ DontSetMotionSetting_patch:
SaveMenuIgnoreOpen_patch:
bl hook_SaveMenuIgnoreOpen

.section .patch_PermadeathDeleteSave
.global PermadeathDeleteSave_patch
PermadeathDeleteSave_patch:
bl hook_PermadeathDeleteSave

.section .patch_PermadeathSkipMenu
.global PermadeathSkipMenu_patch
PermadeathSkipMenu_patch:
bl hook_PermadeathSkipMenu

.section .patch_PermadeathForceQuit
.global PermadeathForceQuit_patch
PermadeathForceQuit_patch:
bl hook_PermadeathForceQuit

.section .patch_OverrideFogDuringGameplayInit
.global OverrideFogDuringGameplayInit_patch
OverrideFogDuringGameplayInit_patch:
Expand Down
23 changes: 23 additions & 0 deletions code/src/permadeath.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#include "z3D/z3D.h"
#include "settings.h"
#include "savefile.h"

u8 Permadeath_GetOption(void) {
// For safety, verify that the seed and save file was created with permadeath enabled
return gSettingsContext.permadeath && gExtSaveData.permadeath;
}

typedef void (*SaveFile_Delete_proc)(u8 fileNum);
#ifdef Version_EUR
#define SaveFile_Delete_addr 0x446FE4
#else
#define SaveFile_Delete_addr 0x446FC4
#endif
#define SaveFile_Delete ((SaveFile_Delete_proc)SaveFile_Delete_addr)

void Permadeath_DeleteSave(void) {
if (!Permadeath_GetOption()) {
return;
}
SaveFile_Delete(gSaveContext.fileNum);
}
11 changes: 6 additions & 5 deletions code/src/savefile.c
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ void SaveFile_Init(u32 fileBaseIndex) {
}

SaveFile_SetStartingInventory();
SaveFile_InitExtSaveData(fileBaseIndex + gSaveContext.fileNum);
SaveFile_InitExtSaveData(fileBaseIndex + gSaveContext.fileNum, 1);

// Ingame Defaults
gSaveContext.zTargetingSetting = gSettingsContext.zTargeting;
Expand Down Expand Up @@ -705,7 +705,7 @@ s8 SaveFile_GetIgnoreMaskReactionOption(u32 reactionSet) {
return gExtSaveData.option_IgnoreMaskReaction;
}

void SaveFile_InitExtSaveData(u32 saveNumber) {
void SaveFile_InitExtSaveData(u32 saveNumber, u8 fromSaveCreation) {
gExtSaveData.version = EXTSAVEDATA_VERSION; // Do not change this line
memset(&gExtSaveData.extInf, 0, sizeof(gExtSaveData.extInf));
gExtSaveData.extInf[EXTINF_MASTERSWORDFLAGS] =
Expand All @@ -714,6 +714,7 @@ void SaveFile_InitExtSaveData(u32 saveNumber) {
gExtSaveData.playtimeSeconds = 0;
memset(&gExtSaveData.scenesDiscovered, 0, sizeof(gExtSaveData.scenesDiscovered));
memset(&gExtSaveData.entrancesDiscovered, 0, sizeof(gExtSaveData.entrancesDiscovered));
gExtSaveData.permadeath = fromSaveCreation ? gSettingsContext.permadeath : 0;
// Ingame Options
gExtSaveData.option_EnableBGM = gSettingsContext.playMusic;
gExtSaveData.option_EnableSFX = gSettingsContext.playSFX;
Expand All @@ -732,7 +733,7 @@ void SaveFile_LoadExtSaveData(u32 saveNumber) {
Handle fileHandle;

if (R_FAILED(res = extDataMount(&fsa))) {
SaveFile_InitExtSaveData(saveNumber);
SaveFile_InitExtSaveData(saveNumber, 0);
return;
}

Expand All @@ -741,7 +742,7 @@ void SaveFile_LoadExtSaveData(u32 saveNumber) {
// Load default values if the file does not exist
if (R_FAILED(res = extDataOpen(&fileHandle, fsa, path))) {
extDataUnmount(fsa);
SaveFile_InitExtSaveData(saveNumber);
SaveFile_InitExtSaveData(saveNumber, 0);
return;
}

Expand All @@ -752,7 +753,7 @@ void SaveFile_LoadExtSaveData(u32 saveNumber) {
extDataClose(fileHandle);
extDataDeleteFile(fsa, path);
extDataUnmount(fsa);
SaveFile_InitExtSaveData(saveNumber);
SaveFile_InitExtSaveData(saveNumber, 0);
return;
}

Expand Down
7 changes: 4 additions & 3 deletions code/src/savefile.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,14 +24,14 @@ u32 SaveFile_MaskSlotValue(void);
void SaveFile_SetOwnedTradeItemEquipped(void);
void SaveFile_ResetItemSlotsIfMatchesID(u8 itemSlot);
u8 SaveFile_InventoryMenuHasSlot(u8 adult, u8 itemSlot);
void SaveFile_InitExtSaveData(u32 fileBaseIndex);
void SaveFile_InitExtSaveData(u32 fileBaseIndex, u8 fromSaveCreation);
void SaveFile_LoadExtSaveData(u32 saveNumber);
void SaveFile_SaveExtSaveData(u32 saveNumber);
void SaveFile_EnforceHealthLimit(void);
u8 SaveFile_SwordlessPatchesEnabled(void);

// Increment the version number whenever the ExtSaveData structure is changed
#define EXTSAVEDATA_VERSION 12
#define EXTSAVEDATA_VERSION 13

typedef enum {
EXTINF_BIGGORONTRADES,
Expand All @@ -43,7 +43,7 @@ typedef enum {

typedef struct {
u32 version; // Needs to always be the first field of the structure
u8 extInf[EXTINF_SIZE]; // Used for various bit flags
u8 extInf[EXTINF_SIZE]; // Used for various bit flags that should also be synced in multiplayer
struct {
Vec3i pos;
s32 yaw;
Expand All @@ -57,6 +57,7 @@ typedef struct {
u32 playtimeSeconds;
u32 scenesDiscovered[SAVEFILE_SCENES_DISCOVERED_IDX_COUNT];
u32 entrancesDiscovered[SAVEFILE_ENTRANCES_DISCOVERED_IDX_COUNT];
u8 permadeath;
// Ingame Options, all need to be s8
s8 option_EnableBGM;
s8 option_EnableSFX;
Expand Down
1 change: 1 addition & 0 deletions code/src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,7 @@ typedef struct {
u8 fastBunnyHood;

u8 damageMultiplier;
u8 permadeath;
u8 startingTime;
u8 gossipStoneHints;
u8 totAltarHints;
Expand Down
5 changes: 5 additions & 0 deletions source/descriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -825,6 +825,11 @@ string_view damageMultiDesc = "Changes the amount of damage taken.\n"
"\n" //
"If set to OHKO, Link will die in one hit."; //
/*------------------------------ //
| PERMADEATH | //
------------------------------*/ //
string_view permadeathDesc = "Dying deletes your save file and kicks you back\n"//
"out to the main menu."; //
/*------------------------------ //
| STARTING TIME | //
------------------------------*/ //
string_view startingTimeDesc = "Change up Link's sleep routine."; //
Expand Down
2 changes: 2 additions & 0 deletions source/descriptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -266,6 +266,8 @@ extern string_view mapsShowDungeonModesDesc;

extern string_view damageMultiDesc;

extern string_view permadeathDesc;

extern string_view startingTimeDesc;

extern string_view locationsReachableDesc;
Expand Down
1 change: 1 addition & 0 deletions source/preset.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -492,6 +492,7 @@ PremadePreset presetFullChaos = { "Full Chaos",
{ &Settings::CompassesShowWotH, OFF },
{ &Settings::MapsShowDungeonMode, OFF },
{ &Settings::DamageMultiplier, DAMAGEMULTIPLIER_OHKO },
{ &Settings::Permadeath, ON },
{ &Settings::RandomTrapDmg, RANDOMTRAPS_ADVANCED },
{ &Settings::FireTrap, ON },
{ &Settings::AntiFairyTrap, ON },
Expand Down
3 changes: 3 additions & 0 deletions source/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@ Option CompassesShowReward = Option::U8 ("Compasses Show Rewards", {"No", "Yes"
Option CompassesShowWotH = Option::U8 ("Compasses Show WotH", {"No", "Yes"}, {compassesShowWotHDesc}, OptionCategory::Setting, ON);
Option MapsShowDungeonMode = Option::U8 ("Maps Show Dungeon Modes",{"No", "Yes"}, {mapsShowDungeonModesDesc}, OptionCategory::Setting, ON);
Option DamageMultiplier = Option::U8 ("Damage Multiplier", {"x1/2", "x1", "x2", "x4", "x8", "x16", "OHKO"}, {damageMultiDesc}, OptionCategory::Setting, DAMAGEMULTIPLIER_DEFAULT);
Option Permadeath = Option::Bool("Permadeath", {"Off", "On"}, {permadeathDesc});
Option StartingTime = Option::U8 ("Starting Time", {"Day", "Night"}, {startingTimeDesc});
Option ChestAnimations = Option::Bool("Chest Animations", {"Always Fast", "Match Contents"}, {chestAnimDesc});
Option ChestSize = Option::Bool("Chest Size and Color", {"Vanilla", "Match Contents"}, {chestSizeDesc});
Expand All @@ -348,6 +349,7 @@ std::vector<Option *> miscOptions = {
&CompassesShowWotH,
&MapsShowDungeonMode,
&DamageMultiplier,
&Permadeath,
&StartingTime,
&ChestAnimations,
&ChestSize,
Expand Down Expand Up @@ -1425,6 +1427,7 @@ SettingsContext FillContext() {
ctx.compassesShowWotH = CompassesShowWotH.Value<u8>();
ctx.mapsShowDungeonMode = MapsShowDungeonMode.Value<u8>();
ctx.damageMultiplier = DamageMultiplier.Value<u8>();
ctx.permadeath = (Permadeath) ? 1 : 0;
ctx.startingTime = StartingTime.Value<u8>();
ctx.chestAnimations = (ChestAnimations) ? 1 : 0;
ctx.chestSize = (ChestSize) ? 1 : 0;
Expand Down
1 change: 1 addition & 0 deletions source/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,7 @@ extern Option CompassesShowReward;
extern Option CompassesShowWotH;
extern Option MapsShowDungeonMode;
extern Option DamageMultiplier;
extern Option Permadeath;
extern Option StartingTime;
extern Option ChestAnimations;
extern Option ChestSize;
Expand Down