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

SceneDB [WIP Do not merge] #4460

Open
wants to merge 5 commits into
base: develop
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions soh/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ shipofharkinian.ini
imgui.ini
oot.otr
oot_save.sav
build.c

# Tool artifacts
tools/mipspro7.2_compiler/
Expand Down
18 changes: 9 additions & 9 deletions soh/include/regs.h
Original file line number Diff line number Diff line change
Expand Up @@ -102,20 +102,20 @@
#define R_ENV_LIGHT1_DIR(i) cREG(3 + i)
#define R_ENV_LIGHT2_DIR(i) cREG(6 + i)
#define R_B_LABEL_DD WREG(0)
#define R_OW_MINIMAP_X WREG(29)
#define R_OW_MINIMAP_Y WREG(30)
#define R_OW_MINIMAP_X WREG(29) // TODO test removal
#define R_OW_MINIMAP_Y WREG(30) // TODO test removal
#define R_MINIMAP_DISABLED WREG(31)
#define R_B_LABEL_X(i) WREG(40 + i)
#define R_B_LABEL_Y(i) WREG(43 + i)
#define R_DGN_MINIMAP_X WREG(68)
#define R_DGN_MINIMAP_Y WREG(69)
#define R_MAP_INDEX VREG(11)
#define R_MAP_TEX_INDEX_BASE VREG(12)
#define R_MAP_TEX_INDEX VREG(13)
#define R_COMPASS_SCALE_X VREG(14)
#define R_COMPASS_SCALE_Y VREG(15)
#define R_COMPASS_OFFSET_X VREG(16)
#define R_COMPASS_OFFSET_Y VREG(17)
#define R_MAP_INDEX VREG(11) // TODO test removal
#define R_MAP_TEX_INDEX_BASE VREG(12) // TODO test removal
#define R_MAP_TEX_INDEX VREG(13) // TODO test removal
#define R_COMPASS_SCALE_X VREG(14) // TODO test removal
#define R_COMPASS_SCALE_Y VREG(15) // TODO test removal
#define R_COMPASS_OFFSET_X VREG(16) // TODO test removal
#define R_COMPASS_OFFSET_Y VREG(17) // TODO test removal
#define R_MINIMAP_COLOR(i) VREG(18 + i)
#define R_ITEM_AMMO_X(i) VREG(64 + i)
#define R_ITEM_AMMO_Y(i) VREG(68 + i)
Expand Down
3 changes: 0 additions & 3 deletions soh/include/variables.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,6 @@ extern "C"
extern s16 gLinkObjectIds[2];
extern u32 gObjectTableSize;
extern RomFile gObjectTable[OBJECT_ID_MAX];
extern EntranceInfo gEntranceTable[ENTR_MAX];
extern SceneTableEntry gSceneTable[SCENE_ID_MAX];
extern u16 gSramSlotOffsets[];
// 4 16-colors palettes
extern u64 gMojiFontTLUTs[4][4]; // original name: "moji_tlut"
Expand Down Expand Up @@ -201,7 +199,6 @@ extern "C"
extern LightningStrike gLightningStrike;
extern MapData* gMapData;
extern f32 gBossMarkScale;
extern PauseMapMarksData* gLoadedPauseMarkDataTable;
extern s32 gTrnsnUnkState;
extern Color_RGBA8_u32 D_801614B0;
extern PreNmiBuff* gAppNmiBufferPtr;
Expand Down
3 changes: 1 addition & 2 deletions soh/include/z64.h
Original file line number Diff line number Diff line change
Expand Up @@ -792,7 +792,7 @@ typedef struct {
/* 0x0254 */ u16 minimapAlpha;
/* 0x0256 */ s16 startAlpha;
/* 0x0258 */ s16 unk_258;
/* 0x025A */ s16 unk_25A;
/* 0x025A */ s16 unk_25A; // TODO unneeded, just use mapIndex
/* 0x025C */ s16 mapRoomNum;
/* 0x025E */ s16 mapPaletteIndex; // "map_palete_no"
/* 0x0260 */ u8 unk_260;
Expand Down Expand Up @@ -1482,7 +1482,6 @@ typedef struct PlayState {
/* 0x1241C */ TransitionFade transitionFade;
/* 0x12428 */ char unk_12428[0x3];
/* 0x1242B */ u8 unk_1242B;
/* 0x1242C */ SceneTableEntry* loadedScene;
/* 0x12430 */ char unk_12430[0xE8];
// SOH [Custom Models] MTX tracker for flex based skeletons
Mtx** flexLimbOverrideMTX;
Expand Down
6 changes: 3 additions & 3 deletions soh/include/z64save.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ typedef struct {
/* 0x28 */ u16 equipment; // a mask where each nibble corresponds to a type of equipment `EquipmentType`, and each bit to an owned piece `EquipInv*`
/* 0x2C */ u32 upgrades;
/* 0x30 */ u32 questItems;
/* 0x34 */ u8 dungeonItems[20];
/* 0x48 */ s8 dungeonKeys[19];
/* 0x34 */ u8* dungeonItems;
/* 0x48 */ s8* dungeonKeys;
/* 0x5B */ s8 defenseHearts;
/* 0x5C */ s16 gsTokens;
} Inventory; // size = 0x5E
Expand Down Expand Up @@ -189,7 +189,7 @@ typedef struct {
/* 0x0066 */ s16 savedSceneNum; // Upstream TODO: sceneId
/* 0x0068 */ ItemEquips equips;
/* 0x0074 */ Inventory inventory;
/* 0x00D4 */ SavedSceneFlags sceneFlags[124];
/* 0x00D4 */ SavedSceneFlags* sceneFlags;
/* 0x0E64 */ FaroresWindData fw;
/* 0x0E8C */ char unk_E8C[0x10];
/* 0x0E9C */ s32 gsFlags[6];
Expand Down
1 change: 1 addition & 0 deletions soh/include/z64scene.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#ifndef Z64SCENE_H
#define Z64SCENE_H
#include "z64math.h"

#include "command_macros_base.h"
#include "libultraship/libultra.h"
Expand Down
2 changes: 1 addition & 1 deletion soh/soh/ActorDB.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ ActorDB::Entry& ActorDB::AddEntry(const std::string& name, const std::string& de
return entry;
}

// Adds an actor with the new ActorDBInit struct. The id assigned to the actor is dynamic. Use the return Entry or RetrieveId to get it.
// Adds an actor with the new ActorDBInit struct. The id assigned to the actor is dynamic. Use the returned Entry or RetrieveId to get it.
ActorDB::Entry& ActorDB::AddEntry(const ActorDBInit& init) {
Entry& entry = AddEntry(init.name, init.desc, nextFreeId);

Expand Down
5 changes: 3 additions & 2 deletions soh/soh/Enhancements/randomizer/hook_handlers.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <libultraship/bridge.h>
#include "soh/OTRGlobals.h"
#include "soh/SceneDB.h"
#include "soh/Enhancements/enhancementTypes.h"
#include "soh/Enhancements/custom-message/CustomMessageTypes.h"
#include "soh/Enhancements/item-tables/ItemTableManager.h"
Expand Down Expand Up @@ -684,15 +685,15 @@ void RandomizerOnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, va_l
case VB_BE_ELIGIBLE_FOR_LIGHT_ARROWS:
*should =
LINK_IS_ADULT &&
(gEntranceTable[gSaveContext.entranceIndex].scene == SCENE_TEMPLE_OF_TIME) &&
(EntranceDB::Instance->RetrieveEntry(gSaveContext.entranceIndex).entry.sceneId == SCENE_TEMPLE_OF_TIME) &&
!Flags_GetEventChkInf(EVENTCHKINF_RETURNED_TO_TEMPLE_OF_TIME_WITH_ALL_MEDALLIONS) &&
MeetsLACSRequirements();
break;
case VB_BE_ELIGIBLE_FOR_NOCTURNE_OF_SHADOW:
*should =
!Flags_GetEventChkInf(EVENTCHKINF_BONGO_BONGO_ESCAPED_FROM_WELL) &&
LINK_IS_ADULT &&
gEntranceTable[((void)0, gSaveContext.entranceIndex)].scene == SCENE_KAKARIKO_VILLAGE &&
(EntranceDB::Instance->RetrieveEntry(gSaveContext.entranceIndex).entry.sceneId == SCENE_KAKARIKO_VILLAGE) &&
CHECK_QUEST_ITEM(QUEST_MEDALLION_FOREST) &&
CHECK_QUEST_ITEM(QUEST_MEDALLION_FIRE) &&
CHECK_QUEST_ITEM(QUEST_MEDALLION_WATER);
Expand Down
60 changes: 24 additions & 36 deletions soh/soh/Enhancements/randomizer/randomizer_entrance.c
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

#include "randomizer_entrance.h"
#include "randomizer_grotto.h"
#include "soh/SceneDB.h"
#include <string.h>

#include "global.h"
Expand Down Expand Up @@ -44,8 +45,6 @@ static s16 entranceOverrideTable[ENTRANCE_TABLE_SIZE] = {0};
static s16 bossSceneSaveDeathWarps[SHUFFLEABLE_BOSS_COUNT] = {0};
static ActorEntry modifiedLinkActorEntry = {0};

EntranceInfo originalEntranceTable[ENTRANCE_TABLE_SIZE] = {0};

typedef struct {
s16 entryway;
s16 exit;
Expand Down Expand Up @@ -78,19 +77,20 @@ u8 Entrance_EntranceIsNull(EntranceOverride* entranceOverride) {
entranceOverride->overrideDestination == 0;
}

// TODO all of this
static void Entrance_SeparateOGCFairyFountainExit(void) {
//Overwrite unused entrance 0x03E8 (ENTR_POTION_SHOP_KAKARIKO_1) with values from 0x0340 (ENTR_HYRULE_CASTLE_2) to use it as the
//exit from OGC Great Fairy Fountain -> Castle Grounds
for (size_t i = 0; i < 4; ++i) {
gEntranceTable[ENTR_POTION_SHOP_KAKARIKO_1 + i] = gEntranceTable[ENTR_HYRULE_CASTLE_2 + i];
EntranceDB_Copy(ENTR_HYRULE_CASTLE_2 + i, ENTR_POTION_SHOP_KAKARIKO_1 + i);
}
}

static void Entrance_SeparateAdultSpawnAndPrelude() {
// Overwrite unused entrance 0x0282 (ENTR_HYRULE_FIELD_10) with values from 0x05F4 (ENTR_TEMPLE_OF_TIME_7) to use it as the
// Adult Spawn index and separate it from Prelude of Light
for (size_t i = 0; i < 4; ++i) {
gEntranceTable[ENTR_HYRULE_FIELD_10 + i] = gEntranceTable[ENTR_TEMPLE_OF_TIME_7 + i];
EntranceDB_Copy(ENTR_TEMPLE_OF_TIME_7 + i, ENTR_HYRULE_FIELD_10 + i);
}
}

Expand All @@ -99,53 +99,43 @@ static void Entrance_ReplaceChildTempleWarps() {
if (Randomizer_GetSettingValue(RSK_SHUFFLE_DUNGEON_ENTRANCES) != RO_DUNGEON_ENTRANCE_SHUFFLE_OFF ||
Randomizer_GetSettingValue(RSK_SHUFFLE_BOSS_ENTRANCES) != RO_BOSS_ROOM_ENTRANCE_SHUFFLE_OFF) {
// Forest Temple
gEntranceTable[ENTR_SACRED_FOREST_MEADOW_3] = gEntranceTable[ENTR_SACRED_FOREST_MEADOW_2];
gEntranceTable[ENTR_SACRED_FOREST_MEADOW_3_1] = gEntranceTable[ENTR_SACRED_FOREST_MEADOW_2_1];
EntranceDB_Copy(ENTR_SACRED_FOREST_MEADOW_2, ENTR_SACRED_FOREST_MEADOW_3);
EntranceDB_Copy(ENTR_SACRED_FOREST_MEADOW_2_1, ENTR_SACRED_FOREST_MEADOW_3_1);
// Fire Temple
gEntranceTable[ENTR_DEATH_MOUNTAIN_CRATER_5] = gEntranceTable[ENTR_DEATH_MOUNTAIN_CRATER_4];
gEntranceTable[ENTR_DEATH_MOUNTAIN_CRATER_5_1] = gEntranceTable[ENTR_DEATH_MOUNTAIN_CRATER_4_1];
EntranceDB_Copy(ENTR_DEATH_MOUNTAIN_CRATER_4, ENTR_DEATH_MOUNTAIN_CRATER_5);
EntranceDB_Copy(ENTR_DEATH_MOUNTAIN_CRATER_4_1, ENTR_DEATH_MOUNTAIN_CRATER_5_1);
// Water Temple
gEntranceTable[ENTR_LAKE_HYLIA_9] = gEntranceTable[ENTR_LAKE_HYLIA_8];
gEntranceTable[ENTR_LAKE_HYLIA_9_1] = gEntranceTable[ENTR_LAKE_HYLIA_8_1];
EntranceDB_Copy(ENTR_LAKE_HYLIA_8, ENTR_LAKE_HYLIA_9);
EntranceDB_Copy(ENTR_LAKE_HYLIA_8_1, ENTR_LAKE_HYLIA_9_1);
// Shadow Temple
gEntranceTable[ENTR_GRAVEYARD_8] = gEntranceTable[ENTR_GRAVEYARD_7];
gEntranceTable[ENTR_GRAVEYARD_8_1] = gEntranceTable[ENTR_GRAVEYARD_7_1];
EntranceDB_Copy(ENTR_GRAVEYARD_7, ENTR_GRAVEYARD_8);
EntranceDB_Copy(ENTR_GRAVEYARD_7_1, ENTR_GRAVEYARD_8_1);
// Spirit Temple
gEntranceTable[ENTR_DESERT_COLOSSUS_8] = gEntranceTable[ENTR_DESERT_COLOSSUS_5];
gEntranceTable[ENTR_DESERT_COLOSSUS_8_1] = gEntranceTable[ENTR_DESERT_COLOSSUS_5_1];
}
}

void Entrance_CopyOriginalEntranceTable(void) {
if (!hasCopiedEntranceTable) {
memcpy(originalEntranceTable, gEntranceTable, sizeof(EntranceInfo) * ENTRANCE_TABLE_SIZE);
hasCopiedEntranceTable = 1;
EntranceDB_Copy(ENTR_DESERT_COLOSSUS_5, ENTR_DESERT_COLOSSUS_8);
EntranceDB_Copy(ENTR_DESERT_COLOSSUS_5_1, ENTR_DESERT_COLOSSUS_8_1);
}
}

void Entrance_ResetEntranceTable(void) {
if (hasCopiedEntranceTable && hasModifiedEntranceTable) {
memcpy(gEntranceTable, originalEntranceTable, sizeof(EntranceInfo) * ENTRANCE_TABLE_SIZE);
hasModifiedEntranceTable = 0;
}
EntranceDB_ResetVanillaEntrances();
}

void Entrance_Init(void) {
EntranceOverride* entranceOverrides = Randomizer_GetEntranceOverrides();
s32 index;

Entrance_CopyOriginalEntranceTable();

// Skip Child Stealth if given by settings
if (Randomizer_GetSettingValue(RSK_SKIP_CHILD_STEALTH)) {
gEntranceTable[ENTR_CASTLE_COURTYARD_GUARDS_DAY_0].scene = SCENE_CASTLE_COURTYARD_ZELDA;
gEntranceTable[ENTR_CASTLE_COURTYARD_GUARDS_DAY_0].spawn = 0;
gEntranceTable[ENTR_CASTLE_COURTYARD_GUARDS_DAY_0].field = ENTRANCE_INFO_FIELD(false, false, TRANS_TYPE_FADE_WHITE, TRANS_TYPE_FADE_WHITE);
EntranceDB_Copy(ENTR_CASTLE_COURTYARD_ZELDA_0, ENTR_CASTLE_COURTYARD_GUARDS_DAY_0);
}

// Delete the title card and add a fade in for Hyrule Field from Ocarina of Time cutscene
for (index = ENTR_HYRULE_FIELD_16; index <= ENTR_HYRULE_FIELD_16_3; ++index) {
gEntranceTable[index].field = ENTRANCE_INFO_FIELD(false, false, TRANS_TYPE_FADE_BLACK, TRANS_TYPE_INSTANT);
EntranceDBEntry* entry = EntranceDB_Retrieve(index);
entry->continueBgm = false;
entry->displayTitleCard = false;
entry->endTransition = TRANS_TYPE_FADE_BLACK;
entry->startTransition = TRANS_TYPE_INSTANT;
}

Entrance_SeparateOGCFairyFountainExit();
Expand Down Expand Up @@ -238,9 +228,7 @@ void Entrance_Init(void) {

s16 override = indicesToSilenceBackgroundMusic[j];
for (s16 i = 0; i < 4; i++) {
// Zero out the bit in the field which tells the game to keep playing
// background music for all four scene setups at each index
gEntranceTable[override + i].field &= ~ENTRANCE_INFO_CONTINUE_BGM_FLAG;
EntranceDB_Retrieve(override + i)->continueBgm = false;
}
}
}
Expand Down Expand Up @@ -308,8 +296,8 @@ u32 Entrance_SceneAndSpawnAre(u8 scene, u8 spawn) {
}
}

EntranceInfo currentEntrance = gEntranceTable[entranceIndex];
return currentEntrance.scene == scene && currentEntrance.spawn == spawn;
EntranceDBEntry* entry = EntranceDB_Retrieve(entranceIndex);
return entry->sceneId == scene && entry->spawn == spawn;
}

// Properly respawn the player after a game over, accounting for dungeon entrance randomizer
Expand Down
3 changes: 0 additions & 3 deletions soh/soh/Enhancements/savestates.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ typedef struct SaveStateInfo {
uint16_t gAudioSfxSwapTarget_copy[10];
uint8_t gAudioSfxSwapMode_copy[10];
void (*D_801755D0_copy)(void);
MapMarkData** sLoadedMarkDataTableCopy;

//Static Data

Expand Down Expand Up @@ -698,7 +697,6 @@ void SaveState::LoadOverlayStaticData(void) {
void SaveState::SaveMiscCodeData(void) {
info->gGameOverTimer_copy = gGameOverTimer;
info->gTimeIncrement_copy = gTimeIncrement;
info->sLoadedMarkDataTableCopy = sLoadedMarkDataTable;

info->sPlayerInitialPosX_copy = sPlayerInitialPosX;
info->sPlayerInitialPosZ_copy = sPlayerInitialPosZ;
Expand Down Expand Up @@ -759,7 +757,6 @@ void SaveState::SaveMiscCodeData(void) {
void SaveState::LoadMiscCodeData(void) {
gGameOverTimer = info->gGameOverTimer_copy;
gTimeIncrement = info->gTimeIncrement_copy;
sLoadedMarkDataTable = info->sLoadedMarkDataTableCopy;

sPlayerInitialPosX = info->sPlayerInitialPosX_copy;
sPlayerInitialPosZ = info->sPlayerInitialPosZ_copy;
Expand Down
1 change: 0 additions & 1 deletion soh/soh/Enhancements/savestates_extern.inc
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ extern "C" MtxF* sMatrixStack;
extern "C" MtxF* sCurrentMatrix;
extern "C" LightsBuffer sLightsBuffer;
extern "C" s16 sWarpTimerTarget;
extern "C" MapMarkData** sLoadedMarkDataTable;

//Camera static data
extern "C" int32_t sInitRegs;
Expand Down
3 changes: 2 additions & 1 deletion soh/soh/Enhancements/timesaver_hook_handlers.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include <libultraship/bridge.h>
#include "soh/OTRGlobals.h"
#include "soh/SceneDB.h"
#include "soh/Enhancements/randomizer/randomizerTypes.h"
#include "soh/Enhancements/game-interactor/GameInteractor.h"
#include "soh/Enhancements/game-interactor/GameInteractor_Hooks.h"
Expand Down Expand Up @@ -155,7 +156,7 @@ void TimeSaverOnVanillaBehaviorHandler(GIVanillaBehavior id, bool* should, va_li
// LACS
u8 meetsLACSRequirements =
LINK_IS_ADULT &&
(gEntranceTable[((void)0, gSaveContext.entranceIndex)].scene == SCENE_TEMPLE_OF_TIME) &&
(EntranceDB::Instance->RetrieveEntry(gSaveContext.entranceIndex).entry.sceneId == SCENE_TEMPLE_OF_TIME) &&
CHECK_QUEST_ITEM(QUEST_MEDALLION_SPIRIT) &&
CHECK_QUEST_ITEM(QUEST_MEDALLION_SHADOW) &&
!Flags_GetEventChkInf(EVENTCHKINF_RETURNED_TO_TEMPLE_OF_TIME_WITH_ALL_MEDALLIONS);
Expand Down
5 changes: 3 additions & 2 deletions soh/soh/Enhancements/tts/tts.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
#include <spdlog/fmt/fmt.h>

#include "soh/OTRGlobals.h"
#include "soh/SceneDB.h"
#include "message_data_static.h"
#include "overlays/gamestates/ovl_file_choose/file_choose.h"
#include "soh/Enhancements/boss-rush/BossRush.h"
#include "soh/resource/type/SohResourceType.h"

extern "C" {
extern MapData* gMapData;
extern SaveContext gSaveContext;
extern PlayState* gPlayState;
}
Expand Down Expand Up @@ -204,6 +204,7 @@ void RegisterOnKaleidoscopeUpdateHook() {

PauseContext* pauseCtx = &gPlayState->pauseCtx;
Input* input = &gPlayState->state.input[0];
SceneDB::Entry& scene = SceneDB::Instance->RetrieveEntry(gSaveContext.mapIndex);

// Save game prompt
if (pauseCtx->state == 7) {
Expand Down Expand Up @@ -452,7 +453,7 @@ void RegisterOnKaleidoscopeUpdateHook() {

// Cursor is on a dungeon floor position
if (cursorPoint >= 3 && cursorPoint < 11) {
int floorID = gMapData->floorID[gPlayState->interfaceCtx.unk_25A][pauseCtx->dungeonMapSlot - 3];
int floorID = scene.entry.dungeonData.floors[pauseCtx->dungeonMapSlot - 3].id; // TODO test
// Normalize so F1 == 0, and negative numbers are basement levels
int normalizedFloor = (floorID * -1) + 8;
if (normalizedFloor >= 0) {
Expand Down
3 changes: 3 additions & 0 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
#include "Enhancements/item-tables/ItemTableManager.h"
#include "SohGui.hpp"
#include "ActorDB.h"
#include "SceneDB.h"

#ifdef ENABLE_REMOTE_CONTROL
#include "Enhancements/crowd-control/CrowdControl.h"
Expand Down Expand Up @@ -1141,6 +1142,8 @@ extern "C" void InitOTR() {
SohGui::SetupGuiElements();
AudioCollection::Instance = new AudioCollection();
ActorDB::Instance = new ActorDB();
SceneDB::Instance = new SceneDB();
EntranceDB::Instance = new EntranceDB();
#ifdef __APPLE__
SpeechSynthesizer::Instance = new DarwinSpeechSynthesizer();
SpeechSynthesizer::Instance->Init();
Expand Down
Loading