Skip to content

Commit

Permalink
rst: Move custom camera logic out of game/
Browse files Browse the repository at this point in the history
rst: Move custom message logic out of game/

Remove more extern "C"

game: Fix GlobalContext pause flag definition

New field definitions in player.h and actor.h.

Some have a few explanations as to what they really mean as well.

Update boss lines to ztarget_pos

Update common_data.h and main.cpp (leoetlino#174)

* Update common_data.h and main.cpp

Some more decomp'd things like the RespawnData.

Increased assert size due to the fact that sub13s[8]  contains respawn data.

Created RespawnData struct.

Found some BitFields that indicate counters for items.

Found bitfiled for sword and shield.

Include enums for sword and shield.

* Keep naming convention.

* Remove extra value in sub13s.

Update raw to u32.

Collect Register didn't change in main?

* Remove old BitField.

Update more structs in player.h and common_data.h (leoetlino#176)

* Update common_data.h and main.cpp

Some more decomp'd things like the RespawnData.

Increased assert size due to the fact that sub13s[8]  contains respawn data.

Created RespawnData struct.

Found some BitFields that indicate counters for items.

Found bitfiled for sword and shield.

Include enums for sword and shield.

* Keep naming convention.

* Remove extra value in sub13s.

Update raw to u32.

Collect Register didn't change in main?

* Remove old BitField.

* Update inventory registers.

* Include more common_data changes.

Include player changes.

game: Add memory allocator structures

game: Update player struct to add PlayerUtils

Update common_data.h and main.cpp

Some more decomp'd things like the RespawnData.

Increased assert size due to the fact that sub13s[8]  contains respawn data.

Created RespawnData struct.

Found some BitFields that indicate counters for items.

Found bitfiled for sword and shield.

Include enums for sword and shield.

Keep naming convention.

Remove extra value in sub13s.

Update raw to u32.

Collect Register didn't change in main?

Remove old BitField.

Update inventory registers.

Include more common_data changes.

Include player changes.

Update common_data struct.

Include rupee accumulator  and bottle contents array.

Change casing.

Update Common Data (leoetlino#187)

Implement ISG (leoetlino#188)

I saw this feature being asked for by a few people. Since it shouldn't directly interfere with gameplay, unless specifically activated (pickup item while shielding and swinging). I've checked both on patched and non-patched versions of the game to see if this implementation works, and they both had the same expected behaviour (8 slashes with kokiri sword to kill Gibdos). It appears that this implementation should not impact any regular game play.
  • Loading branch information
leoetlino authored and PhlexPlexico committed Aug 4, 2021
1 parent b3b57da commit 436e09b
Show file tree
Hide file tree
Showing 27 changed files with 464 additions and 174 deletions.
8 changes: 4 additions & 4 deletions hooks/main.hks
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,18 @@ message_get_hook:
type: branch
link: false
addr: 0x1BDE78
func: rst_MessageDataGet
func: rst::MessageDataGet(game::MessageData*, unsigned short, game::Message*)

# Input
pad_update_hook:
type: softbranch
opcode: post
func: rst_UpdatePadState
func: rst::UpdatePadState()
addr: 0x116A30
pad_update_hook:
type: softbranch
opcode: post
func: rst_UpdatePadStateForOcarina
func: rst::UpdatePadStateForOcarina()
addr: 0x116900
decouple_trigger_btns:
type: patch
Expand All @@ -67,7 +67,7 @@ trigger_item_use_hook:
type: softbranch
opcode: post
addr: 0x1DB744
func: rst_TriggerItemUseHook
func: rst::link::TriggerItemUseHook()

# UI menu triggers
ui_schedule_trigger_hook:
Expand Down
2 changes: 1 addition & 1 deletion hooks/rst_boss_odolwa.hks
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ boss_odolwa_collision_hook:
type: branch
link: true
addr: 0x29E5E4
func: rst_OdolwaHandleRegularCollision
func: rst::OdolwaHandleRegularCollision(game::act::BossOdolwa*)
boss_odolwa_no_crippling_weakness_to_deku_nuts:
type: patch
addr: 0x65e52c
Expand Down
12 changes: 12 additions & 0 deletions hooks/rst_isg.hks
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Relative branch to skip past sword flags.
# b #0x00000c
patch_in_isg:
type: patch
addr: 0x1D32E0
data: 010000EA

# b #0x00000c
patch_in_isg_2:
type: patch
addr: 0x1DBEA4
data: 010000EA
2 changes: 1 addition & 1 deletion hooks/rst_player.hks
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
player_get_arrow_info:
type: branch
link: false
func: rst_PlayerGetArrowInfo
func: game::act::PlayerGetArrowInfo(game::GlobalContext*, game::act::Player*, game::ItemId*, int*)
addr: 0x22F7B0

# State handlers
Expand Down
2 changes: 1 addition & 1 deletion hooks/rst_time.hks
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
update_time_hook:
type: softbranch
opcode: pre
func: rst_UpdateTimeHook
func: rst::UpdateTimeHook()
addr: 0x172A64

move_scheduled_npc_hook:
Expand Down
5 changes: 5 additions & 0 deletions source/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ add_executable(newcode
game/context.h
game/items.cpp
game/items.h
game/memory.cpp
game/memory.h
game/message.cpp
game/message.h
game/pad.cpp
Expand Down Expand Up @@ -67,6 +69,8 @@ add_executable(newcode
game/ui/screens/main_screen.h
game/ui/screens/schedule_screen.h
game/ui/screens/screen.h
rst/camera.cpp
rst/camera.h
rst/fixes/boss.cpp
rst/fixes/boss.h
rst/fixes/boss.s
Expand All @@ -79,6 +83,7 @@ add_executable(newcode
rst/link.cpp
rst/link.h
rst/main.cpp
rst/message.cpp
rst/trampolines.s
)
set_target_properties(newcode PROPERTIES SUFFIX ".elf")
Expand Down
4 changes: 4 additions & 0 deletions source/common/flags.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,10 @@ namespace rst {
template <typename FlagType, typename = typename std::enable_if_t<std::is_enum_v<FlagType>, void>>
class Flags {
public:
constexpr auto& operator=(FlagType v) {
flags = std::underlying_type_t<FlagType>(v);
return *this;
}
constexpr void Set(FlagType v) { flags |= std::underlying_type_t<FlagType>(v); }
constexpr void Clear(FlagType v) { flags &= ~std::underlying_type_t<FlagType>(v); }

Expand Down
13 changes: 8 additions & 5 deletions source/game/actor.h
Original file line number Diff line number Diff line change
Expand Up @@ -154,27 +154,30 @@ struct Actor {
u16 field_22;
PosRot pos;
u8 gap_38[4];
PosRot target_pos;
PosRot ztarget_pos;
sound::EffectId sound_effect;
u8 gap_54[4];
Vec3 model_scale;
Vec3 vel;
float vel_xz;
float field_74;
// Modifying this value causes link to moonjump/levitate.
float vel_y;
u8 gap_78[8];
u32 field_80;
u8 gap_84;
u8 field_85;
u8 gap86[3];
u8 gap_89[3];
float field_8C;
// Distance to water/submerged? After -30.99 it goes to -32000.00
float dist_to_water_maybe;
u8 gap_90[4];
rst::Flags<Flag94> flags_94;
float field_98;
float distance_to_link;
float height_diff_to_link;
DamageTable* damage_table;
Vec3 field_A8;
// Changing x and z causes link to slide across plane in direction.
Vec3 target_pos_maybe;
u32 field_B4;
u16 field_B8;
u8 field_BA;
Expand All @@ -195,7 +198,7 @@ struct Actor {
Vec3 field_F0;
u32 field_FC;
Vec3 field_100;
Vec3 field_10C;
Vec3 actor_coords;
u8 field_118;
u8 gap119;
u16 text_id_maybe;
Expand Down
57 changes: 0 additions & 57 deletions source/game/camera.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,62 +12,5 @@ u32 Camera::ChangeMode(CameraMode mode, u32 unknown) {
return rst::util::GetPointer<u32(Camera*, CameraMode, u32)>(0x18B31C)(this, mode, unknown);
}

static bool IsMovingCStick(const pad::State& state) {
return (state.c_stick.x_raw_last * state.c_stick.x_raw_last +
state.c_stick.y_raw_last * state.c_stick.y_raw_last) >= 5.198f;
}

void CalcCamera() {
// Add an extra free cam switch trigger for the ocarina
auto* states = rst::util::GetPointer<CameraStateInfo>(0x667894);
auto& ocarina_state = states[size_t(CameraState::ITEM1)];

static bool s_initialised = false;
if (!s_initialised) {
auto& free_cam_mode = (*ocarina_state.modes)[size_t(CameraMode::FREECAMERA)];
free_cam_mode.handler_fn_idx = 0x3D;
free_cam_mode.field_2 = 2;
free_cam_mode.field_4 = 0x6645C8;
s_initialised = true;
}

auto* gctx = rst::GetContext().gctx;
auto* camera = &gctx->main_camera + gctx->camera_idx;
const bool using_ocarina = gctx->camera_idx == 1 && camera->state == CameraState::ITEM1;
if (using_ocarina) {
// Only enable free camera mode when needed to ensure that the camera goes into
// mode NORMAL when starting to play the ocarina.
ocarina_state.allowed_modes.Set(CameraMode::FREECAMERA);
if (camera->mode == CameraMode::NORMAL && IsMovingCStick(gctx->pad_state))
camera->ChangeMode(CameraMode::FREECAMERA);
} else {
ocarina_state.allowed_modes.Clear(CameraMode::FREECAMERA);
}
}

} // namespace game

extern "C" {
using namespace game;
RST_HOOK bool rst_ShouldSwitchToFreeCam(Camera* self, CameraMode mode, u32) {
constexpr CameraMode extra_freecam_modes[] = {
CameraMode::FREECAMERA,
CameraMode::TALK,
CameraMode::KEEPON,
CameraMode::PARALLEL,
};
if (!rst::util::Contains(extra_freecam_modes, mode))
return false;

// Keep free camera mode.
// ...but not if the player wants to reset the camera.
const pad::State& state = rst::GetContext().gctx->pad_state;
if (state.input.new_buttons.IsSet(pad::Button::L))
return false;
if (self->mode == CameraMode::FREECAMERA)
return true;

// Otherwise, enter free camera mode only if the C stick is moved.
return IsMovingCStick(state);
}
}
2 changes: 0 additions & 2 deletions source/game/camera.h
Original file line number Diff line number Diff line change
Expand Up @@ -291,6 +291,4 @@ struct CameraStateInfo {
};
static_assert(sizeof(CameraStateInfo) == 0xc);

void CalcCamera();

} // namespace game
Loading

0 comments on commit 436e09b

Please sign in to comment.