|
| 1 | +#include "RoomMenu.hpp" |
| 2 | + |
| 3 | +#include <imgui.h> |
| 4 | +#include "ImHelpers.hpp" |
| 5 | +#include "os.h" |
| 6 | +#include "prime/CStateManager.hpp" |
| 7 | +#include "prime/CWorld.hpp" |
| 8 | +#include "WarpMenu.h" |
| 9 | + |
| 10 | + |
| 11 | +namespace GUI { |
| 12 | + void hideAllRooms(); |
| 13 | + void showVisibilityControls(); |
| 14 | + |
| 15 | + void showLoadControls(); |
| 16 | + |
| 17 | + void drawRoomMenu() { |
| 18 | + if (ImGui::TreeNode("Rooms")) { |
| 19 | + |
| 20 | + if (ImGui::TreeNode("Visibility")) { |
| 21 | + ImGui::Text("Warning: If you show too many rooms, the game may crash!"); |
| 22 | + if (ImGui::Button("Hide all")) { |
| 23 | + hideAllRooms(); |
| 24 | + } |
| 25 | + showVisibilityControls(); |
| 26 | + ImGui::TreePop(); |
| 27 | + } |
| 28 | + if (ImGui::TreeNode("Load")) { |
| 29 | + ImGui::Text("Warning: If you load too many rooms, the game may crash!"); |
| 30 | + showLoadControls(); |
| 31 | + ImGui::TreePop(); |
| 32 | + } |
| 33 | + ImGui::TreePop(); |
| 34 | + } |
| 35 | + } |
| 36 | + |
| 37 | + void hideAllRooms() { |
| 38 | + CStateManager *stateManager = ((CStateManager *) 0x8045A1A8); |
| 39 | + CWorld *world = stateManager->GetWorld(); |
| 40 | + if (world == nullptr) { |
| 41 | + return; |
| 42 | + } |
| 43 | + TAreaId areaId = world->GetCurrentAreaId(); |
| 44 | + auto areas = world->areas(); |
| 45 | + for (int i = 0; i < areas->length(); i++) { |
| 46 | + auto area = areas->get(i).ptr; |
| 47 | + if (area->areaIDx() == areaId) continue; |
| 48 | + area->SetOcclusionState(EOcclusionState::Occluded); |
| 49 | + } |
| 50 | + } |
| 51 | + |
| 52 | + void showVisibilityControls() { |
| 53 | + CStateManager *stateManager = ((CStateManager *) 0x8045A1A8); |
| 54 | + CWorld *world = stateManager->GetWorld(); |
| 55 | + if (world == nullptr) { |
| 56 | + return; |
| 57 | + } |
| 58 | + TAreaId areaId = world->GetCurrentAreaId(); |
| 59 | + auto areas = world->areas(); |
| 60 | + for (int i = 0; i < areas->length(); i++) { |
| 61 | + auto area = areas->get(i).ptr; |
| 62 | + auto post = area->postConstructed(); |
| 63 | + if (post != nullptr && area->curChain() == EChain::Alive) { |
| 64 | + if (area->areaIDx() == areaId) continue; |
| 65 | + const char *name = getNameForAreaAsset(world->GetWorldId(), area->mrea()); |
| 66 | + ImGui::Text("%s", name); |
| 67 | + ImGui::SameLine(); |
| 68 | + if (post->occlusionState() == EOcclusionState::Occluded) { |
| 69 | + char label[32]; |
| 70 | + memset(label, 0, 32); |
| 71 | + snprintf(label, 32, "Show###%d", area->mrea()); |
| 72 | + if (ImGui::Button(label)) { |
| 73 | + area->SetOcclusionState(EOcclusionState::Visible); |
| 74 | + } |
| 75 | + } else { |
| 76 | + char label[32]; |
| 77 | + memset(label, 0, 32); |
| 78 | + snprintf(label, 32, "Show###%d", area->mrea()); |
| 79 | + if (ImGui::Button(label)) { |
| 80 | + area->SetOcclusionState(EOcclusionState::Occluded); |
| 81 | + } |
| 82 | + } |
| 83 | + } |
| 84 | + } |
| 85 | + } |
| 86 | + |
| 87 | + void showLoadControls() { |
| 88 | + CStateManager *stateManager = ((CStateManager *) 0x8045A1A8); |
| 89 | + CWorld *world = stateManager->GetWorld(); |
| 90 | + if (world == nullptr) { |
| 91 | + return; |
| 92 | + } |
| 93 | + TAreaId areaId = world->GetCurrentAreaId(); |
| 94 | + auto currentArea = world->areas()->get(areaId).ptr; |
| 95 | + auto docks = currentArea->docks(); |
| 96 | + for (int i = 0; i < docks->length(); i++) { |
| 97 | + auto dock = &docks->get(i); |
| 98 | + auto refs = dock->refs(); |
| 99 | + for (int j = 0; j < refs->length(); j++) { |
| 100 | + auto ref = &refs->get(j); |
| 101 | + auto connectedAreaId = ref->x0_area; |
| 102 | + auto connectedArea = world->areas()->get(connectedAreaId).ptr; |
| 103 | + const char *name = getNameForAreaAsset(world->GetWorldId(), connectedArea->mrea()); |
| 104 | + ImGui::Text("%s %x", name, ref->x6_loadOther); |
| 105 | + ImGui::SameLine(); |
| 106 | + bool loadOther = (ref->x6_loadOther & 0x80) > 0; |
| 107 | + if (loadOther) { |
| 108 | + char label[32]; |
| 109 | + memset(label, 0, 32); |
| 110 | + snprintf(label, 32, "Unload###%d", connectedAreaId); |
| 111 | + if (ImGui::Button(label)) { |
| 112 | + ref->x6_loadOther &= 0x7F; |
| 113 | + } |
| 114 | + } else { |
| 115 | + char label[32]; |
| 116 | + memset(label, 0, 32); |
| 117 | + snprintf(label, 32, "Load###%d", connectedAreaId); |
| 118 | + if (ImGui::Button(label)) { |
| 119 | + ref->x6_loadOther |= 0x80; |
| 120 | + } |
| 121 | + } |
| 122 | + } |
| 123 | + } |
| 124 | + } |
| 125 | +} |
| 126 | + |
0 commit comments