Skip to content

Commit

Permalink
Bring in rough chest content matching for future purposes.
Browse files Browse the repository at this point in the history
  • Loading branch information
PhlexPlexico committed Feb 16, 2024
1 parent b689f62 commit 7268f7f
Show file tree
Hide file tree
Showing 9 changed files with 186 additions and 14 deletions.
12 changes: 6 additions & 6 deletions code/include/game/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,14 @@ namespace game::act {

// Name courtesy of the OoT decomp project.
struct DynaPolyActor : Actor {
u32 dyna_poly_id;
float field_1FC;
u32 bg_id;
float push_force;
float field_200;
u16 field_204;
u8 field_206;
u32 dyna_poly_flags;
s16 y_rotation;
u32 transform_flags;
u8 interact_flags;
};
static_assert(sizeof(DynaPolyActor) == 0x20C);
static_assert(sizeof(DynaPolyActor) == 0x210);

struct DayTimerActor {
Actor common_actor;
Expand Down
55 changes: 55 additions & 0 deletions code/include/game/actors/chest.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
#ifndef _GAME_ACTORS_CHEST_H
#define _GAME_ACTORS_CHEST_H

#include "game/actor.h"
#include "game/as.h"
#include "game/collision.h"
#include "game/skelanime.h"
#include "rnd/item_override.h"

namespace game::actors {
enum class EnBoxType : u8 {
ENBOX_TYPE_BIG = 0, // E.g. Hookshot Chest
ENBOX_TYPE_BIG_ROOM_CLEAR = 1,
ENBOX_TYPE_BIG_ORNATE = 2, // E.g. Boss Key Chests
ENBOX_TYPE_BIG_SWITCH_FLAG_FALL = 3,
ENBOX_TYPE_BIG_INVISIBLE = 4,
ENBOX_TYPE_SMALL = 5,
ENBOX_TYPE_SMALL_INVISIBLE = 6,
ENBOX_TYPE_SMALL_ROOM_CLEAR = 7,
ENBOX_TYPE_SMALL_SWITCH_FLAG_FALL = 8,
ENBOX_TYPE_BIG_SONG_ZELDAS_LULLABY = 9,
ENBOX_TYPE_BIG_SONG_SUNS = 10,
ENBOX_TYPE_BIG_SWITCH_FLAG = 11,
ENBOX_TYPE_SMALL_SWITCH_FLAG = 12
};

struct En_Box {
game::act::DynaPolyActor dyna;
SkelAnime* skel_anime;
u8 gap_210[52];
CollisionInfoCylinder* collision_cylinder;
u8 gap_248[84];
int field_29C;
u8 gap_2A0[8];
void* some_fn;
u8 gap_2AC[312];
u16 some_item_check;
u8 movement_flags;
u8 alpha;
u8 switch_flag;
EnBoxType chest_type;
u8 iceSmokeTImer;
s8 field_3EB;
u8 gap_3EC[16];
void* field_3fc;
u8 gap_400[16];
game::act::Actor* field_410;
int csId2;
rnd::GetItemID GetItemID;
s32 collectableFlag;
u8 gap_420[8];
};
} // namespace game::actors

#endif
39 changes: 39 additions & 0 deletions code/include/game/skelanime.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#ifndef _GAME_SKELANIME_H
#define _GAME_SKELANIME_H

#include "common/types.h"
#include "game/context.h"
#include "z3d/z3DVec.h"

namespace game {

struct SkelAnime {
u8 limb_count;
u8 mode;
u8 d_list_count;
s8 taper;
void** skeleton; /* An array of pointers to limbs. Can be StandardLimb, LodLimb, or SkinLimb. */
void* animation; /* Can be an AnimationHeader or PlayerAnimationHeader. */
float start_frame;
float end_frame;
float animation_length;
float cur_frame;
float play_speed;
z3dVec3s* joint_table;
z3dVec3s* morph_table;
float morph_weight;
float morph_rate;
union {
s32 (*normal)(struct SkelAnime*); // Can be Loop, Partial loop, Play once, Morph, or Tapered morph
s32 (*player)(struct game::GlobalContext*, struct SkelAnime*); // Loop, Play once, and Morph
} update;
s8 init_flags;
u8 move_flags;
s16 prev_yaw;
z3dVec3s prev_transl;
z3dVec3s base_transl;
};

} // namespace game

#endif
21 changes: 15 additions & 6 deletions code/include/rnd/chest.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,16 @@
#define _RND_CHEST_H_

#include "common/advanced_context.h"
#include "game/actors/chest.h"
#include "game/context.h"

#include "rnd/item_override.h"
#include "rnd/settings.h"
#if defined ENABLE_DEBUG || defined DEBUG_PRINT
#include "common/debug.h"
extern "C" {
#include <3ds/svc.h>
}
#endif
namespace rnd {
enum class ChestSize : u8 {
VANILLA_SIZE,
Expand All @@ -22,10 +30,11 @@ namespace rnd {
DECORATED_SMALL,
};

void EnBox_rInit(game::act::Actor* thisx, game::GlobalContext* globalCtx);
void EnBox_rUpdate(game::act::Actor* thisx, game::GlobalContext* globalCtx);
u8 Chest_OverrideAnimation();
u8 Chest_OverrideDecoration();
u8 Chest_OverrideIceSmoke(game::act::Actor* thisx);
extern "C" game::actors::EnBoxType Chest_OverrideTexture(game::actors::En_Box*, game::GlobalContext*, s16);
// void EnBox_rInit(game::act::Actor* thisx, game::GlobalContext* globalCtx);
// void EnBox_rUpdate(game::act::Actor* thisx, game::GlobalContext* globalCtx);
// u8 Chest_OverrideAnimation();
// u8 Chest_OverrideDecoration();
// u8 Chest_OverrideIceSmoke(game::act::Actor* thisx);
} // namespace rnd
#endif //_CHEST_H_
4 changes: 4 additions & 0 deletions code/mm.ld
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,10 @@ SECTIONS{
*(.patch_IceArrowsAnywhere)
}

.patch_changeChestTypeToMatchContents 0x31cad4 : {
*(.patch_changeChestTypeToMatchContents)
}

.patch_RemoveZoraMaskCheckMikau 0x32BBB8 : {
*(.patch_RemoveZoraMaskCheckMikau)
}
Expand Down
20 changes: 20 additions & 0 deletions code/source/asm/hooks.s
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,26 @@ hook_OwlExtDataSave:
cpy r6,r0
b 0x317008

.global hook_changeChestTypeToMatchContents
hook_changeChestTypeToMatchContents:
push {r0-r2, lr}
cpy r0, r4
cpy r1, r5
ldrh r2,[r4,#0x1C]
lsl r2, r2, #0x14
lsr r2,r2, #0x19
bl Chest_OverrideTexture
cmp r0,#0xFF
beq doNotOverrideChestType
strb r0,[r4,#0x3e9]
pop {r0-r2, lr}
bx lr
doNotOverrideChestType:
pop {r0-r2, lr}
strb r2,[r4,#0x3e9]
bx lr


.global hook_MikauRewardCheck
hook_MikauRewardCheck:
push {r0-r12, lr}
Expand Down
6 changes: 6 additions & 0 deletions code/source/asm/patches.s
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,12 @@ patch_SaveExtDataOnOwl:
patch_IceArrowsAnywhere:
nop

.section .patch_changeChestTypeToMatchContents
.global patch_changeChestTypeToMatchContents
patch_changeChestTypeToMatchContents:
bl hook_changeChestTypeToMatchContents
@mov r2, #0x02

.section .patch_RemoveZoraMaskCheckMikau
.global patch_RemoveZoraMaskCheckMikau
patch_RemoveZoraMaskCheckMikau:
Expand Down
39 changes: 39 additions & 0 deletions code/source/rnd/chest.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
#include "rnd/chest.h"
#include "rnd/item_table.h"

namespace rnd {
extern "C" {
game::actors::EnBoxType Chest_OverrideTexture(game::actors::En_Box* actor, game::GlobalContext* gctx, s16 gid) {
// First check to see if setting is enabled.
// TODO: Create setting
if (gSettingsContext.chestSize == 0) {
return (game::actors::EnBoxType)0xFF;
}
game::SceneId scene = gctx->scene;
ItemOverride override = ItemOverride_Lookup((game::act::Actor*)&actor->dyna, (u16)scene, gid);
if (override.key.all != 0 &&) {
ItemRow* itemToBeGiven = ItemTable_GetItemRow(override.value.getItemId);
if (actor->chest_type == game::actors::EnBoxType::ENBOX_TYPE_SMALL ||
actor->chest_type == game::actors::EnBoxType::ENBOX_TYPE_BIG ||
actor->chest_type == game::actors::EnBoxType::ENBOX_TYPE_BIG_ORNATE) {
if (itemToBeGiven->baseItemId == 0x02)
return game::actors::EnBoxType::ENBOX_TYPE_SMALL;
else if (itemToBeGiven->baseItemId == 0x2B)
return game::actors::EnBoxType::ENBOX_TYPE_BIG;
else if (itemToBeGiven->baseItemId == 0x78)
return game::actors::EnBoxType::ENBOX_TYPE_BIG_ORNATE;
} else if (actor->chest_type == game::actors::EnBoxType::ENBOX_TYPE_BIG_INVISIBLE ||
actor->chest_type == game::actors::EnBoxType::ENBOX_TYPE_SMALL_INVISIBLE) {
if (itemToBeGiven->baseItemId == 0x02)
return game::actors::EnBoxType::ENBOX_TYPE_SMALL_INVISIBLE;
else if (itemToBeGiven->baseItemId == 0x2B || itemToBeGiven->baseItemId == 0x78)
return game::actors::EnBoxType::ENBOX_TYPE_BIG_INVISIBLE;
}
} else {
return (game::actors::EnBoxType)0xFF;
}
return (game::actors::EnBoxType)0xFF;
}
}

} // namespace rnd
4 changes: 2 additions & 2 deletions code/source/rnd/item_override.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ namespace rnd {
rItemOverrides[0].value.looksLikeItemId = 0x26;
rItemOverrides[1].key.scene = 0x6F;
rItemOverrides[1].key.type = ItemOverride_Type::OVR_COLLECTABLE;
rItemOverrides[1].value.getItemId = 0xB4;
rItemOverrides[1].value.looksLikeItemId = 0xB4;
rItemOverrides[1].value.getItemId = 0x01;
rItemOverrides[1].value.looksLikeItemId = 0x01;
rItemOverrides[2].key.scene = 0x12;
rItemOverrides[2].key.type = ItemOverride_Type::OVR_COLLECTABLE;
rItemOverrides[2].value.getItemId = 0x37;
Expand Down

0 comments on commit 7268f7f

Please sign in to comment.