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

[Mod] Hyrule Warriors-style Link #665

Open
wants to merge 19 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 5 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
9 changes: 9 additions & 0 deletions mm/2s2h/BenGui/BenMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "2s2h/Enhancements/Enhancements.h"
#include "2s2h/Enhancements/Graphics/MotionBlur.h"
#include "2s2h/Enhancements/Graphics/PlayAsKafei.h"
#include "2s2h/Enhancements/Graphics/HWStyledLink.h"
#include "2s2h/Enhancements/Modes/TimeMovesWhenYouMove.h"
#include "2s2h/DeveloperTools/DeveloperTools.h"
#include "2s2h/DeveloperTools/WarpPoint.h"
Expand Down Expand Up @@ -574,6 +575,11 @@ void DrawEnhancementsMenu() {
UIWidgets::CVarCheckbox("Fierce Deity's Mask Anywhere", "gEnhancements.Masks.FierceDeitysAnywhere",
{ .tooltip = "Allow using Fierce Deity's mask outside of boss rooms." });
UIWidgets::CVarCheckbox("No Blast Mask Cooldown", "gEnhancements.Masks.NoBlastMaskCooldown", {});
if (UIWidgets::CVarCheckbox("Persistent Bunny Hood", "gEnhancements.Masks.PersistentBunnyHood.Enabled",
{ .tooltip = "Permanantly toggle a speed boost from the bunny hood by pressing "
"'A' on it in the mask menu." })) {
UpdatePersistentMasksState();
}

ImGui::EndMenu();
}
Expand All @@ -588,6 +594,9 @@ void DrawEnhancementsMenu() {
if (UIWidgets::BeginMenu("Modes")) {
UIWidgets::CVarCheckbox("Play As Kafei", "gModes.PlayAsKafei",
{ .tooltip = "Requires scene reload to take effect." });
UIWidgets::CVarCheckbox("Hyrule Warriors Young Link", "gModes.HWStyledLink",
{ .tooltip = "When acquired, places the Keaton and Fierce Deity masks on Link "
"similarly to how he wears them in Hyrule Warriors" });
if (UIWidgets::CVarCheckbox("Time Moves When You Move", "gModes.TimeMovesWhenYouMove")) {
RegisterTimeMovesWhenYouMove();
}
Expand Down
2 changes: 2 additions & 0 deletions mm/2s2h/Enhancements/Enhancements.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,14 @@ void InitEnhancements() {

// Graphics
RegisterDisableBlackBars();
RegisterHWStyledLink();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be easier to understand what this is doing if we write it out in full

Suggested change
RegisterHWStyledLink();
RegisterHyruleWarriorsStyledLink();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh yeah, absolutely, just old habits still sticking around haha


// Masks
RegisterFastTransformation();
RegisterFierceDeityAnywhere();
RegisterBlastMaskKeg();
RegisterNoBlastMaskCooldown();
RegisterPersistentMasks();

// Minigames
RegisterAlwaysWinDoggyRace();
Expand Down
2 changes: 2 additions & 0 deletions mm/2s2h/Enhancements/Enhancements.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include "Masks/FierceDeityAnywhere.h"
#include "Masks/NoBlastMaskCooldown.h"
#include "Masks/FastTransformation.h"
#include "Masks/PersistentMasks.h"
#include "Minigames/AlwaysWinDoggyRace.h"
#include "Cutscenes/Cutscenes.h"
#include "Restorations/FlipHopVariable.h"
Expand All @@ -29,6 +30,7 @@
#include "Saving/SavingEnhancements.h"
#include "Graphics/DisableBlackBars.h"
#include "Modes/TimeMovesWhenYouMove.h"
#include "Graphics/HWStyledLink.h"

enum AlwaysWinDoggyRaceOptions {
ALWAYS_WIN_DOGGY_RACE_OFF,
Expand Down
17 changes: 17 additions & 0 deletions mm/2s2h/Enhancements/GameInteractor/GameInteractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,17 @@ void GameInteractor_ExecuteOnKaleidoUpdate(PauseContext* pauseCtx) {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnKaleidoUpdate>(pauseCtx);
}

void GameInteractor_ExecuteBeforeKaleidoDrawPage(PauseContext* pauseCtx, u16 pauseIndex) {
GameInteractor::Instance->ExecuteHooks<GameInteractor::BeforeKaleidoDrawPage>(pauseCtx, pauseIndex);
GameInteractor::Instance->ExecuteHooksForID<GameInteractor::BeforeKaleidoDrawPage>(pauseIndex, pauseCtx,
pauseIndex);
}

void GameInteractor_ExecuteAfterKaleidoDrawPage(PauseContext* pauseCtx, u16 pauseIndex) {
GameInteractor::Instance->ExecuteHooks<GameInteractor::AfterKaleidoDrawPage>(pauseCtx, pauseIndex);
GameInteractor::Instance->ExecuteHooksForID<GameInteractor::AfterKaleidoDrawPage>(pauseIndex, pauseCtx, pauseIndex);
}

void GameInteractor_ExecuteOnSaveInit(s16 fileNum) {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnSaveInit>(fileNum);
}
Expand Down Expand Up @@ -112,6 +123,12 @@ void GameInteractor_ExecuteOnActorKill(Actor* actor) {
GameInteractor::Instance->ExecuteHooksForFilter<GameInteractor::OnActorKill>(actor);
}

void GameInteractor_ExecuteOnPlayerPostLimbDraw(Player* player, s32 limbIndex) {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnPlayerPostLimbDraw>(player, limbIndex);
GameInteractor::Instance->ExecuteHooksForID<GameInteractor::OnPlayerPostLimbDraw>(limbIndex, player, limbIndex);
GameInteractor::Instance->ExecuteHooksForFilter<GameInteractor::OnPlayerPostLimbDraw>(player, limbIndex);
}

void GameInteractor_ExecuteOnSceneFlagSet(s16 sceneId, FlagType flagType, u32 flag) {
SPDLOG_DEBUG("OnSceneFlagSet: sceneId: {}, flagType: {}, flag: {}", sceneId, (u32)flagType, flag);
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnSceneFlagSet>(sceneId, flagType, flag);
Expand Down
13 changes: 11 additions & 2 deletions mm/2s2h/Enhancements/GameInteractor/GameInteractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
#include <string>
extern "C" {
#endif
#include "z64actor.h"
#include "z64camera.h"
#include "z64.h"
#ifdef __cplusplus
}
Expand Down Expand Up @@ -48,6 +46,11 @@ typedef enum {
GI_VB_SONG_AVAILABLE_TO_PLAY,
GI_VB_USE_CUSTOM_CAMERA,
GI_VB_DELETE_OWL_SAVE,
GI_VB_CONSIDER_BUNNY_HOOD_EQUIPPED,
GI_VB_USE_ITEM_EQUIP_MASK,
GI_VB_KALEIDO_DISPLAY_ITEM_TEXT,
GI_VB_USE_ITEM_CONSIDER_LINK_HUMAN,
GI_VB_DRAW_ITEM_EQUIPPED_OUTLINE,
GI_VB_PLAY_TRANSITION_CS,
GI_VB_TATL_INTERUPT_MSG3,
GI_VB_TATL_INTERUPT_MSG6,
Expand Down Expand Up @@ -258,6 +261,8 @@ class GameInteractor {
DEFINE_HOOK(OnGameStateDrawFinish, ());
DEFINE_HOOK(OnGameStateUpdate, ());
DEFINE_HOOK(OnKaleidoUpdate, (PauseContext * pauseCtx));
DEFINE_HOOK(BeforeKaleidoDrawPage, (PauseContext * pauseCtx, u16 pauseIndex));
DEFINE_HOOK(AfterKaleidoDrawPage, (PauseContext * pauseCtx, u16 pauseIndex));
DEFINE_HOOK(OnSaveInit, (s16 fileNum));
DEFINE_HOOK(BeforeEndOfCycleSave, ());
DEFINE_HOOK(AfterEndOfCycleSave, ());
Expand All @@ -274,6 +279,7 @@ class GameInteractor {
DEFINE_HOOK(ShouldActorDraw, (Actor * actor, bool* should));
DEFINE_HOOK(OnActorDraw, (Actor * actor));
DEFINE_HOOK(OnActorKill, (Actor * actor));
DEFINE_HOOK(OnPlayerPostLimbDraw, (Player * player, s32 limbIndex));

DEFINE_HOOK(OnSceneFlagSet, (s16 sceneId, FlagType flagType, u32 flag));
DEFINE_HOOK(OnSceneFlagUnset, (s16 sceneId, FlagType flagType, u32 flag));
Expand Down Expand Up @@ -301,6 +307,8 @@ void GameInteractor_ExecuteOnGameStateMainFinish();
void GameInteractor_ExecuteOnGameStateDrawFinish();
void GameInteractor_ExecuteOnGameStateUpdate();
void GameInteractor_ExecuteOnKaleidoUpdate(PauseContext* pauseCtx);
void GameInteractor_ExecuteBeforeKaleidoDrawPage(PauseContext* pauseCtx, u16 pauseIndex);
void GameInteractor_ExecuteAfterKaleidoDrawPage(PauseContext* pauseCtx, u16 pauseIndex);
void GameInteractor_ExecuteOnSaveInit(s16 fileNum);
void GameInteractor_ExecuteBeforeEndOfCycleSave();
void GameInteractor_ExecuteAfterEndOfCycleSave();
Expand All @@ -317,6 +325,7 @@ void GameInteractor_ExecuteOnActorUpdate(Actor* actor);
bool GameInteractor_ShouldActorDraw(Actor* actor);
void GameInteractor_ExecuteOnActorDraw(Actor* actor);
void GameInteractor_ExecuteOnActorKill(Actor* actor);
void GameInteractor_ExecuteOnPlayerPostLimbDraw(Player* player, s32 limbIndex);

void GameInteractor_ExecuteOnSceneFlagSet(s16 sceneId, FlagType flagType, u32 flag);
void GameInteractor_ExecuteOnSceneFlagUnset(s16 sceneId, FlagType flagType, u32 flag);
Expand Down
65 changes: 65 additions & 0 deletions mm/2s2h/Enhancements/Graphics/HWStyledLink.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
#include "HWStyledLink.h"
#include "libultraship/libultraship.h"
#include "2s2h/Enhancements/GameInteractor/GameInteractor.h"
#include "Enhancements/FrameInterpolation/FrameInterpolation.h"

extern "C" {
#include "z64.h"
#include "z64player.h"
#include "functions.h"
#include "macros.h"
#include "src/overlays/kaleido_scope/ovl_kaleido_scope/z_kaleido_scope.h"

extern PlayState* gPlayState;
extern const char* D_801C0B20[28];
extern SaveContext gSaveContext;
#include "objects/object_link_child/object_link_child.h"
void ResourceMgr_PatchGfxByName(const char* path, const char* patchName, int index, Gfx instruction);
void ResourceMgr_UnpatchGfxByName(const char* path, const char* patchName);
}

void UpdateHWStyledLink() {
GameInteractor::Instance->RegisterGameHookForID<GameInteractor::OnPlayerPostLimbDraw>(
PLAYER_LIMB_HEAD, [](Player* player, s32 limbIndex) {
if (CVarGetInteger("gModes.HWStyledLink", 0) && player->currentMask == PLAYER_MASK_NONE &&
player->transformation == PLAYER_FORM_HUMAN && INV_CONTENT(ITEM_MASK_KEATON) == ITEM_MASK_KEATON) {
OPEN_DISPS(gPlayState->state.gfxCtx);
Matrix_Push();
Matrix_RotateYS(14563, MTXMODE_APPLY);
Matrix_RotateZS(-4854, MTXMODE_APPLY);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Matrix_RotateYS and Matrix_RotateZS use 'binangs' (binary angles). Would it be alright to write this as hex?

Alternatively, write it in degrees and use the DEG_TO_BINANG(angle) macro

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

tbh these first values were put in there by Proxy, I'll look into converting them tho

Matrix_Translate(300.0f, -250.0f, 77.7f, MTXMODE_APPLY);
Matrix_Scale(0.648f, 0.648f, 0.648f, MTXMODE_APPLY);
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(gPlayState->state.gfxCtx),
G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gSPDisplayList(POLY_OPA_DISP++, (Gfx*)D_801C0B20[PLAYER_MASK_KEATON - 1]);
Matrix_Pop();
CLOSE_DISPS(gPlayState->state.gfxCtx);
}
});
GameInteractor::Instance->RegisterGameHookForID<GameInteractor::OnPlayerPostLimbDraw>(
PLAYER_LIMB_WAIST, [](Player* player, s32 limbIndex) {
if (CVarGetInteger("gModes.HWStyledLink", 0) && player->transformation == PLAYER_FORM_HUMAN &&
player->itemAction != PLAYER_IA_MASK_FIERCE_DEITY &&
INV_CONTENT(ITEM_MASK_FIERCE_DEITY) == ITEM_MASK_FIERCE_DEITY) {
OPEN_DISPS(gPlayState->state.gfxCtx);
Matrix_Push();
Matrix_RotateXS(-25000, MTXMODE_APPLY);
Matrix_RotateYS(-2000, MTXMODE_APPLY);
Matrix_RotateZS(-15000, MTXMODE_APPLY);
Matrix_Translate(-85.0f, 658.0f, -165.0f, MTXMODE_APPLY);
Matrix_Scale(0.635f, 0.635f, 0.635f, MTXMODE_APPLY);
gSPMatrix(POLY_OPA_DISP++, Matrix_NewMtx(gPlayState->state.gfxCtx),
G_MTX_NOPUSH | G_MTX_LOAD | G_MTX_MODELVIEW);
gSPDisplayList(POLY_OPA_DISP++, (Gfx*)D_801C0B20[PLAYER_MASK_FIERCE_DEITY - 1]);
Matrix_Pop();
CLOSE_DISPS(gPlayState->state.gfxCtx);
}
});
}

void RegisterHWStyledLink() {
UpdateHWStyledLink();

GameInteractor::Instance->RegisterGameHook<GameInteractor::OnSceneInit>(
[](s8 sceneId, s8 spawnNum) { UpdateHWStyledLink(); });
}
7 changes: 7 additions & 0 deletions mm/2s2h/Enhancements/Graphics/HWStyledLink.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#ifndef GRAPHICS_HW_STYLED_LINK
#define GRAPHICS_HW_STYLED_LINK

void RegisterHWStyledLink();
void UpdateHWStyledLink();

#endif // GRAPHICS_HW_STYLED_LINK
Loading