Skip to content

Commit

Permalink
Added memory viewer
Browse files Browse the repository at this point in the history
  • Loading branch information
angryzor committed Dec 3, 2024
1 parent 78adb61 commit 8d610dd
Show file tree
Hide file tree
Showing 9 changed files with 91 additions and 4 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# v0.1.60
* Added a Memory Viewer that lets you view raw memory areas.
You can open it by right clicking objects, components, gameservices or RFL data.


# v0.1.59
* Added toggles for position and rotation inheritance in `GOCTransform` inspector.

Expand Down
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
cmake_minimum_required(VERSION 3.28)
# DevTools
project(devtools VERSION 0.1.59
project(devtools VERSION 0.1.60
DESCRIPTION "Hedgehog Engine 2 DevTools"
LANGUAGES CXX)

Expand Down Expand Up @@ -81,7 +81,7 @@ foreach(DEVTOOLS_TARGET_SDK miller rangers wars)
add_subdirectory(${SDK_PATH} ${DEVTOOLS_TARGET_SDK}-sdk EXCLUDE_FROM_ALL)

add_library(${DEVTOOLS_TARGET} SHARED)
target_link_libraries(${DEVTOOLS_TARGET} PRIVATE ${DEVTOOLS_TARGET_SDK}-sdk filewatch detours imgui imgui-backend-win32 imgui-backend-dx11 imgui-file-dialog imgui-node-editor imguizmo implot reflectcpp OGDF rip-hl)
target_link_libraries(${DEVTOOLS_TARGET} PRIVATE ${DEVTOOLS_TARGET_SDK}-sdk filewatch detours imgui imgui-backend-win32 imgui-backend-dx11 imgui-file-dialog imgui-node-editor imgui-memory-editor imguizmo implot reflectcpp OGDF rip-hl)
target_compile_features(${DEVTOOLS_TARGET} PRIVATE cxx_std_20)
target_compile_options(${DEVTOOLS_TARGET} PRIVATE /permissive- /W4 /wd4100 /wd4458 /wd4324)
target_compile_definitions(${DEVTOOLS_TARGET}
Expand Down
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ target_sources(${DEVTOOLS_TARGET}
ui/Shortcuts.cpp
ui/ToolBar.cpp
ui/tools/RflComparer.cpp
ui/tools/MemoryViewer.cpp
utilities/BoundingBoxes.cpp
utilities/math/EulerTransform.cpp
utilities/math/Frustum.cpp
Expand Down Expand Up @@ -111,6 +112,7 @@ target_sources(${DEVTOOLS_TARGET}
ui/Shortcuts.h
ui/ToolBar.h
ui/tools/RflComparer.h
ui/tools/MemoryViewer.h
utilities/BoundingBoxes.h
utilities/Helpers.h
utilities/math/EulerTransform.h
Expand Down
6 changes: 6 additions & 0 deletions src/ui/common/editors/Reflection.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <ui/common/Translations.h>
#include <ui/common/inputs/Basic.h>
#include <ui/common/editors/Basic.h>
#include <ui/tools/MemoryViewer.h>
#include <ui/Desktop.h>

using namespace hh::fnd;
Expand Down Expand Up @@ -239,6 +240,8 @@ class RenderStaticReflectionEditor {
typeInfo->ConstructObject(&obj, hh::fnd::MemoryRouter::GetModuleAllocator());
edited = true;
}
if (ImGui::Selectable("Open in memory viewer"))
new (Desktop::instance->GetAllocator()) MemoryViewer{ Desktop::instance->GetAllocator(), &obj, rflClass->GetSize() };
ImGui::EndPopup();
}

Expand Down Expand Up @@ -370,6 +373,9 @@ class RenderResettableReflectionEditor {
edited = true;
}

if (ImGui::Selectable("Open in memory viewer"))
new (Desktop::instance->GetAllocator()) MemoryViewer{ Desktop::instance->GetAllocator(), &obj, rflClass->GetSize() };

ImGui::EndPopup();
}

Expand Down
11 changes: 10 additions & 1 deletion src/ui/game-services/GameServiceInspector.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "GameServiceInspector.h"
#include <imgui_internal.h>
#include <ui/Desktop.h>
#include <ui/tools/MemoryViewer.h>

#ifdef DEVTOOLS_TARGET_SDK_wars
#include "game-service-inspectors/FxParamManager.h"
Expand Down Expand Up @@ -97,7 +98,15 @@ void GameServiceInspector::RenderContents() {

for (auto* service : gameManager->GetServices()) {
ImGui::PushID(service);
if (ImGui::CollapsingHeader(service->staticClass->name))
bool isOpen = ImGui::CollapsingHeader(service->staticClass->name);

if (ImGui::BeginPopupContextItem("GameService Operations")) {
if (ImGui::Selectable("Open in memory viewer"))
new (Desktop::instance->GetAllocator()) MemoryViewer{ Desktop::instance->GetAllocator(), service };
ImGui::EndPopup();
}

if (isOpen)
ServiceIterator<>::Render(*service);
ImGui::PopID();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <ui/common/viewers/Basic.h>
#include <ui/common/editors/Basic.h>
#include <ui/common/inputs/Basic.h>
#include <ui/tools/MemoryViewer.h>
#include <utilities/math/EulerTransform.h>
#include <utilities/math/MathUtils.h>
#include <utilities/GameObjectUtils.h>
Expand Down Expand Up @@ -162,9 +163,16 @@ namespace ui::operation_modes::modes::object_inspection {
}
else {
auto focusedObject = selection[0];
ImGui::BeginGroup();
ImGui::Text("Object name: %s", focusedObject->name.c_str());
ImGui::Text("Layer: %d", focusedObject->layer);
ImGui::Text("Class: %s", focusedObject->objectClass ? focusedObject->objectClass->GetName() : "<none>");
ImGui::EndGroup();
if (ImGui::BeginPopupContextItem("GameObject Operations")) {
if (ImGui::Selectable("Open in memory viewer"))
new (Desktop::instance->GetAllocator()) MemoryViewer{ Desktop::instance->GetAllocator(), focusedObject, focusedObject->objectClass->GetObjectSize() };
ImGui::EndPopup();
}
ImGui::Separator();
if (ImGui::BeginTabBar("Inspector types")) {
if (ImGui::BeginTabItem("Properties")) {
Expand All @@ -175,7 +183,15 @@ namespace ui::operation_modes::modes::object_inspection {
char title[200];
snprintf(title, 200, "%s (%s) - %x", component->pStaticClass->pName, component->pStaticClass->category, component->nameHash);

if (ImGui::CollapsingHeader(title))
bool isComponentSectionOpen = ImGui::CollapsingHeader(title);

if (ImGui::BeginPopupContextItem("Component Operations")) {
if (ImGui::Selectable("Open in memory viewer"))
new (Desktop::instance->GetAllocator()) MemoryViewer{ Desktop::instance->GetAllocator(), component, component->pStaticClass->size };
ImGui::EndPopup();
}

if (isComponentSectionOpen)
ComponentIterator<>::Render(*component);

ImGui::PopID();
Expand Down
26 changes: 26 additions & 0 deletions src/ui/operation-modes/modes/object-inspection/ObjectList.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "ObjectList.h"
#include "Behaviors.h"
#include <ui/common/Icons.h>
#include <ui/tools/MemoryViewer.h>
#include <utilities/math/MathUtils.h>

namespace ui::operation_modes::modes::object_inspection {
Expand All @@ -15,6 +16,8 @@ namespace ui::operation_modes::modes::object_inspection {
if (selectionBehavior->GetSelection().find(obj) != -1)
nodeflags |= ImGuiTreeNodeFlags_Selected;

ImGui::PushID(obj);

auto* transform = obj->GetComponent<GOCTransform>();

if (transform && transform->GetChildren().size() > 0) {// || obj->GetChildren().size() > 0) {
Expand All @@ -23,6 +26,12 @@ namespace ui::operation_modes::modes::object_inspection {
if (ImGui::IsItemClicked())
selectionBehavior->Select(obj);

if (ImGui::BeginPopupContextItem("GameObject Operations")) {
if (ImGui::Selectable("Open in memory viewer"))
new (Desktop::instance->GetAllocator()) MemoryViewer{ Desktop::instance->GetAllocator(), obj, obj->objectClass->GetObjectSize() };
ImGui::EndPopup();
}

if (ImGui::BeginDragDropSource()) {
ImGui::SetDragDropPayload("GameObject", &obj, sizeof(obj));
ImGui::EndDragDropSource();
Expand Down Expand Up @@ -59,6 +68,12 @@ namespace ui::operation_modes::modes::object_inspection {
if (ImGui::IsItemClicked())
selectionBehavior->Select(obj);

if (ImGui::BeginPopupContextItem("GameObject Operations")) {
if (ImGui::Selectable("Open in memory viewer"))
new (Desktop::instance->GetAllocator()) MemoryViewer{ Desktop::instance->GetAllocator(), obj, obj->objectClass->GetObjectSize() };
ImGui::EndPopup();
}

if (ImGui::BeginDragDropSource()) {
ImGui::SetDragDropPayload("GameObject", &obj, sizeof(obj));
ImGui::EndDragDropSource();
Expand All @@ -82,6 +97,7 @@ namespace ui::operation_modes::modes::object_inspection {
ImGui::EndDragDropTarget();
}
}
ImGui::PopID();
}

void ObjectList::RenderPanel() {
Expand All @@ -107,6 +123,8 @@ namespace ui::operation_modes::modes::object_inspection {
for (auto* layer : GameManager::GetInstance()->gameObjectLayers) {
if (layer->objects.size() != 0 && ImGui::TreeNode(layer, layer->name)) {
for (auto* obj : layer->objects) {
ImGui::PushID(obj);

ImGuiTreeNodeFlags nodeflags = ImGuiTreeNodeFlags_Leaf | ImGuiTreeNodeFlags_NoTreePushOnOpen;

if (selectionBehavior->IsSelected(obj))
Expand All @@ -117,6 +135,12 @@ namespace ui::operation_modes::modes::object_inspection {
if (ImGui::IsItemClicked())
selectionBehavior->Select(obj);

if (ImGui::BeginPopupContextItem("GameObject Operations")) {
if (ImGui::Selectable("Open in memory viewer"))
new (Desktop::instance->GetAllocator()) MemoryViewer{ Desktop::instance->GetAllocator(), obj, obj->objectClass->GetObjectSize() };
ImGui::EndPopup();
}

if (ImGui::BeginDragDropSource()) {
ImGui::SetDragDropPayload("GameObject", &obj, sizeof(obj));
ImGui::EndDragDropSource();
Expand All @@ -139,6 +163,8 @@ namespace ui::operation_modes::modes::object_inspection {
}
ImGui::EndDragDropTarget();
}

ImGui::PopID();
}
ImGui::TreePop();
}
Expand Down
11 changes: 11 additions & 0 deletions src/ui/tools/MemoryViewer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#include "MemoryViewer.h"

MemoryViewer::MemoryViewer(csl::fnd::IAllocator* allocator, void* addr, size_t size) : StandaloneWindow{ allocator }, addr{ addr }, size{ size } {
char namebuf[500];
snprintf(namebuf, sizeof(namebuf), "Memory viewer @ 0x%zx - viewing %zx bytes", addr, size);
SetTitle(namebuf);
}

void MemoryViewer::RenderContents() {
memEditor.DrawContents(addr, size);
}
12 changes: 12 additions & 0 deletions src/ui/tools/MemoryViewer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once
#include <ui/common/StandaloneWindow.h>
#include <imgui_memory_editor.h>

class MemoryViewer : public StandaloneWindow {
void* addr{};
size_t size{};
MemoryEditor memEditor{};
public:
MemoryViewer(csl::fnd::IAllocator* allocator, void* addr, size_t size = 0x10000);
virtual void RenderContents() override;
};

0 comments on commit 8d610dd

Please sign in to comment.