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

Setting: Chest Appearance Mod requires Shard of Agony #689

Merged
merged 1 commit into from
Aug 20, 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
40 changes: 22 additions & 18 deletions code/src/actors/chest.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,32 @@ u32 isBombchuMajor(void) {
}

void EnBox_rInit(Actor* thisx, GlobalContext* globalCtx) {
EnBox* this = (EnBox*)thisx;
EnBox_Init(thisx, globalCtx);
sLastTrapChest = 0;

u8 vanilla = (gSettingsContext.chestAppearance == CHESTAPPEARANCE_VANILLA) ||
(globalCtx->sceneNum == 16 && thisx->room != 6); // treasure chest shop, final room
if ((gSettingsContext.chestAppearance != CHESTAPPEARANCE_VANILLA)) {
// Set mipmap count to 1 for both chest models, to avoid issues with custom textures
void** cmbMan = ZAR_GetCMBByIndex(((EnBox*)thisx)->zarInfo, 1);
*((u8*)(*cmbMan) + 0x59C) = 1;
*((u8*)(*cmbMan) + 0x530) = 1;

// Change Appearance depending on settings
if (!gSettingsContext.chestAgony || ((gSaveContext.questItems >> 21) & 1)) { // shard of agony inventory flag
Chest_ChangeAppearance(thisx, globalCtx);
}
}
}

void Chest_ChangeAppearance(Actor* thisx, GlobalContext* globalCtx) {
EnBox* this = (EnBox*)thisx;

if (globalCtx->sceneNum == 16 && thisx->room != 6) { // treasure chest shop, not final room
return;
}

ItemOverride thisOverride = ItemOverride_Lookup(thisx, globalCtx->sceneNum, 0);
ItemRow* thisItemRow;
if (vanilla || thisOverride.key.all == 0) {
if (thisOverride.key.all == 0) {
thisItemRow = ItemTable_GetItemRowFromIndex((thisx->params & 0x0FE0) >> 5); // get type from vanilla item table
} else {
thisItemRow = ItemTable_GetItemRow(ItemTable_ResolveUpgrades(thisOverride.value.itemId));
Expand All @@ -44,11 +61,8 @@ void EnBox_rInit(Actor* thisx, GlobalContext* globalCtx) {
type = isBombchuMajor() ? CHEST_MAJOR : CHEST_JUNK;
}

EnBox_Init(thisx, globalCtx);

// Change Chest Model
if (type == CHEST_BOSS_KEY ||
((gSettingsContext.chestAppearance != CHESTAPPEARANCE_VANILLA) && (type == CHEST_SMALL_KEY))) {
if (type == CHEST_BOSS_KEY || type == CHEST_SMALL_KEY) {
// 0: Fancy Chest 1: Wooden Chest 2: Fancy Lid 3: Wooden Lid
Model_EnableMeshGroupByIndex(this->skelAnime.unk_28, 0);
Model_EnableMeshGroupByIndex(this->skelAnime.unk_28, 2);
Expand All @@ -61,11 +75,6 @@ void EnBox_rInit(Actor* thisx, GlobalContext* globalCtx) {
Model_DisableMeshGroupByIndex(this->skelAnime.unk_28, 2);
}

// Stop here for vanilla settings
if (vanilla) {
return;
}

// Change Chest Texture
if (gSettingsContext.chestAppearance == CHESTAPPEARANCE_TEXTURE ||
gSettingsContext.chestAppearance == CHESTAPPEARANCE_SIZE_AND_TEXTURE) {
Expand All @@ -75,11 +84,6 @@ void EnBox_rInit(Actor* thisx, GlobalContext* globalCtx) {
exObjectBankIdx = Object_Spawn(&rExtendedObjectCtx, OBJECT_CUSTOM_GENERAL_ASSETS);
}

void** cmbMan = ZAR_GetCMBByIndex(this->zarInfo, 1);
// Set mipmap count to 1 for both chest models
*((u8*)(*cmbMan) + 0x59C) = 1;
*((u8*)(*cmbMan) + 0x530) = 1;

static const u32 chestType_to_assetIndex[CHESTTYPE_MAX] = { TEXANIM_GOLD_CHEST, 0, 0,
TEXANIM_KEY_CHEST, 0, TEXANIM_HEART_CHEST,
TEXANIM_SKULL_CHEST };
Expand Down
1 change: 1 addition & 0 deletions code/src/actors/chest.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ typedef enum {

void EnBox_rInit(Actor* thisx, GlobalContext* globalCtx);
void EnBox_rUpdate(Actor* thisx, GlobalContext* globalCtx);
void Chest_ChangeAppearance(Actor* thisx, GlobalContext* globalCtx);
u8 Chest_OverrideAnimation();
u8 Chest_OverrideIceSmoke(Actor* thisx);

Expand Down
10 changes: 10 additions & 0 deletions code/src/item_effect.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "multiplayer.h"
#include "dungeon.h"
#include "common.h"
#include "actors/chest.h"

void ItemEffect_None(SaveContext* saveCtx, s16 arg1, s16 arg2) {
}
Expand Down Expand Up @@ -423,3 +424,12 @@ void ItemEffect_OwnAdultTrade(SaveContext* saveCtx, s16 arg1, s16 arg2) {
void ItemEffect_GiveWeirdEgg(SaveContext* saveCtx, s16 arg1, s16 arg2) {
gSaveContext.sceneFlags[0x60].unk |= 0x1 << 0x10;
}

void ItemEffect_ShardOfAgony(SaveContext* saveCtx, s16 arg1, s16 arg2) {
if (IsInGame() && gSettingsContext.chestAppearance != CHESTAPPEARANCE_VANILLA && gSettingsContext.chestAgony) {
Actor* chest = gGlobalContext->actorCtx.actorList[ACTORTYPE_CHEST].first;
for (; chest != NULL; chest = chest->next) {
Chest_ChangeAppearance(chest, gGlobalContext);
}
}
}
1 change: 1 addition & 0 deletions code/src/item_effect.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,5 @@ void ItemEffect_MoveNabooru(SaveContext* saveCtx, s16 arg1, s16 arg2);
void ItemEffect_GrannySellsPotions(SaveContext* saveCtx, s16 arg1, s16 arg2);
void ItemEffect_OwnAdultTrade(SaveContext* saveCtx, s16 arg1, s16 arg2);
void ItemEffect_GiveWeirdEgg(SaveContext* saveCtx, s16 arg1, s16 arg2);
void ItemEffect_ShardOfAgony(SaveContext* saveCtx, s16 arg1, s16 arg2);
#endif //_ITEM_EFFECT_H_
4 changes: 2 additions & 2 deletions code/src/item_table.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,8 +74,8 @@ static ItemRow rItemTable[] = {
[0x36] = ITEM_ROW(0x53, 0, 0x52, 0x005C, 0x012D, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x4A, ItemUpgrade_None, ItemEffect_None, -1, -1), // Golden Gauntlets
[0x37] = ITEM_ROW(0x53, 0, 0x53, 0x00CD, 0x00DB, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x2A, ItemUpgrade_None, ItemEffect_None, -1, -1), // Silver Scale
[0x38] = ITEM_ROW(0x53, 0, 0x54, 0x00CE, 0x00DB, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x2B, ItemUpgrade_None, ItemEffect_None, -1, -1), // Golden Scale
[0x39] = ITEM_ROW(0x53, 0, 0x6F, 0x0068, 0x00C8, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x21, ItemUpgrade_None, ItemEffect_None, -1, -1), // Stone of Agony
[0x3A] = ITEM_ROW(0x53, 0, 0x70, 0x007B, 0x00D7, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x24, ItemUpgrade_None, ItemEffect_None, -1, -1), // Gerudo Membership Card
[0x39] = ITEM_ROW(0x53, 0, 0x6F, 0x0068, 0x00C8, 0x01, 0xFF, 0xFF, 0xFF, 0xFF, 0x21, ItemUpgrade_None, ItemEffect_ShardOfAgony, -1, -1), // Shard of Agony
[0x3A] = ITEM_ROW(0x53, 0, 0x70, 0x007B, 0x00D7, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x24, ItemUpgrade_None, ItemEffect_None, -1, -1), // Gerudo Token
[0x3B] = ITEM_ROW(0x53, 0, 0x41, 0x004A, 0x010E, 0x02, 0xFF, 0xFF, 0xFF, 0xFF, 0x46, ItemUpgrade_None, ItemEffect_GiveFairyOcarina, -1, -1), // Fairy Ocarina
[0x3C] = ITEM_ROW(0x4D, 1, 0x58, 0x00DC, 0x0119, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x48, ItemUpgrade_SeedsToRupee, ItemEffect_None, -1, -1), // Deku Seeds (5)
[0x3D] = ITEM_ROW(0x3D, 5, 0x72, 0x00C6, 0x00BD, 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0x13, ItemUpgrade_HealthToRupee, ItemEffect_FullHeal, -1, -1), // Heart Container
Expand Down
1 change: 1 addition & 0 deletions code/src/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -567,6 +567,7 @@ typedef struct {
u8 mapsShowDungeonMode;
u8 chestAnimations;
u8 chestAppearance;
u8 chestAgony;
u8 generateSpoilerLog;
u8 ingameSpoilers;
u8 menuOpeningButton;
Expand Down
4 changes: 3 additions & 1 deletion source/descriptions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -876,7 +876,7 @@ string_view chestAnimDesc = "Choose if you want the slow animation t
"if a chest contains a major item.\n"; //
//
/*------------------------------ //
| CHEST SIZE AND COLOR | //
| CHEST APPEARANCE | //
------------------------------*/ //
string_view chestVanillaDesc = "Chests will appear as they do in the base game."; //
string_view chestTextureDesc = "Chest texture will reflect its contents\n" //
Expand All @@ -898,6 +898,8 @@ string_view chestClassicDesc = "This is the behavior of CSMC in previou
"Lesser Items -> Small Wooden Chests\n" //
"Boss Keys -> Big Fancy Chests\n" //
"Small Keys -> Small Fancy Chests"; //
string_view chestAgonyDesc = "The Chest Appearance Mod will only apply\n" //
"after obtaining the Shard of Agony.\n"; //
//
/*------------------------------ //
| INGAME SPOILERS | //
Expand Down
2 changes: 2 additions & 0 deletions source/descriptions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ extern string_view chestTextureDesc;
extern string_view chestSizeTextureDesc;
extern string_view chestClassicDesc;

extern string_view chestAgonyDesc;

extern string_view ingameSpoilersShowDesc;
extern string_view ingameSpoilersHideDesc;

Expand Down
10 changes: 10 additions & 0 deletions source/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,6 +331,7 @@ Option MapsShowDungeonMode = Option::U8 ("Maps Show Dungeon Modes",{"No", "Yes"
Option StartingTime = Option::U8 ("Starting Time", {"Day", "Night"}, {startingTimeDesc});
Option ChestAnimations = Option::Bool("Chest Animations", {"Always Fast", "Match Contents"}, {chestAnimDesc});
Option ChestAppearance = Option::U8 ("Chest Appearance Mod", {"Vanilla", "Texture", "Size & Texture", "Classic CSMC"}, {chestVanillaDesc, chestTextureDesc, chestSizeTextureDesc, chestClassicDesc});
Option ChestAgony = Option::Bool(2, "Need Shard of Agony", {"No", "Yes"}, {chestAgonyDesc});
Option GenerateSpoilerLog = Option::Bool("Generate Spoiler Log", {"No", "Yes"}, {""}, OptionCategory::Setting, ON);
Option IngameSpoilers = Option::Bool("Ingame Spoilers", {"Hide", "Show"}, {ingameSpoilersHideDesc, ingameSpoilersShowDesc });
bool HasNightStart = false;
Expand All @@ -349,6 +350,7 @@ std::vector<Option *> miscOptions = {
&StartingTime,
&ChestAnimations,
&ChestAppearance,
&ChestAgony,
&GenerateSpoilerLog,
&IngameSpoilers,
};
Expand Down Expand Up @@ -1471,6 +1473,7 @@ SettingsContext FillContext() {
ctx.startingTime = StartingTime.Value<u8>();
ctx.chestAnimations = (ChestAnimations) ? 1 : 0;
ctx.chestAppearance = ChestAppearance.Value<u8>();
ctx.chestAgony = (ChestAgony) ? 1 : 0;
ctx.generateSpoilerLog = (GenerateSpoilerLog) ? 1 : 0;
ctx.ingameSpoilers = (IngameSpoilers) ? 1 : 0;
ctx.menuOpeningButton = MenuOpeningButton.Value<u8>();
Expand Down Expand Up @@ -2261,6 +2264,13 @@ void ForceChange(u32 kDown, Option* currentSetting) {
// Manage toggle for misc hints options
ToggleSet(miscOptions, &MiscHints, &ToTAltarHints, &GanonHints);

if (ChestAppearance.IsNot(CHESTAPPEARANCE_VANILLA)) {
ChestAgony.Unhide();
} else {
ChestAgony.Hide();
ChestAgony.SetSelectedIndex(0);
}

// Only show advanced trap options if random trap damage is set to "Advanced"
if (RandomTrapDmg.Is(RANDOMTRAPS_ADVANCED)) {
FireTrap.Unhide();
Expand Down
1 change: 1 addition & 0 deletions source/settings.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -466,6 +466,7 @@ extern Option Permadeath;
extern Option StartingTime;
extern Option ChestAnimations;
extern Option ChestAppearance;
extern Option ChestAgony;
extern Option GenerateSpoilerLog;
extern Option IngameSpoilers;
extern Option MenuOpeningButton;
Expand Down