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

Alt Asset Preload and Persistence (aka "Error 404: Asset Load Hiccup Not Found") #4652

Open
wants to merge 15 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
6 changes: 4 additions & 2 deletions soh/soh/Enhancements/TimeDisplay/TimeDisplay.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,10 @@ typedef enum {
NAVI_PREPARE = 600,
NAVI_ACTIVE = 3000,
NAVI_COOLDOWN = 25800,
DAY_BEGINS = 17759,
NIGHT_BEGINS = 49155
SUNRISE_BEGINS = 0x2AAC,
DAY_BEGINS = 0x4555,
SUNSET_BEGINS = 0xAAAB,
NIGHT_BEGINS = 0xC001
};

typedef struct {
Expand Down
5 changes: 5 additions & 0 deletions soh/soh/OTRGlobals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1138,9 +1138,12 @@ extern "C" void InitOTR() {
DetectOTRVersion("oot-mq.otr", true);

OTRGlobals::Instance = new OTRGlobals();

ResourceMgr_LoadPersistentAltAssets();
CustomMessageManager::Instance = new CustomMessageManager();
ItemTableManager::Instance = new ItemTableManager();
GameInteractor::Instance = new GameInteractor();
ResourceMgr_RegisterHooks();
SaveManager::Instance = new SaveManager();

std::shared_ptr<Ship::Config> conf = OTRGlobals::Instance->context->GetConfig();
Expand Down Expand Up @@ -1202,6 +1205,8 @@ extern "C" void InitOTR() {
Sail::Instance->Enable();
}
#endif

ResourceMgr_Init();
}

extern "C" void SaveManager_ThreadPoolWait() {
Expand Down
1 change: 0 additions & 1 deletion soh/soh/OTRGlobals.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ class OTRGlobals {
bool HasMasterQuest();
bool HasOriginal();
uint32_t GetInterpolationFPS();
std::shared_ptr<std::vector<std::string>> ListFiles(std::string path);

private:
void CheckSaveFile(size_t sramSize) const;
Expand Down
329 changes: 298 additions & 31 deletions soh/soh/ResourceManagerHelpers.cpp

Large diffs are not rendered by default.

17 changes: 17 additions & 0 deletions soh/soh/ResourceManagerHelpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,12 @@ extern "C" {
#include "z64animation.h"
#include "z64audio.h"
#include "z64bgcheck.h"
typedef enum {
TOD_Sunrise,
TOD_Day,
TOD_Sunset,
TOD_Night
} TimeOfDay;
uint32_t ResourceMgr_IsGameMasterQuest();
uint32_t ResourceMgr_IsSceneMasterQuest(s16 sceneNum);
uint32_t ResourceMgr_GameHasMasterQuest();
Expand Down Expand Up @@ -61,6 +67,17 @@ extern "C" {
s32* ResourceMgr_LoadCSByName(const char* path);
int ResourceMgr_OTRSigCheck(char* imgData);
char* ResourceMgr_GetResourceDataByNameHandlingMQ(const char* path);
void ResourceMgr_LoadAllSceneResources(int16_t sceneNum, bool now);
void ResourceMgr_UnloadSceneAssets();
void ResourceMgr_LoadDelayedPersistentAltAssets();
void ResourceMgr_LoadPersistentAltAssets();
void ResourceMgr_RegisterUnloadSceneAssets(s16 prevScene);
void ResourceMgr_CheckLoadSkybox(bool fileSelect);
void ResourceMgr_SceneInitSkybox();
void ResourceMgr_RegisterHooks();
void ResourceMgr_LoadSkyBox(TimeOfDay timeIndex, bool fileSelect);
void ResourceMgr_UnloadSkyBox(TimeOfDay timeIndex);
void ResourceMgr_Init();
#ifdef __cplusplus
}
#endif // __cplusplus
6 changes: 4 additions & 2 deletions soh/soh/z_play_otr.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "OTRGlobals.h"
#include "ResourceManagerHelpers.h"
#include <libultraship/libultraship.h>
#include "soh/ResourceManagerHelpers.h"
#include "soh/resource/type/Scene.h"
#include <utils/StringHelper.h>
#include "soh/Enhancements/game-interactor/GameInteractor.h"
Expand All @@ -14,7 +15,7 @@ void OTRPlay_InitScene(PlayState* play, s32 spawn);
s32 OTRScene_ExecuteCommands(PlayState* play, SOH::Scene* scene);

//LUS::OTRResource* OTRPlay_LoadFile(PlayState* play, RomFile* file) {
Ship::IResource* OTRPlay_LoadFile(PlayState* play, const char* fileName)
Ship::IResource* OTRPlay_LoadFile(const char* fileName)
{
auto res = Ship::Context::GetInstance()->GetResourceManager()->LoadResource(fileName);
return res.get();
Expand All @@ -40,7 +41,7 @@ extern "C" void OTRPlay_SpawnScene(PlayState* play, s32 sceneId, s32 spawn) {
}
std::string scenePath = StringHelper::Sprintf("scenes/%s/%s/%s", sceneVersion.c_str(), scene->sceneFile.fileName, scene->sceneFile.fileName);

play->sceneSegment = OTRPlay_LoadFile(play, scenePath.c_str());
play->sceneSegment = OTRPlay_LoadFile(scenePath.c_str());

// Failed to load scene... default to doodongs cavern
if (play->sceneSegment == nullptr)
Expand Down Expand Up @@ -76,6 +77,7 @@ void OTRPlay_InitScene(PlayState* play, s32 spawn) {
Object_InitBank(play, &play->objectCtx);
LightContext_Init(play, &play->lightCtx);
TransitionActor_InitContext(&play->state, &play->transiActorCtx);

func_80096FD4(play, &play->roomCtx.curRoom);
YREG(15) = 0;
gSaveContext.worldMapArea = 0;
Expand Down
4 changes: 2 additions & 2 deletions soh/soh/z_scene_otr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
#include "soh/resource/type/scenecommand/SetEchoSettings.h"
#include "soh/resource/type/scenecommand/SetAlternateHeaders.h"

extern Ship::IResource* OTRPlay_LoadFile(PlayState* play, const char* fileName);
extern Ship::IResource* OTRPlay_LoadFile(const char* fileName);
extern "C" s32 Object_Spawn(ObjectContext* objectCtx, s16 objectId);
extern "C" RomFile sNaviMsgFiles[];
s32 OTRScene_ExecuteCommands(PlayState* play, SOH::Scene* scene);
Expand Down Expand Up @@ -107,7 +107,7 @@ bool Scene_CommandSpecialFiles(PlayState* play, SOH::ISceneCommand* cmd) {

if (specialCmd->specialObjects.elfMessage != 0) {
auto res =
(Ship::Blob*)OTRPlay_LoadFile(play, sNaviMsgFiles[specialCmd->specialObjects.elfMessage - 1].fileName);
(Ship::Blob*)OTRPlay_LoadFile(sNaviMsgFiles[specialCmd->specialObjects.elfMessage - 1].fileName);
play->cUpElfMsgs = (ElfMessage*)res->Data.data();
}

Expand Down
11 changes: 10 additions & 1 deletion soh/src/code/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,11 +466,20 @@ void GameState_Destroy(GameState* gameState) {

osSyncPrintf("game デストラクタ終了\n"); // "game destructor end"

PlayState* play = (PlayState*)gameState;
static s16 sceneNum = -1;

// Performing clear skeletons before unload resources fixes an actor heap corruption crash due to the skeleton patching system.
ResourceMgr_ClearSkeletons();
if (play->sceneNum != sceneNum) {

if (play->sceneNum >= SCENE_DEKU_TREE && play->sceneNum <= SCENE_TESTROOM) {
ResourceMgr_RegisterUnloadSceneAssets(play->sceneNum);
}
ResourceUnloadDirectory("alt/textures/vs*");
sceneNum = play->sceneNum;
}
if (ResourceMgr_IsAltAssetsEnabled()) {
ResourceUnloadDirectory("alt/*");
gfx_texture_cache_clear();
}
}
Expand Down
1 change: 1 addition & 0 deletions soh/src/overlays/actors/ovl_player_actor/z_player.c
Original file line number Diff line number Diff line change
Expand Up @@ -5155,6 +5155,7 @@ s32 Player_HandleExitsAndVoids(PlayState* play, Player* this, CollisionPoly* pol
gSaveContext.retainWeatherMode = 1;
Scene_SetTransitionForNextEntrance(play);
}
ResourceMgr_LoadAllSceneResources(gEntranceTable[((void)0, play->nextEntranceIndex)].scene, false);
play->transitionTrigger = TRANS_TRIGGER_START;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3300,6 +3300,7 @@ void FileChoose_Main(GameState* thisx) {

if (CVarGetInteger(CVAR_ENHANCEMENT("TimeFlowFileSelect"), 0) != 0) {
gSaveContext.skyboxTime += 0x10;
ResourceMgr_CheckLoadSkybox(true);
}

if (CVarGetInteger(CVAR_DEVELOPER_TOOLS("SkipLogoTitle"), 0) && CVarGetInteger(CVAR_DEVELOPER_TOOLS("SaveFileID"), FASTFILE_1) <= FASTFILE_3 && !isFastFileIdIncompatible) {
Expand Down