diff --git a/soh/soh/Enhancements/debugger/valueViewer.cpp b/soh/soh/Enhancements/debugger/valueViewer.cpp index 14a571dac..579b353b2 100644 --- a/soh/soh/Enhancements/debugger/valueViewer.cpp +++ b/soh/soh/Enhancements/debugger/valueViewer.cpp @@ -1,5 +1,6 @@ #include "valueViewer.h" #include "../../UIWidgets.hpp" +#include "soh/Enhancements/stairs.h" extern "C" { #include @@ -14,26 +15,33 @@ s32 GfxPrint_Printf(GfxPrint* printer, const char* fmt, ...); ImVec4 WHITE = ImVec4(1.0f, 1.0f, 1.0f, 1.0f); +static u32 stairsOutMaxFree; +static u32 stairsOutFree; +static u32 stairsOutAlloc; + std::vector valueTable = { - { "Time", "gSaveContext.dayTime", "TIME:", TYPE_U16, false, []() -> void* { return &gSaveContext.dayTime; }, WHITE }, - { "Age", "gSaveContext.linkAge", "AGE:", TYPE_S32, false, []() -> void* { return &gSaveContext.linkAge; }, WHITE }, - { "Health", "gSaveContext.health", "HP:", TYPE_S16, false, []() -> void* { return &gSaveContext.health; }, WHITE }, - { "Navi Timer", "gSaveContext.naviTimer", "NAVI:", TYPE_U16, false, []() -> void* { return &gSaveContext.naviTimer; }, WHITE }, - { "Scene ID", "play->sceneNum", "SCENE:", TYPE_S16, true, []() -> void* { return &gPlayState->sceneNum; }, WHITE }, - { "Room ID", "play->roomCtx.curRoom.num", "ROOM:", TYPE_S8, true, []() -> void* { return &gPlayState->roomCtx.curRoom.num; }, WHITE }, - { "Entrance ID", "gSaveContext.entranceIndex", "ENTR:", TYPE_S32, false, []() -> void* { return &gSaveContext.entranceIndex; }, WHITE }, - { "Cutscene ID", "gSaveContext.cutsceneIndex", "CUTS:", TYPE_S32, false, []() -> void* { return &gSaveContext.cutsceneIndex; }, WHITE }, - { "Link X", "Player->actor.world.pos.x", "X:", TYPE_FLOAT, true, []() -> void* { return &GET_PLAYER(gPlayState)->actor.world.pos.x; }, WHITE }, - { "Link Y", "Player->actor.world.pos.y", "Y:", TYPE_FLOAT, true, []() -> void* { return &GET_PLAYER(gPlayState)->actor.world.pos.y; }, WHITE }, - { "Link Z", "Player->actor.world.pos.z", "Z:", TYPE_FLOAT, true, []() -> void* { return &GET_PLAYER(gPlayState)->actor.world.pos.z; }, WHITE }, - { "Link Yaw", "Player->actor.world.rot.y", "ROT:", TYPE_S16, true, []() -> void* { return &GET_PLAYER(gPlayState)->actor.world.rot.y; }, WHITE }, - { "Link Velocity", "Player->linearVelocity", "V:", TYPE_FLOAT, true, []() -> void* { return &GET_PLAYER(gPlayState)->linearVelocity; }, WHITE }, - { "Link X Velocity", "Player->actor.velocity.x", "XV:", TYPE_FLOAT, true, []() -> void* { return &GET_PLAYER(gPlayState)->actor.velocity.x; }, WHITE }, - { "Link Y Velocity", "Player->actor.velocity.y", "YV:", TYPE_FLOAT, true, []() -> void* { return &GET_PLAYER(gPlayState)->actor.velocity.y; }, WHITE }, - { "Link Z Velocity", "Player->actor.velocity.z", "ZV:", TYPE_FLOAT, true, []() -> void* { return &GET_PLAYER(gPlayState)->actor.velocity.z; }, WHITE }, - { "Text ID", "play->msgCtx.textId", "TEXTID:", TYPE_U16, true, []() -> void* { return &gPlayState->msgCtx.textId; }, WHITE }, - { "Analog Stick X", "play->state.input->cur.stick_x", "AX:", TYPE_S8, true, []() -> void* { return &gPlayState->state.input->cur.stick_x; }, WHITE }, - { "Analog Stick Y", "play->state.input->cur.stick_y", "AY:", TYPE_S8, true, []() -> void* { return &gPlayState->state.input->cur.stick_y; }, WHITE }, + { "Time", "gSaveContext.dayTime", "TIME:", TYPE_U16, false, []() -> void* { return &gSaveContext.dayTime; }, WHITE }, + { "Age", "gSaveContext.linkAge", "AGE:", TYPE_S32, false, []() -> void* { return &gSaveContext.linkAge; }, WHITE }, + { "Health", "gSaveContext.health", "HP:", TYPE_S16, false, []() -> void* { return &gSaveContext.health; }, WHITE }, + { "Navi Timer", "gSaveContext.naviTimer", "NAVI:", TYPE_U16, false, []() -> void* { return &gSaveContext.naviTimer; }, WHITE }, + { "Scene ID", "play->sceneNum", "SCENE:", TYPE_S16, true, []() -> void* { return &gPlayState->sceneNum; }, WHITE }, + { "Room ID", "play->roomCtx.curRoom.num", "ROOM:", TYPE_S8, true, []() -> void* { return &gPlayState->roomCtx.curRoom.num; }, WHITE }, + { "Entrance ID", "gSaveContext.entranceIndex", "ENTR:", TYPE_S32, false, []() -> void* { return &gSaveContext.entranceIndex; }, WHITE }, + { "Cutscene ID", "gSaveContext.cutsceneIndex", "CUTS:", TYPE_S32, false, []() -> void* { return &gSaveContext.cutsceneIndex; }, WHITE }, + { "Link X", "Player->actor.world.pos.x", "X:", TYPE_FLOAT, true, []() -> void* { return &GET_PLAYER(gPlayState)->actor.world.pos.x; }, WHITE }, + { "Link Y", "Player->actor.world.pos.y", "Y:", TYPE_FLOAT, true, []() -> void* { return &GET_PLAYER(gPlayState)->actor.world.pos.y; }, WHITE }, + { "Link Z", "Player->actor.world.pos.z", "Z:", TYPE_FLOAT, true, []() -> void* { return &GET_PLAYER(gPlayState)->actor.world.pos.z; }, WHITE }, + { "Link Yaw", "Player->actor.world.rot.y", "ROT:", TYPE_S16, true, []() -> void* { return &GET_PLAYER(gPlayState)->actor.world.rot.y; }, WHITE }, + { "Link Velocity", "Player->linearVelocity", "V:", TYPE_FLOAT, true, []() -> void* { return &GET_PLAYER(gPlayState)->linearVelocity; }, WHITE }, + { "Link X Velocity", "Player->actor.velocity.x", "XV:", TYPE_FLOAT, true, []() -> void* { return &GET_PLAYER(gPlayState)->actor.velocity.x; }, WHITE }, + { "Link Y Velocity", "Player->actor.velocity.y", "YV:", TYPE_FLOAT, true, []() -> void* { return &GET_PLAYER(gPlayState)->actor.velocity.y; }, WHITE }, + { "Link Z Velocity", "Player->actor.velocity.z", "ZV:", TYPE_FLOAT, true, []() -> void* { return &GET_PLAYER(gPlayState)->actor.velocity.z; }, WHITE }, + { "Text ID", "play->msgCtx.textId", "TEXTID:", TYPE_U16, true, []() -> void* { return &gPlayState->msgCtx.textId; }, WHITE }, + { "Analog Stick X", "play->state.input->cur.stick_x", "AX:", TYPE_S8, true, []() -> void* { return &gPlayState->state.input->cur.stick_x; }, WHITE }, + { "Analog Stick Y", "play->state.input->cur.stick_y", "AY:", TYPE_S8, true, []() -> void* { return &gPlayState->state.input->cur.stick_y; }, WHITE }, + { "Stairs: outMaxFree", "", "STAIR-OM:", TYPE_U32, true, []() -> void* { StairsArena_GetSizes(&stairsOutMaxFree, &stairsOutFree, &stairsOutAlloc); return &stairsOutMaxFree; }, WHITE }, + { "Stairs: outFree", "", "STAIR-OF:", TYPE_U32, true, []() -> void* { StairsArena_GetSizes(&stairsOutMaxFree, &stairsOutFree, &stairsOutAlloc); return &stairsOutFree; }, WHITE }, + { "Stairs: outAlloc", "", "STAIR-OA:", TYPE_U32, true, []() -> void* { StairsArena_GetSizes(&stairsOutMaxFree, &stairsOutFree, &stairsOutAlloc); return &stairsOutAlloc; }, WHITE }, /* TODO: Find these (from GZ) "XZ Units Traveled (Camera based speed variable)" f32 0x801C9018 "Movement Angle" x16 0x801DBB1C diff --git a/soh/soh/Enhancements/gameplaystats.cpp b/soh/soh/Enhancements/gameplaystats.cpp index efcf44efb..7a7b32058 100644 --- a/soh/soh/Enhancements/gameplaystats.cpp +++ b/soh/soh/Enhancements/gameplaystats.cpp @@ -14,6 +14,7 @@ extern "C" { #include #include #include "soh/Enhancements/enhancementTypes.h" +#include "soh/Enhancements/stairs.h" extern "C" { #include diff --git a/soh/soh/Enhancements/stairs.cpp b/soh/soh/Enhancements/stairs.cpp index 87cd679f9..db4aa9d2b 100644 --- a/soh/soh/Enhancements/stairs.cpp +++ b/soh/soh/Enhancements/stairs.cpp @@ -457,7 +457,7 @@ std::unordered_map actorOverlaySizes = { std::unordered_set registeredStairOverlays; std::unordered_map generalPtrMap; -std::unordered_map actorPtrMap; +std::unordered_map overlayRPtrMap; std::unordered_map overlayPtrMap; std::unordered_map mallocRPtrMap; @@ -482,6 +482,10 @@ s32 Stairs_RegisterOverlay(u16 id) { return true; } +s32 Stairs_GetOverlayRegistered(u16 id) { + return registeredStairOverlays.contains(id); +} + s32 Stairs_UnregisterOverlay(u16 id) { if (registeredStairOverlays.contains(id)) { registeredStairOverlays.erase(id); @@ -537,9 +541,9 @@ void* StairsArena_MallocGeneral(size_t size, uintptr_t id) { return ptr; } -void* StairsArena_MallocActor(size_t size, u16 id) { - void* ptr = __osMalloc(&sStairsArena, size); - actorPtrMap[id] = ptr; +void* StairsArena_MallocROverlay(size_t size, u16 id) { + void* ptr = __osMallocR(&sStairsArena, size); + overlayRPtrMap[id] = ptr; // StairsArena_CheckPointer(ptr, size, "stairs_malloc", "確保"); // "Secure" return ptr; @@ -560,7 +564,7 @@ void* StairsArena_MallocR(size_t size) { return ptr; } -void* StairsArena_MallocRGeneral(size_t size, u16 id) { +void* StairsArena_MallocRGeneral(size_t size, uintptr_t id) { void* ptr = __osMallocR(&sStairsArena, size); mallocRPtrMap[id] = ptr; @@ -593,12 +597,12 @@ void StairsArena_FreeGeneral(uintptr_t id) { generalPtrMap[id] = nullptr; } -void StairsArena_FreeActor(u16 id) { - void* ptr = actorPtrMap[id]; +void StairsArena_FreeMallocROverlay(u16 id) { + void* ptr = overlayRPtrMap[id]; if (ptr) { __osFree(&sStairsArena, ptr); } - actorPtrMap[id] = nullptr; + overlayRPtrMap[id] = nullptr; } void StairsArena_FreeOverlay(u16 id) { @@ -656,7 +660,7 @@ void StairsArena_Cleanup() { __osMallocCleanup(&sStairsArena); registeredStairOverlays.clear(); generalPtrMap.clear(); - actorPtrMap.clear(); + overlayRPtrMap.clear(); overlayPtrMap.clear(); mallocRPtrMap.clear(); absolutePtr = nullptr; diff --git a/soh/soh/Enhancements/stairs.h b/soh/soh/Enhancements/stairs.h index 8875bdbe9..48749fafa 100644 --- a/soh/soh/Enhancements/stairs.h +++ b/soh/soh/Enhancements/stairs.h @@ -18,6 +18,7 @@ extern "C" { u16 Stairs_GetAllocType(u16 id); s32 Stairs_RegisterOverlay(u16 id); +s32 Stairs_GetOverlayRegistered(u16 id); s32 Stairs_UnregisterOverlay(u16 id); s32 Stairs_RegisterAbsoluteSpace(); s32 Stairs_GetAbsoluteSpace(); @@ -40,12 +41,12 @@ void StairsArena_Cleanup(); u8 StairsArena_IsInitalized(); void* StairsArena_MallocGeneral(size_t size, uintptr_t id); -void* StairsArena_MallocActor(size_t size, u16 id); +void* StairsArena_MallocROverlay(size_t size, u16 id); void* StairsArena_MallocOverlay(size_t size, u16 id); -void* StairsArena_MallocRGeneral(size_t size, u16 id); +void* StairsArena_MallocRGeneral(size_t size, uintptr_t id); void* StairsArena_MallocRAbsolute(size_t size); void StairsArena_FreeGeneral(uintptr_t id); -void StairsArena_FreeActor(u16 id); +void StairsArena_FreeMallocROverlay(u16 id); void StairsArena_FreeOverlay(u16 id); void StairsArena_FreeMallocR(u16 id); void StairsArena_FreeAbsolute(); diff --git a/soh/src/code/z_actor.c b/soh/src/code/z_actor.c index 51a5f89da..72a1c4a30 100644 --- a/soh/src/code/z_actor.c +++ b/soh/src/code/z_actor.c @@ -3147,7 +3147,7 @@ void Actor_FreeOverlay(ActorDBEntry* dbEntry) { } if (CVarGetInteger("gStairs", 1)) { - if (!Stairs_RegisterOverlay(dbEntry->id)) { + if (Stairs_GetOverlayRegistered(dbEntry->id)) { u16 allocType = Stairs_GetAllocType(dbEntry->id); if (allocType & STAIRS_ACTOROVL_ALLOC_PERSISTENT) { @@ -3213,10 +3213,10 @@ Actor* Actor_Spawn(ActorContext* actorCtx, PlayState* play, s16 actorId, f32 pos } else if (allocType & STAIRS_ACTOROVL_ALLOC_ABSOLUTE) { if (Stairs_RegisterAbsoluteSpace()) { - StairsArena_MallocRAbsolute(overlaySize); + StairsArena_MallocRAbsolute(STAIRS_ACTOROVL_ABSOLUTE_SPACE_SIZE); } } else if (allocType & STAIRS_ACTOROVL_ALLOC_PERSISTENT) { - StairsArena_MallocRGeneral(overlaySize, dbEntry->id); + StairsArena_MallocROverlay(overlaySize, dbEntry->id); } else { StairsArena_MallocOverlay(overlaySize, dbEntry->id); } @@ -3249,10 +3249,9 @@ Actor* Actor_Spawn(ActorContext* actorCtx, PlayState* play, s16 actorId, f32 pos } if ((CVarGetInteger("gStairs", 1))) { - Actor* ptr = StairsArena_MallocGeneral(dbEntry->instanceSize, (uintptr_t)actor); - if (ptr == NULL) { - Actor_FreeOverlay(dbEntry); - actor = NULL; + if (StairsArena_MallocGeneral(dbEntry->instanceSize, (uintptr_t)actor) == NULL) { + // Actor_FreeOverlay(dbEntry); + // actor = NULL; return NULL; } } @@ -3399,7 +3398,7 @@ Actor* Actor_Delete(ActorContext* actorCtx, Actor* actor, PlayState* play) { newHead = Actor_RemoveFromCategory(play, actorCtx, actor); if (CVarGetInteger("gStairs", 1)) { - StairsArena_FreeActor((uintptr_t)actor); + StairsArena_FreeGeneral((uintptr_t)actor); } ZELDA_ARENA_FREE_DEBUG(actor);