Skip to content

Commit

Permalink
Merge branch 'HarbourMasters:develop' into develop
Browse files Browse the repository at this point in the history
  • Loading branch information
Quorsor authored Jun 29, 2024
2 parents 45db3a2 + 2e4710c commit 443adc6
Show file tree
Hide file tree
Showing 17 changed files with 129 additions and 34 deletions.
1 change: 0 additions & 1 deletion mm/2s2h/BenGui/BenMenuBar.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
#include "2s2h/Enhancements/Graphics/PlayAsKafei.h"
#include "2s2h/Enhancements/Modes/TimeMovesWhenYouMove.h"
#include "2s2h/DeveloperTools/DeveloperTools.h"
#include "2s2h/DeveloperTools/WarpPoint.h"
#include "2s2h/Enhancements/Cheats/Cheats.h"
#include "2s2h/Enhancements/Player/Player.h"
#include "HudEditor.h"
Expand Down
1 change: 1 addition & 0 deletions mm/2s2h/DeveloperTools/DeveloperTools.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -155,4 +155,5 @@ void InitDeveloperTools() {
RegisterPreventActorUpdateHooks();
RegisterPreventActorDrawHooks();
RegisterPreventActorInitHooks();
RegisterWarpPoint();
}
2 changes: 2 additions & 0 deletions mm/2s2h/DeveloperTools/DeveloperTools.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ void RegisterDebugSaveCreate();
void RegisterPreventActorUpdateHooks();
void RegisterPreventActorDrawHooks();
void RegisterPreventActorInitHooks();
void RegisterWarpPoint();
void RenderWarpPointSection();
void InitDeveloperTools();

#endif // DEVELOPER_TOOLS_H
64 changes: 54 additions & 10 deletions mm/2s2h/DeveloperTools/WarpPoint.cpp
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#include "WarpPoint.h"

#include <libultraship/libultraship.h>
#include "2s2h/BenGui/UIWidgets.hpp"
#include "window/gui/IconsFontAwesome4.h"
#include "2s2h/Enhancements/GameInteractor/GameInteractor.h"

extern "C" {
#include "z64.h"
#include "macros.h"
#include "functions.h"
#include "overlays/gamestates/ovl_select/z_select.h"
extern PlayState* gPlayState;
extern SaveContext gSaveContext;
extern GameState* gGameState;
}

#define CV "gDeveloperTools.WarpPoint."
Expand All @@ -27,6 +28,56 @@ std::unordered_map<s16, const char*> warpPointSceneList = {
#undef DEFINE_SCENE
#undef DEFINE_SCENE_UNSET

void Warp() {
Vec3f pos = { CVarGetFloat(CV "X", 0.0f), CVarGetFloat(CV "Y", 0.0f), CVarGetFloat(CV "Z", 0.0f) };
s32 entrance = CVarGetInteger(CV "Entrance", ENTRANCE(SOUTH_CLOCK_TOWN, 0));

if (gPlayState == NULL) {
// If gPlayState is NULL, it means the the user opted into BootToWarpPoint and the game is starting up. This is
// a hidden cvar for developers, while it is extremely useful for quick testing and debugging, I am not 100%
// confident in it's stability and ability to initialize the game properly in all cases. So for now, I'm going
// to leave it as a hidden cvar. This is incompatible with the SkipToFileSelect enhancement. To enable it open
// the Console and type: `set gDeveloperTools.WarpPoint.BootToWarpPoint 1`
gSaveContext.gameMode = GAMEMODE_NORMAL;
Sram_InitNewSave();
gSaveContext.sceneLayer = 0;
gSaveContext.save.time = CLOCK_TIME(8, 0);
gSaveContext.save.day = 1;
gSaveContext.save.cutsceneIndex = 0;
gSaveContext.save.playerForm = PLAYER_FORM_HUMAN;
gSaveContext.save.linkAge = 0;
gSaveContext.fileNum = 0xFF;
MapSelect_LoadGame((MapSelectState*)gGameState, CVarGetInteger(CV "Entrance", 0), 0);
} else {
// The else case, and the rest of this function is primarly relevant code copied from Play_SetRespawnData and
// func_80169EFC, minus the parts that copy scene flags to scene we are warping to (this is obviously
// undesireable)
gPlayState->nextEntrance = Entrance_Create(entrance >> 9, 0, entrance & 0xF);
gPlayState->transitionTrigger = TRANS_TRIGGER_START;
gPlayState->transitionType = TRANS_TYPE_INSTANT;
}
gSaveContext.respawn[RESPAWN_MODE_DOWN].entrance = Entrance_Create(entrance >> 9, 0, entrance & 0xF);
gSaveContext.respawn[RESPAWN_MODE_DOWN].roomIndex = CVarGetInteger(CV "Room", 0);
gSaveContext.respawn[RESPAWN_MODE_DOWN].pos = pos;
gSaveContext.respawn[RESPAWN_MODE_DOWN].yaw = CVarGetFloat(CV "Rotation", 0.0f);
gSaveContext.respawn[RESPAWN_MODE_DOWN].playerParams = PLAYER_PARAMS(0xFF, PLAYER_INITMODE_D);
gSaveContext.nextTransitionType = TRANS_TYPE_FADE_BLACK_FAST;
gSaveContext.respawnFlag = -8;
}

void RegisterWarpPoint() {
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnConsoleLogoUpdate>([]() {
if (!CVarGetInteger("gEnhancements.Cutscenes.SkipToFileSelect", 0) && CVarGetInteger(CV "BootToWarpPoint", 0) &&
CVarGetInteger(CV "Saved", 0)) {
// Normally called on console logo screen
gSaveContext.seqId = (u8)NA_BGM_DISABLED;
gSaveContext.ambienceId = AMBIENCE_ID_DISABLED;
gSaveContext.gameMode = GAMEMODE_TITLE_SCREEN;
Warp();
}
});
}

void RenderWarpPointSection() {
if (gPlayState == NULL)
return;
Expand Down Expand Up @@ -60,14 +111,7 @@ void RenderWarpPointSection() {
}
ImGui::SameLine();
if (UIWidgets::Button("Warp", { .size = UIWidgets::Sizes::Inline })) {
Vec3f pos = { CVarGetFloat(CV "X", 0.0f), CVarGetFloat(CV "Y", 0.0f), CVarGetFloat(CV "Z", 0.0f) };

Play_SetRespawnData(&gPlayState->state, RESPAWN_MODE_DOWN,
CVarGetInteger(CV "Entrance", ENTRANCE(SOUTH_CLOCK_TOWN, 0)),
CVarGetInteger(CV "Room", 0), PLAYER_PARAMS(0xFF, PLAYER_INITMODE_D), &pos,
CVarGetFloat(CV "Rotation", 0.0f));
func_80169EFC(&gPlayState->state);
gSaveContext.respawnFlag = -8;
Warp();
}
}
}
6 changes: 0 additions & 6 deletions mm/2s2h/DeveloperTools/WarpPoint.h

This file was deleted.

1 change: 1 addition & 0 deletions mm/2s2h/Enhancements/Cutscenes/Cutscenes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,5 @@ void RegisterCutscenes() {
RegisterHideTitleCards();
RegisterSkipEntranceCutscenes();
RegisterSkipIntroSequence();
RegisterSkipToFileSelect();
}
1 change: 1 addition & 0 deletions mm/2s2h/Enhancements/Cutscenes/Cutscenes.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,5 +14,6 @@ void RegisterSkipClockTowerOpen();
void RegisterHideTitleCards();
void RegisterSkipEntranceCutscenes();
void RegisterSkipIntroSequence();
void RegisterSkipToFileSelect();

#endif // CUTSCENES_H
33 changes: 33 additions & 0 deletions mm/2s2h/Enhancements/Cutscenes/SkipToFileSelect.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include <libultraship/bridge.h>
#include "Enhancements/GameInteractor/GameInteractor.h"

extern "C" {
#include "z64.h"
#include "z64game.h"
#include "overlays/gamestates/ovl_file_choose/z_file_select.h"
#include "overlays/gamestates/ovl_title/z_title.h"
extern SaveContext gSaveContext;
extern GameState* gGameState;
}

void RegisterSkipToFileSelect() {
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnConsoleLogoUpdate>([]() {
if (CVarGetInteger("gEnhancements.Cutscenes.SkipToFileSelect", 0)) {
ConsoleLogoState* consoleLogoState = (ConsoleLogoState*)gGameState;

// Wait for the console logo to fade out
if (consoleLogoState->exit) {
// Normally the PRNG seed is set at least once from the title opening running Play_Init
// We need to call it manually before file select creates RNG values for new saves
Rand_Seed(osGetTime());
// Normally called on console logo screen
gSaveContext.seqId = (u8)NA_BGM_DISABLED;
gSaveContext.ambienceId = AMBIENCE_ID_DISABLED;
gSaveContext.gameMode = GAMEMODE_TITLE_SCREEN;

STOP_GAMESTATE(gGameState);
SET_NEXT_GAMESTATE(gGameState, FileSelect_Init, sizeof(FileSelectState));
}
}
});
}
4 changes: 4 additions & 0 deletions mm/2s2h/Enhancements/GameInteractor/GameInteractor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@ void GameInteractor_ExecuteOnGameStateUpdate() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnGameStateUpdate>();
}

void GameInteractor_ExecuteOnConsoleLogoUpdate() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnConsoleLogoUpdate>();
}

void GameInteractor_ExecuteOnKaleidoUpdate(PauseContext* pauseCtx) {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnKaleidoUpdate>(pauseCtx);
}
Expand Down
2 changes: 2 additions & 0 deletions mm/2s2h/Enhancements/GameInteractor/GameInteractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -258,6 +258,7 @@ class GameInteractor {
DEFINE_HOOK(OnGameStateMainFinish, ());
DEFINE_HOOK(OnGameStateDrawFinish, ());
DEFINE_HOOK(OnGameStateUpdate, ());
DEFINE_HOOK(OnConsoleLogoUpdate, ());
DEFINE_HOOK(OnKaleidoUpdate, (PauseContext * pauseCtx));
DEFINE_HOOK(OnSaveInit, (s16 fileNum));
DEFINE_HOOK(BeforeEndOfCycleSave, ());
Expand Down Expand Up @@ -301,6 +302,7 @@ extern "C" {
void GameInteractor_ExecuteOnGameStateMainFinish();
void GameInteractor_ExecuteOnGameStateDrawFinish();
void GameInteractor_ExecuteOnGameStateUpdate();
void GameInteractor_ExecuteOnConsoleLogoUpdate();
void GameInteractor_ExecuteOnKaleidoUpdate(PauseContext* pauseCtx);
void GameInteractor_ExecuteOnSaveInit(s16 fileNum);
void GameInteractor_ExecuteBeforeEndOfCycleSave();
Expand Down
1 change: 1 addition & 0 deletions mm/include/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -1765,6 +1765,7 @@ extern u16 D_0F000000[];

// #region 2S2H [General]
extern PlayState* gPlayState;
extern GameState* gGameState;
// #endregion

#ifdef __cplusplus
Expand Down
6 changes: 6 additions & 0 deletions mm/src/code/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,10 @@ VisZbuf sGameVisZbuf;
VisMono sGameVisMono;
ViMode sGameViMode;

// #region 2S2H [General] Making gGameState available
GameState* gGameState;
// #endregion

void GameState_UpdateFramerateDivisors(s32 divisor) {
gFramerateDivisor = divisor;
gFramerateDivisorF = divisor;
Expand Down Expand Up @@ -205,6 +209,7 @@ void GameState_Realloc(GameState* gameState, size_t size) {
}

void GameState_Init(GameState* gameState, GameStateFunc init, GraphicsContext* gfxCtx) {
gGameState = gameState;
gameState->gfxCtx = gfxCtx;
gameState->frames = 0;
gameState->main = NULL;
Expand Down Expand Up @@ -256,6 +261,7 @@ void GameState_Destroy(GameState* gameState) {
ViMode_Destroy(&sGameViMode);
THA_Destroy(&gameState->tha);
GameAlloc_Cleanup(&gameState->alloc);
gGameState = NULL;
}

GameStateFunc GameState_GetInit(GameState* gameState) {
Expand Down
6 changes: 5 additions & 1 deletion mm/src/overlays/actors/ovl_En_Bombers/z_en_bombers.c
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,11 @@ void func_80C039A8(EnBombers* this, PlayState* play) {
this->actor.textId = 0x744;
}
break;

// #region 2S2H - Enhancements. Fierce Deity gets same dialog as Human without notebook
case PLAYER_FORM_FIERCE_DEITY:
this->actor.textId = 0x73D;
break;
// #endregion
default:
break;
}
Expand Down
6 changes: 6 additions & 0 deletions mm/src/overlays/actors/ovl_En_Bombers2/z_en_bombers2.c
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ void func_80C04BA0(EnBombers2* this, PlayState* play) {
player = GET_PLAYER(play);

switch (player->transformation) {
// #region 2S2H - Enhancements. Fierce Deity gets same dialog as Goron and Zora
case PLAYER_FORM_FIERCE_DEITY:
// #endregion
case PLAYER_FORM_GORON:
case PLAYER_FORM_ZORA:
this->textIdIndex = 1;
Expand Down Expand Up @@ -233,6 +236,9 @@ void func_80C04D8C(EnBombers2* this, PlayState* play) {
this->unk_28E = -0xFA0;
break;

// #region 2S2H - Enhancements. Fierce Deity.
case PLAYER_FORM_FIERCE_DEITY:
// #endregion
case PLAYER_FORM_GORON:
case PLAYER_FORM_ZORA:
this->unk_28E = -0x1770;
Expand Down
14 changes: 8 additions & 6 deletions mm/src/overlays/actors/ovl_En_Bomjima/z_en_bomjima.c
Original file line number Diff line number Diff line change
Expand Up @@ -84,19 +84,19 @@ static ColliderCylinderInit sCylinderInit = {
{ 10, 30, 0, { 0, 0, 0 } },
};

u16 D_80C00A44[] = { 0x719, 0x71A, 0x71B, 0x708 };
u16 D_80C00A44[] = { 0x719, 0x71A, 0x71B, 0x708 }; // text IDs before popping balloon

u16 D_80C00A4C[] = { 0x739, 0x73A, 0x73B, 0x000 };
u16 D_80C00A4C[] = { 0x739, 0x73A, 0x73B, 0x000 }; // text IDs after popping balloon

u16 D_80C00A54[] = {
0x739, 0x73A, 0x73B, 0x714, 0x709, 0x70A, 0x70B, 0x70C, 0x70D, 0x70E, 0x70F, 0x712, 0x713,
};
}; // text IDs for Deku after popping balloon

u16 D_80C00A70[] = {
0x739, 0x73A, 0x73B, 0x759, 0x753, 0x754, 0x755, 0x756, 0x70D, 0x757, 0x758, 0x712, 0x713,
};
}; // text IDs for Human after popping balloon

u16 D_80C00A8C[] = { 0x736, 0x737, 0x738, 0x74E };
u16 D_80C00A8C[] = { 0x736, 0x737, 0x738, 0x74E }; // text IDs after hide and seek

typedef enum {
/* -1 */ ENBOMJIMA_ANIM_NONE = -1,
Expand Down Expand Up @@ -225,9 +225,11 @@ void func_80BFE32C(EnBomjima* this, PlayState* play, s32 arg2) {
if (player->transformation == PLAYER_FORM_GORON) {
this->unk_2C8 = 1;
}
if (player->transformation == PLAYER_FORM_ZORA) {
// #region 2S2H - Enhancements. Fierce Deity gets same dialog as Zora
if (player->transformation == PLAYER_FORM_ZORA || player->transformation == PLAYER_FORM_FIERCE_DEITY) {
this->unk_2C8 = 2;
}
// #endregion

switch (this->unk_2CA) {
case 0:
Expand Down
2 changes: 1 addition & 1 deletion mm/src/overlays/actors/ovl_En_Bomjima/z_en_bomjima.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ typedef struct EnBomjima {
/* 0x2C2 */ s16 unk_2C2;
/* 0x2C4 */ s16 cutsceneTimer;
/* 0x2C6 */ s16 unk_2C6;
/* 0x2C8 */ s16 unk_2C8;
/* 0x2C8 */ s16 unk_2C8; //index into arrays of textIDs
/* 0x2CA */ s16 unk_2CA;
/* 0x2CC */ f32 animEndFrame;
/* 0x2D0 */ f32 unk_2D0;
Expand Down
13 changes: 4 additions & 9 deletions mm/src/overlays/gamestates/ovl_title/z_title.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
#include "overlays/gamestates/ovl_opening/z_opening.h"
#include "misc/nintendo_rogo_static/nintendo_rogo_static.h"

#include "overlays/gamestates/ovl_file_choose/z_file_select.h"
#include "build.h"
#include "BenPort.h"
#include "2s2h/Enhancements/GameInteractor/GameInteractor.h"
#include <stdlib.h>

#define dgShipLogoDL "__OTR__misc/nintendo_rogo_static/gShipLogoDL"
Expand Down Expand Up @@ -200,16 +200,11 @@ void ConsoleLogo_Main(GameState* thisx) {
gSaveContext.gameMode = GAMEMODE_TITLE_SCREEN;

STOP_GAMESTATE(&this->state);
if (CVarGetInteger("gEnhancements.Cutscenes.SkipToFileSelect", 0)) {
// Normally the PRNG seed is set at least once from the title opening running Play_Init
// We need to call it manually before file select creates RNG values for new saves
Rand_Seed(osGetTime());
SET_NEXT_GAMESTATE(&this->state, FileSelect_Init, sizeof(FileSelectState));
} else {
SET_NEXT_GAMESTATE(&this->state, TitleSetup_Init, sizeof(TitleSetupState));
}
SET_NEXT_GAMESTATE(&this->state, TitleSetup_Init, sizeof(TitleSetupState));
}

GameInteractor_ExecuteOnConsoleLogoUpdate();

CLOSE_DISPS(this->state.gfxCtx);
}

Expand Down

0 comments on commit 443adc6

Please sign in to comment.