Skip to content

Commit 66f4594

Browse files
authored
Merge pull request #1647 from Giragast/memory_editor_export
Allow memory editors to export directly to a file
2 parents 437f208 + 599d5da commit 66f4594

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/gui/gui.cc

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -733,6 +733,28 @@ void PCSX::GUI::init(std::function<void()> applyArguments) {
733733
g_emulator->m_gpu->partialUpdateVRAM(x, y, 1, 1, &newPixel);
734734
};
735735

736+
auto exportFn = [](ImU8* data, size_t len, size_t base_addr, std::string postfixName) {
737+
std::filesystem::path writeFilepath =
738+
g_system->getPersistentDir() / (s_gui->getSaveStatePrefix(true) + "mem_" + postfixName + ".bin");
739+
IO<File> f(new PosixFile(writeFilepath.string(), FileOps::TRUNCATE));
740+
if (!f->failed()) {
741+
f->write(data, len);
742+
f->close();
743+
g_system->log(LogClass::UI, "Memory exported to: %s\n", writeFilepath.string().c_str());
744+
} else {
745+
g_system->log(LogClass::UI, "Failed to export memory to: %s\n", writeFilepath.string().c_str());
746+
}
747+
};
748+
#define EXPORT_FUNC(name) [=](ImU8* data, size_t len, size_t base_addr) { exportFn(data, len, base_addr, name); }
749+
for (auto& editor : m_mainMemEditors) {
750+
editor.editor.ExportFn = EXPORT_FUNC("wram");
751+
}
752+
m_parallelPortEditor.editor.ExportFn = EXPORT_FUNC("parallel");
753+
m_scratchPadEditor.editor.ExportFn = EXPORT_FUNC("scratch");
754+
m_hwrEditor.editor.ExportFn = EXPORT_FUNC("hwr");
755+
m_biosEditor.editor.ExportFn = EXPORT_FUNC("bios");
756+
m_vramEditor.editor.ExportFn = EXPORT_FUNC("vram");
757+
736758
m_offscreenShaderEditor.init();
737759
m_outputShaderEditor.init();
738760

third_party/imgui_memory_editor/imgui_memory_editor.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -361,9 +361,9 @@ void MemoryEditor::DrawContents(void* mem_data_void, size_t mem_size)
361361
}
362362
}
363363

364-
void MemoryEditor::DrawOptionsLine(const Sizes& s, void* mem_data, size_t mem_size)
364+
void MemoryEditor::DrawOptionsLine(const Sizes& s, void* mem_data_void, size_t mem_size)
365365
{
366-
IM_UNUSED(mem_data);
366+
ImU8* mem_data = (ImU8*)mem_data_void;
367367
ImGuiStyle& style = ImGui::GetStyle();
368368
const char* format_range = OptUpperCaseHex ? "Range %0*" _PRISizeT "X..%0*" _PRISizeT "X" : "Range %0*" _PRISizeT "x..%0*" _PRISizeT "x";
369369

@@ -423,6 +423,14 @@ void MemoryEditor::DrawOptionsLine(const Sizes& s, void* mem_data, size_t mem_si
423423
GotoAddr = 0;
424424
OffsetAddr = 0;
425425
}
426+
427+
// Export memory via a function, if available
428+
if (ExportFn) {
429+
ImGui::SameLine();
430+
if (ImGui::Button("Export Memory")) {
431+
ExportFn(mem_data, mem_size, BaseAddr);
432+
}
433+
}
426434
}
427435

428436
void MemoryEditor::DrawPreviewLine(const Sizes& s, void* mem_data_void, size_t mem_size)

third_party/imgui_memory_editor/imgui_memory_editor.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ struct MemoryEditor
8585
bool (*HighlightFn)(const ImU8* data, size_t off);//= 0 // optional handler to return Highlight property (to support non-contiguous highlighting).
8686
std::function<void()> PushMonoFont = nullptr;
8787
size_t& OffsetAddr; // referenced from PCSX-Redux Settings
88+
std::function<void(ImU8* data, size_t len, size_t base)> ExportFn = nullptr; // optional handler to export all memory data.
8889

8990
private:
9091
// [Internal State]
@@ -129,7 +130,7 @@ struct MemoryEditor
129130
void DrawWindow(const char* title, void* mem_data, size_t mem_size);
130131
// Memory Editor contents only
131132
void DrawContents(void* mem_data_void, size_t mem_size);
132-
void DrawOptionsLine(const Sizes& s, void* mem_data, size_t mem_size);
133+
void DrawOptionsLine(const Sizes& s, void* mem_data_void, size_t mem_size);
133134
void DrawPreviewLine(const Sizes& s, void* mem_data_void, size_t mem_size);
134135
// Utilities for Data Preview
135136
const char* DataTypeGetDesc(ImGuiDataType data_type) const;

0 commit comments

Comments
 (0)