Fix play as kafei by swapping out resources later (#617)

This commit is contained in:
Garrett Cox
2024-05-30 23:10:45 -04:00
committed by GitHub
parent f32bccc5b9
commit 8ac7dc6b7d
5 changed files with 18 additions and 17 deletions
+2 -4
View File
@@ -531,10 +531,8 @@ void DrawEnhancementsMenu() {
}
if (UIWidgets::BeginMenu("Modes")) {
if (UIWidgets::CVarCheckbox("Play As Kafei", "gModes.PlayAsKafei",
{ .tooltip = "Requires scene reload to take effect." })) {
UpdatePlayAsKafeiSkeletons();
}
UIWidgets::CVarCheckbox("Play As Kafei", "gModes.PlayAsKafei",
{ .tooltip = "Requires scene reload to take effect." });
ImGui::EndMenu();
}
if (UIWidgets::BeginMenu("Player Movement")) {
@@ -49,6 +49,10 @@ void GameInteractor_ExecuteOnRoomInit(s16 sceneId, s8 roomNum) {
GameInteractor::Instance->ExecuteHooksForFilter<GameInteractor::OnRoomInit>(sceneId, roomNum);
}
void GameInteractor_ExecuteOnPlayDestroy() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnPlayDestroy>();
}
bool GameInteractor_ShouldActorInit(Actor* actor) {
bool result = true;
GameInteractor::Instance->ExecuteHooks<GameInteractor::ShouldActorInit>(actor, &result);
@@ -255,6 +255,7 @@ class GameInteractor {
DEFINE_HOOK(OnSceneInit, (s8 sceneId, s8 spawnNum));
DEFINE_HOOK(OnRoomInit, (s8 sceneId, s8 roomNum));
DEFINE_HOOK(OnPlayDestroy, ());
DEFINE_HOOK(ShouldActorInit, (Actor * actor, bool* should));
DEFINE_HOOK(OnActorInit, (Actor * actor));
@@ -296,6 +297,7 @@ void GameInteractor_ExecuteBeforeMoonCrashSaveReset();
void GameInteractor_ExecuteOnSceneInit(s16 sceneId, s8 spawnNum);
void GameInteractor_ExecuteOnRoomInit(s16 sceneId, s8 roomNum);
void GameInteractor_ExecuteOnPlayDestroy();
bool GameInteractor_ShouldActorInit(Actor* actor);
void GameInteractor_ExecuteOnActorInit(Actor* actor);
+7 -13
View File
@@ -17,20 +17,12 @@ extern TexturePtr sPlayerMouthTextures[PLAYER_FORM_MAX][PLAYER_MOUTH_MAX];
static SkeletonHeader gLinkHumanSkelBackup;
static SkeletonHeader gKafeiSkelBackup;
void UpdatePlayAsKafeiSkeletons() {
void UpdatePlayAsKafei() {
if (CVarGetInteger("gModes.PlayAsKafei", 0)) {
auto gLinkHumanSkelResource = Ship::Context::GetInstance()->GetResourceManager()->LoadResource(gLinkHumanSkel);
SkeletonHeader* gLinkHumanSkelPtr = (SkeletonHeader*)gLinkHumanSkelResource->GetRawPointer();
memcpy(gLinkHumanSkelPtr, &gKafeiSkelBackup, sizeof(SkeletonHeader));
} else {
auto gLinkHumanSkelResource = Ship::Context::GetInstance()->GetResourceManager()->LoadResource(gLinkHumanSkel);
SkeletonHeader* gLinkHumanSkelPtr = (SkeletonHeader*)gLinkHumanSkelResource->GetRawPointer();
memcpy(gLinkHumanSkelPtr, &gLinkHumanSkelBackup, sizeof(SkeletonHeader));
}
}
void UpdatePlayAsKafeiOther() {
if (CVarGetInteger("gModes.PlayAsKafei", 0)) {
ResourceMgr_PatchGfxByName(gLinkHumanWaistDL, "gLinkHumanWaistDL0", 0,
gsSPDisplayListOTRFilePath(gKafeiWaistDL));
ResourceMgr_PatchGfxByName(gLinkHumanWaistDL, "gLinkHumanWaistDL1", 1, gsSPEndDisplayList());
@@ -49,6 +41,10 @@ void UpdatePlayAsKafeiOther() {
sPlayerMouthTextures[PLAYER_FORM_HUMAN][2] = (TexturePtr)gKafeiMouthAngryTex;
sPlayerMouthTextures[PLAYER_FORM_HUMAN][3] = (TexturePtr)gKafeiMouthHappyTex;
} else {
auto gLinkHumanSkelResource = Ship::Context::GetInstance()->GetResourceManager()->LoadResource(gLinkHumanSkel);
SkeletonHeader* gLinkHumanSkelPtr = (SkeletonHeader*)gLinkHumanSkelResource->GetRawPointer();
memcpy(gLinkHumanSkelPtr, &gLinkHumanSkelBackup, sizeof(SkeletonHeader));
ResourceMgr_UnpatchGfxByName(gLinkHumanWaistDL, "gLinkHumanWaistDL0");
ResourceMgr_UnpatchGfxByName(gLinkHumanWaistDL, "gLinkHumanWaistDL1");
@@ -78,9 +74,7 @@ void RegisterPlayAsKafei() {
memcpy(&gLinkHumanSkelBackup, gLinkHumanSkelPtr, sizeof(SkeletonHeader));
memcpy(&gKafeiSkelBackup, gKafeiSkelPtr, sizeof(SkeletonHeader));
UpdatePlayAsKafeiSkeletons();
UpdatePlayAsKafeiOther();
UpdatePlayAsKafei();
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnSceneInit>(
[](s8 sceneId, s8 spawnNum) { UpdatePlayAsKafeiOther(); });
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnPlayDestroy>([]() { UpdatePlayAsKafei(); });
}
+3
View File
@@ -467,6 +467,9 @@ void Play_Destroy(GameState* thisx) {
KaleidoScopeCall_Destroy(this);
KaleidoManager_Destroy();
ZeldaArena_Cleanup();
GameInteractor_ExecuteOnPlayDestroy();
// #region 2S2H [General] Making gPlayState available
gPlayState = NULL;
// #endregion