Skip to content

Commit

Permalink
Merge commit 'refs/pull/3083/head' of garrettjoecox.github.com:Harbou…
Browse files Browse the repository at this point in the history
…rMasters/Shipwright into anchor
  • Loading branch information
garrettjoecox committed Aug 16, 2023
2 parents e12728c + 39fff23 commit 0330c21
Show file tree
Hide file tree
Showing 12 changed files with 449 additions and 5 deletions.
2 changes: 2 additions & 0 deletions soh/include/functions.h
Original file line number Diff line number Diff line change
Expand Up @@ -2447,6 +2447,8 @@ void Heaps_Free(void);

CollisionHeader* BgCheck_GetCollisionHeader(CollisionContext* colCtx, s32 bgId);

void Interface_CreateQuadVertexGroup(Vtx* vtxList, s32 xStart, s32 yStart, s32 width, s32 height, u8 flippedH);

// Exposing these methods to leverage them from the file select screen to render messages
void Message_OpenText(PlayState* play, u16 textId);
void Message_Decode(PlayState* play);
Expand Down
2 changes: 2 additions & 0 deletions soh/soh/Enhancements/cosmetics/CosmeticsEditor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,8 @@ static std::map<std::string, CosmeticOption> cosmeticOptions = {
COSMETIC_OPTION("Hud_MinimapEntrance", "Minimap Entrance", GROUP_HUD, ImVec4(200, 0, 0, 255), false, true, true),
COSMETIC_OPTION("Hud_EnemyHealthBar", "Enemy Health Bar", GROUP_HUD, ImVec4(255, 0, 0, 255), true, true, false),
COSMETIC_OPTION("Hud_EnemyHealthBorder", "Enemy Health Border", GROUP_HUD, ImVec4(255, 255, 255, 255), true, false, true),
COSMETIC_OPTION("Hud_NameTagActorText", "Nametag Text", GROUP_HUD, ImVec4(255, 255, 255, 255), true, true, false),
COSMETIC_OPTION("Hud_NameTagActorBackground", "Nametag Background", GROUP_HUD, ImVec4(0, 0, 0, 80), true, false, true),

COSMETIC_OPTION("Title_FileChoose", "File Choose", GROUP_TITLE, ImVec4(100, 150, 255, 255), false, true, false),
COSMETIC_OPTION("Title_NintendoLogo", "Nintendo Logo", GROUP_TITLE, ImVec4( 0, 0, 255, 255), false, true, true),
Expand Down
73 changes: 71 additions & 2 deletions soh/soh/Enhancements/debugger/actorViewer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
#include "../../util.h"
#include "../../UIWidgets.hpp"
#include "soh/ActorDB.h"
#include "soh/Enhancements/game-interactor/GameInteractor.h"
#include "soh/Enhancements/nametag.h"

#include <array>
#include <bit>
Expand All @@ -22,6 +24,8 @@ extern PlayState* gPlayState;
#include "textures/icon_item_24_static/icon_item_24_static.h"
}

#define DEBUG_ACTOR_NAMETAG_TAG "debug_actor_viewer"

typedef struct {
u16 id;
u16 params;
Expand Down Expand Up @@ -51,6 +55,13 @@ std::array<const char*, 12> acMapping = {
"Chest"
};

typedef enum {
ACTORVIEWER_NAMETAGS_NONE,
ACTORVIEWER_NAMETAGS_DESC,
ACTORVIEWER_NAMETAGS_NAME,
ACTORVIEWER_NAMETAGS_BOTH,
} ActorViewerNameTagsType;

const std::string GetActorDescription(u16 id) {
return ActorDB::Instance->RetrieveEntry(id).entry.valid ? ActorDB::Instance->RetrieveEntry(id).entry.desc : "???";
}
Expand Down Expand Up @@ -96,6 +107,42 @@ void PopulateActorDropdown(int i, std::vector<Actor*>& data) {
}
}

void ActorViewer_AddTagForActor(Actor* actor) {
int val = CVarGetInteger("gDebugActorViewerNameTags", ACTORVIEWER_NAMETAGS_NONE);
auto entry = ActorDB::Instance->RetrieveEntry(actor->id);
std::string tag;

if (val > 0 && entry.entry.valid) {
switch (val) {
case ACTORVIEWER_NAMETAGS_DESC:
tag = entry.desc;
break;
case ACTORVIEWER_NAMETAGS_NAME:
tag = entry.name;
break;
case ACTORVIEWER_NAMETAGS_BOTH:
tag = entry.name + '\n' + entry.desc;
break;
}

NameTag_RegisterForActorWithOptions(actor, tag.c_str(), { .tag = DEBUG_ACTOR_NAMETAG_TAG });
}
}

void ActorViewer_AddTagForAllActors() {
if (gPlayState == nullptr) {
return;
}

for (size_t i = 0; i < ARRAY_COUNT(gPlayState->actorCtx.actorLists); i++) {
ActorListEntry currList = gPlayState->actorCtx.actorLists[i];
Actor* currAct = currList.head;
while (currAct != nullptr) {
ActorViewer_AddTagForActor(currAct);
currAct = currAct->next;
}
}
}

void ActorViewerWindow::DrawElement() {
ImGui::SetNextWindowSize(ImVec2(520, 600), ImGuiCond_FirstUseEver);
Expand Down Expand Up @@ -319,7 +366,7 @@ void ActorViewerWindow::DrawElement() {
newActor.pos.y, newActor.pos.z, newActor.rot.x, newActor.rot.y,
newActor.rot.z, newActor.params);
} else {
func_80078884(NA_SE_SY_ERROR);
func_80078884(NA_SE_SY_ERROR);
}
}
}
Expand All @@ -330,6 +377,22 @@ void ActorViewerWindow::DrawElement() {

ImGui::TreePop();
}

static const char* nameTagOptions[] = {
"None",
"Short Description",
"Actor ID",
"Both"
};

UIWidgets::Spacer(0);

ImGui::Text("Actor Name Tags");
if (UIWidgets::EnhancementCombobox("gDebugActorViewerNameTags", nameTagOptions, ACTORVIEWER_NAMETAGS_NONE)) {
NameTag_RemoveAllByTag(DEBUG_ACTOR_NAMETAG_TAG);
ActorViewer_AddTagForAllActors();
}
UIWidgets::Tooltip("Adds \"name tags\" above actors for identification");
} else {
ImGui::Text("Global Context needed for actor info!");
if (needs_reset) {
Expand All @@ -340,7 +403,13 @@ void ActorViewerWindow::DrawElement() {
needs_reset = false;
}
}


ImGui::End();
}

void ActorViewerWindow::InitElement() {
GameInteractor::Instance->RegisterGameHook<GameInteractor::OnActorInit>([](void* refActor) {
Actor* actor = static_cast<Actor*>(refActor);
ActorViewer_AddTagForActor(actor);
});
}
4 changes: 2 additions & 2 deletions soh/soh/Enhancements/debugger/actorViewer.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,6 @@ class ActorViewerWindow : public LUS::GuiWindow {
using GuiWindow::GuiWindow;

void DrawElement() override;
void InitElement() override {};
void InitElement() override;
void UpdateElement() override {};
};
};
4 changes: 3 additions & 1 deletion soh/soh/Enhancements/game-interactor/GameInteractor.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,11 @@ class GameInteractor {
DEFINE_HOOK(OnSceneSpawnActors, void());
DEFINE_HOOK(OnPlayerUpdate, void());
DEFINE_HOOK(OnOcarinaSongAction, void());

DEFINE_HOOK(OnActorInit, void(void* actor));
DEFINE_HOOK(OnActorUpdate, void(void* actor));
DEFINE_HOOK(OnPlayerBonk, void());
DEFINE_HOOK(OnPlayDestroy, void());
DEFINE_HOOK(OnPlayDrawEnd, void());

DEFINE_HOOK(OnSaveFile, void(int32_t fileNum));
DEFINE_HOOK(OnLoadFile, void(int32_t fileNum));
Expand Down
12 changes: 12 additions & 0 deletions soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ void GameInteractor_ExecuteOnOcarinaSongAction() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnOcarinaSongAction>();
}

void GameInteractor_ExecuteOnActorInit(void* actor) {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnActorInit>(actor);
}

void GameInteractor_ExecuteOnActorUpdate(void* actor) {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnActorUpdate>(actor);
}
Expand All @@ -66,6 +70,14 @@ void GameInteractor_ExecuteOnPlayerBonk() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnPlayerBonk>();
}

void GameInteractor_ExecuteOnPlayDestroy() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnPlayDestroy>();
}

void GameInteractor_ExecuteOnPlayDrawEnd() {
GameInteractor::Instance->ExecuteHooks<GameInteractor::OnPlayDrawEnd>();
}

// MARK: - Save Files

void GameInteractor_ExecuteOnSaveFile(int32_t fileNum) {
Expand Down
3 changes: 3 additions & 0 deletions soh/soh/Enhancements/game-interactor/GameInteractor_Hooks.h
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ void GameInteractor_ExecuteOnFlagUnset(int16_t flagType, int16_t flag);
void GameInteractor_ExecuteOnSceneSpawnActors();
void GameInteractor_ExecuteOnPlayerUpdate();
void GameInteractor_ExecuteOnOcarinaSongAction();
void GameInteractor_ExecuteOnActorInit(void* actor);
void GameInteractor_ExecuteOnActorUpdate(void* actor);
void GameInteractor_ExecuteOnPlayerBonk();
void GameInteractor_ExecuteOnOcarinaSongAction();
void GameInteractor_ExecuteOnPlayDestroy();
void GameInteractor_ExecuteOnPlayDrawEnd();

// MARK: - Save Files
void GameInteractor_ExecuteOnSaveFile(int32_t fileNum);
Expand Down
2 changes: 2 additions & 0 deletions soh/soh/Enhancements/mods.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include "soh/Enhancements/enhancementTypes.h"
#include "soh/Enhancements/randomizer/3drando/random.hpp"
#include "soh/Enhancements/cosmetics/authenticGfxPatches.h"
#include "soh/Enhancements/nametag.h"

extern "C" {
#include <z64.h>
Expand Down Expand Up @@ -771,4 +772,5 @@ void InitMods() {
RegisterMenuPathFix();
RegisterMirrorModeHandler();
RegisterAltTrapTypes();
NameTag_RegisterHooks();
}
Loading

0 comments on commit 0330c21

Please sign in to comment.