Skip to content

Commit 13a7f3b

Browse files
committed
Add heap draw
1 parent 0ba4710 commit 13a7f3b

File tree

4 files changed

+36
-0
lines changed

4 files changed

+36
-0
lines changed

src/cdc/sys/Allocator.cpp

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
#include "Allocator.h"
2+
#include "util/Hooking.h"
3+
4+
cdc::Allocator* cdc::Alloc::Get()
5+
{
6+
return *(cdc::Allocator**)GET_ADDRESS(0x1159DBC, 0x8AFEA4, 0x000000);
7+
}
8+
9+
cdc::HeapAllocator* cdc::Alloc::GetHeap()
10+
{
11+
return *(cdc::HeapAllocator**)GET_ADDRESS(0x1159DC0, 0x8AFEA8, 0x000000);
12+
}

src/cdc/sys/Allocator.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,4 +59,11 @@ namespace cdc
5959

6060
virtual Heap* GetHeapImpl() = 0;
6161
};
62+
63+
class Alloc
64+
{
65+
public:
66+
static Allocator* Get();
67+
static HeapAllocator* GetHeap();
68+
};
6269
}

src/modules/Debug.cpp

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@
88
#include "util/Hooking.h"
99
#include "game/Game.h"
1010

11+
#include "cdc/sys/Allocator.h"
12+
1113
static Debug* s_debug;
1214

1315
// Event debug print hooks
@@ -76,6 +78,18 @@ void Debug::OnPostInitialize()
7678
Initialize();
7779
}
7880

81+
void Debug::OnFrame()
82+
{
83+
if (m_drawHeap)
84+
{
85+
auto font = Font::GetMainFont();
86+
auto allocator = cdc::Alloc::GetHeap();
87+
88+
font->SetCursor(10, 10);
89+
font->Print("Heap: %.1f/%dMB", allocator->GetTotalAllocSize() / 1024.f / 1024.f, allocator->GetMaxHeapSize() >> 20);
90+
}
91+
}
92+
7993
void Debug::OnMenu()
8094
{
8195
if (ImGui::BeginMenu("Debug"))
@@ -94,6 +108,7 @@ void Debug::OnMenu()
94108
}
95109
}
96110

111+
ImGui::MenuItem("Draw heap", nullptr, &m_drawHeap);
97112
ImGui::MenuItem("Debug keypad", nullptr, (bool*)GET_ADDRESS(0x107696C, 0x7C8A3C, 0x000000));
98113

99114
ImGui::EndMenu();

src/modules/Debug.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Debug : public Module
66
{
77
private:
88
bool m_drawDebug = false;
9+
bool m_drawHeap = false;
910

1011
void Initialize() const noexcept;
1112

@@ -15,5 +16,6 @@ class Debug : public Module
1516
bool IsDrawDebug() const noexcept { return m_drawDebug; }
1617

1718
void OnPostInitialize();
19+
void OnFrame();
1820
void OnMenu();
1921
};

0 commit comments

Comments
 (0)